From d3408b91bef512d5f70ce5e07c136ac0fe036b40 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sun, 12 Jan 2020 15:32:26 +0900 Subject: [PATCH] bump libraries --- BTCPayServer.Tests/BTCPayServer.Tests.csproj | 2 +- BTCPayServer/BTCPayServer.csproj | 30 +++++++++---------- .../Controllers/InvoiceController.UI.cs | 8 ++--- BTCPayServer/Controllers/ServerController.cs | 8 +++-- .../Controllers/StoresController.BTCLike.cs | 3 +- BTCPayServer/Controllers/StoresController.cs | 6 ++-- BTCPayServer/EventAggregator.cs | 4 +-- BTCPayServer/Extensions.cs | 8 +++-- .../Extensions/OpenIddictExtensions.cs | 2 +- .../BackgroundJobSchedulerHostedService.cs | 2 +- .../InvoiceNotificationManager.cs | 2 -- BTCPayServer/Models/InvoiceResponse.cs | 4 +-- BTCPayServer/Payments/Changelly/Changelly.cs | 4 +-- BTCPayServer/Program.cs | 2 +- BTCPayServer/Services/Apps/AppService.cs | 2 +- BTCPayServer/Services/DynamicDnsSettings.cs | 3 +- .../Services/Invoices/InvoiceEntity.cs | 4 +-- BTCPayServer/Services/Mails/EmailSettings.cs | 3 +- .../Services/Stores/StoreRepository.cs | 4 +-- Build/Common.csproj | 2 +- 20 files changed, 53 insertions(+), 50 deletions(-) diff --git a/BTCPayServer.Tests/BTCPayServer.Tests.csproj b/BTCPayServer.Tests/BTCPayServer.Tests.csproj index ebbf12963..f76054a8e 100644 --- a/BTCPayServer.Tests/BTCPayServer.Tests.csproj +++ b/BTCPayServer.Tests/BTCPayServer.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index c54611d21..e2c159b32 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -28,26 +28,26 @@ - - - + + + - + all runtime; build; native; contentfiles; analyzers - + - + - - - + + + all @@ -56,17 +56,17 @@ - - - - - + + + + + - + diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 95bc3e728..9f8af315c 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -374,7 +374,7 @@ namespace BTCPayServer.Controllers { if (invoiceId != expectedId || webSocket.State != WebSocketState.Open) return; - CancellationTokenSource cts = new CancellationTokenSource(); + using CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(5000); try { @@ -500,7 +500,7 @@ namespace BTCPayServer.Controllers public async Task CreateInvoice() { var stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), nameof(StoreData.Id), nameof(StoreData.StoreName), null); - if (stores.Count() == 0) + if (!stores.Any()) { TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction"; return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"); @@ -524,7 +524,7 @@ namespace BTCPayServer.Controllers return View(model); } - if (store.GetSupportedPaymentMethods(_NetworkProvider).Count() == 0) + if (!store.GetSupportedPaymentMethods(_NetworkProvider).Any()) { ModelState.AddModelError(nameof(model.StoreId), "You need to configure the derivation scheme in order to create an invoice"); return View(model); @@ -624,7 +624,7 @@ namespace BTCPayServer.Controllers { case JTokenType.Array: var items = item.Value.AsEnumerable().ToList(); - for (var i = 0; i < items.Count(); i++) + for (var i = 0; i < items.Count; i++) { result.Add($"{item.Key}[{i}]", ParsePosData(items[i].ToString())); } diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index bf5a2ecc7..2d732b0f9 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -1121,9 +1121,11 @@ namespace BTCPayServer.Controllers { try { - var client = model.Settings.CreateSmtpClient(); - var message = model.Settings.CreateMailMessage(new MailAddress(model.TestEmail), "BTCPay test", "BTCPay test"); - await client.SendMailAsync(message); + using (var client = model.Settings.CreateSmtpClient()) + using (var message = model.Settings.CreateMailMessage(new MailAddress(model.TestEmail), "BTCPay test", "BTCPay test")) + { + await client.SendMailAsync(message); + } TempData[WellKnownTempData.SuccessMessage] = "Email sent to " + model.TestEmail + ", please, verify you received it"; } catch (Exception ex) diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index e249d9522..1503c1a0f 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -117,7 +117,8 @@ namespace BTCPayServer.Controllers { UTF8Encoding UTF8NOBOM = new UTF8Encoding(false); var bytes = UTF8NOBOM.GetBytes(JsonConvert.SerializeObject(result, network.NBXplorerNetwork.JsonSerializerSettings)); - await webSocket.SendAsync(new ArraySegment(bytes), WebSocketMessageType.Text, true, new CancellationTokenSource(2000).Token); + using var cts = new CancellationTokenSource(2000); + await webSocket.SendAsync(new ArraySegment(bytes), WebSocketMessageType.Text, true, cts.Token); } } catch { } diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 70c0dad9f..11d89f851 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -750,7 +750,7 @@ namespace BTCPayServer.Controllers ViewBag.ShowMenu = false; var stores = await _Repo.GetStoresByUserId(userId); model.Stores = new SelectList(stores.Where(s => s.Role == StoreRoles.Owner), nameof(CurrentStore.Id), nameof(CurrentStore.StoreName)); - if (model.Stores.Count() == 0) + if (!model.Stores.Any()) { TempData[WellKnownTempData.ErrorMessage] = "You need to be owner of at least one store before pairing"; return RedirectToAction(nameof(UserStoresController.ListStores), "UserStores"); @@ -827,9 +827,9 @@ namespace BTCPayServer.Controllers if (pairingResult == PairingResult.Complete || pairingResult == PairingResult.Partial) { var excludeFilter = store.GetStoreBlob().GetExcludedPaymentMethods(); - StoreNotConfigured = store.GetSupportedPaymentMethods(_NetworkProvider) + StoreNotConfigured = !store.GetSupportedPaymentMethods(_NetworkProvider) .Where(p => !excludeFilter.Match(p.PaymentId)) - .Count() == 0; + .Any(); TempData[WellKnownTempData.SuccessMessage] = "Pairing is successful"; if (pairingResult == PairingResult.Partial) TempData[WellKnownTempData.SuccessMessage] = "Server initiated pairing code: " + pairingCode; diff --git a/BTCPayServer/EventAggregator.cs b/BTCPayServer/EventAggregator.cs index 97b90ac80..91d585598 100644 --- a/BTCPayServer/EventAggregator.cs +++ b/BTCPayServer/EventAggregator.cs @@ -63,8 +63,8 @@ namespace BTCPayServer public async Task WaitNext(Func predicate, CancellationToken cancellation = default(CancellationToken)) { TaskCompletionSource tcs = new TaskCompletionSource(); - var subscription = Subscribe((a, b) => { if (predicate(b)) { tcs.TrySetResult(b); a.Unsubscribe(); } }); - using (cancellation.Register(() => { tcs.TrySetCanceled(); subscription.Unsubscribe(); })) + using var subscription = Subscribe((a, b) => { if (predicate(b)) { tcs.TrySetResult(b); a.Unsubscribe(); } }); + using (cancellation.Register(() => { tcs.TrySetCanceled(); })) { return await tcs.Task.ConfigureAwait(false); } diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index 5a8b25d6f..4c300c1b0 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -126,9 +126,11 @@ namespace BTCPayServer { if (webSocket.State == WebSocketState.Open) { - CancellationTokenSource cts = new CancellationTokenSource(); - cts.CancelAfter(5000); - await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cts.Token); + using (CancellationTokenSource cts = new CancellationTokenSource()) + { + cts.CancelAfter(5000); + await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cts.Token); + } } } catch { } diff --git a/BTCPayServer/Extensions/OpenIddictExtensions.cs b/BTCPayServer/Extensions/OpenIddictExtensions.cs index 14ee02ccd..93814bb34 100644 --- a/BTCPayServer/Extensions/OpenIddictExtensions.cs +++ b/BTCPayServer/Extensions/OpenIddictExtensions.cs @@ -14,7 +14,7 @@ namespace BTCPayServer { var file = Path.Combine(configuration.GetDataDir(), fileName); - var rsa = new RSACryptoServiceProvider(2048); + using var rsa = new RSACryptoServiceProvider(2048); if (File.Exists(file)) { rsa.FromXmlString2(File.ReadAllText(file)); diff --git a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs index 1d76e2715..adb21c784 100644 --- a/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs +++ b/BTCPayServer/HostedServices/BackgroundJobSchedulerHostedService.cs @@ -83,7 +83,7 @@ namespace BTCPayServer.HostedServices { lock (_Processing) { - return _Processing.Count(); + return _Processing.Count; } } diff --git a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs index 1cb312cec..075a6532d 100644 --- a/BTCPayServer/HostedServices/InvoiceNotificationManager.cs +++ b/BTCPayServer/HostedServices/InvoiceNotificationManager.cs @@ -118,8 +118,6 @@ namespace BTCPayServer.HostedServices #pragma warning restore CS0618 } - CancellationTokenSource cts = new CancellationTokenSource(10000); - if (!String.IsNullOrEmpty(invoice.NotificationEmail)) { var emailBody = NBitcoin.JsonConverters.Serializer.ToString(notification); diff --git a/BTCPayServer/Models/InvoiceResponse.cs b/BTCPayServer/Models/InvoiceResponse.cs index b3a72fe67..ec704e984 100644 --- a/BTCPayServer/Models/InvoiceResponse.cs +++ b/BTCPayServer/Models/InvoiceResponse.cs @@ -244,10 +244,10 @@ namespace BTCPayServer.Models } [JsonProperty("paymentSubtotals")] - public Dictionary PaymentSubtotals { get; set; } + public Dictionary PaymentSubtotals { get; set; } [JsonProperty("paymentTotals")] - public Dictionary PaymentTotals { get; set; } + public Dictionary PaymentTotals { get; set; } [JsonProperty("amountPaid", DefaultValueHandling = DefaultValueHandling.Include)] public long AmountPaid { get; set; } diff --git a/BTCPayServer/Payments/Changelly/Changelly.cs b/BTCPayServer/Payments/Changelly/Changelly.cs index 2305d7137..ca5e921b6 100644 --- a/BTCPayServer/Payments/Changelly/Changelly.cs +++ b/BTCPayServer/Payments/Changelly/Changelly.cs @@ -42,11 +42,11 @@ namespace BTCPayServer.Payments.Changelly private async Task> PostToApi(string message) { - var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(_apisecret)); + using var hmac = new HMACSHA512(Encoding.UTF8.GetBytes(_apisecret)); var hashMessage = hmac.ComputeHash(Encoding.UTF8.GetBytes(message)); var sign = ToHexString(hashMessage); - var request = new HttpRequestMessage(HttpMethod.Post, ""); + using var request = new HttpRequestMessage(HttpMethod.Post, ""); request.Headers.Add("sign", sign); request.Content = new StringContent(message, Encoding.UTF8, "application/json"); diff --git a/BTCPayServer/Program.cs b/BTCPayServer/Program.cs index 3dbfd635d..69bb07d2e 100644 --- a/BTCPayServer/Program.cs +++ b/BTCPayServer/Program.cs @@ -29,7 +29,7 @@ namespace BTCPayServer IWebHost host = null; var processor = new ConsoleLoggerProcessor(); CustomConsoleLogProvider loggerProvider = new CustomConsoleLogProvider(processor); - var loggerFactory = new LoggerFactory(); + using var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(loggerProvider); var logger = loggerFactory.CreateLogger("Configuration"); try diff --git a/BTCPayServer/Services/Apps/AppService.cs b/BTCPayServer/Services/Apps/AppService.cs index 882ee0c48..e824fdcfd 100644 --- a/BTCPayServer/Services/Apps/AppService.cs +++ b/BTCPayServer/Services/Apps/AppService.cs @@ -304,7 +304,7 @@ namespace BTCPayServer.Services.Apps { if (string.IsNullOrWhiteSpace(template)) return Array.Empty(); - var input = new StringReader(template); + using var input = new StringReader(template); YamlStream stream = new YamlStream(); stream.Load(input); var root = (YamlMappingNode)stream.Documents[0].RootNode; diff --git a/BTCPayServer/Services/DynamicDnsSettings.cs b/BTCPayServer/Services/DynamicDnsSettings.cs index d840fb034..e82ad0677 100644 --- a/BTCPayServer/Services/DynamicDnsSettings.cs +++ b/BTCPayServer/Services/DynamicDnsSettings.cs @@ -41,7 +41,8 @@ namespace BTCPayServer.Services string errorMessage = null; try { - var result = await httpClient.SendAsync(CreateUpdateRequest()); + using var request = CreateUpdateRequest(); + var result = await httpClient.SendAsync(request); if (!result.IsSuccessStatusCode) { try diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index 7b86d3f56..22e67eb6a 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -394,8 +394,8 @@ namespace BTCPayServer.Services.Invoices #pragma warning restore CS0618 // Type or member is obsolete Currency = ProductInformation.Currency, Flags = new Flags() { Refundable = Refundable }, - PaymentSubtotals = new Dictionary(), - PaymentTotals = new Dictionary(), + PaymentSubtotals = new Dictionary(), + PaymentTotals = new Dictionary(), SupportedTransactionCurrencies = new Dictionary(), Addresses = new Dictionary(), PaymentCodes = new Dictionary(), diff --git a/BTCPayServer/Services/Mails/EmailSettings.cs b/BTCPayServer/Services/Mails/EmailSettings.cs index c3cdef8a3..7068a6e13 100644 --- a/BTCPayServer/Services/Mails/EmailSettings.cs +++ b/BTCPayServer/Services/Mails/EmailSettings.cs @@ -52,10 +52,9 @@ namespace BTCPayServer.Services.Mails public bool IsComplete() { - SmtpClient smtp = null; try { - smtp = CreateSmtpClient(); + using var smtp = CreateSmtpClient(); return true; } catch { } diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index 4fb16edb1..8f202cc1b 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -118,7 +118,7 @@ namespace BTCPayServer.Services.Stores { if (!ctx.Database.SupportDropForeignKey()) return; - foreach (var store in await ctx.Stores.Where(s => s.UserStores.Where(u => u.Role == StoreRoles.Owner).Count() == 0).ToArrayAsync()) + foreach (var store in await ctx.Stores.Where(s => !s.UserStores.Where(u => u.Role == StoreRoles.Owner).Any()).ToArrayAsync()) { ctx.Stores.Remove(store); } @@ -145,7 +145,7 @@ namespace BTCPayServer.Services.Stores { if (ctx.Database.SupportDropForeignKey()) { - if (await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.Role == StoreRoles.Owner).CountAsync() == 0) + if (!await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.Role == StoreRoles.Owner).AnyAsync()) { var store = await ctx.Stores.FindAsync(storeId); if (store != null) diff --git a/Build/Common.csproj b/Build/Common.csproj index 8175e8a6c..7a58a3be2 100644 --- a/Build/Common.csproj +++ b/Build/Common.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 $(TargetFrameworkOverride) - NU1701,CA1816,CA1308,CA1810,CA2208 + NU1701,CA1816,CA1308,CA1810,CA2208,CA1303,CA2000 8.0