diff --git a/.editorconfig b/.editorconfig index 7d842c897..7ea42f69c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -136,10 +136,10 @@ dotnet_style_qualification_for_property = false:suggestion dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_event = false:suggestion -# only use var when it's obvious what the variable type is -csharp_style_var_for_built_in_types = false:none -csharp_style_var_when_type_is_apparent = false:none -csharp_style_var_elsewhere = false:suggestion +# always use var when possible +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion # use language keywords instead of BCL types dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion @@ -186,6 +186,13 @@ csharp_style_expression_bodied_properties = true:none csharp_style_expression_bodied_indexers = true:none csharp_style_expression_bodied_accessors = true:none +# Property and accessor preferences +csharp_style_auto_properties = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_keep_existing_attribute_arrangement = true +csharp_keep_existing_initializer_arrangement = true +csharp_prefer_simple_auto_property = true:suggestion + # Pattern matching csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion csharp_style_pattern_matching_over_as_with_null_check = true:suggestion diff --git a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs index b1e7df8c9..1413ae141 100644 --- a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookDeliveryRequest.cs @@ -4,7 +4,6 @@ using BTCPayServer.Client.Models; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Services.Invoices; -using MimeKit; using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -23,7 +22,7 @@ public class InvoiceWebhookDeliveryRequest( UIStoresController.StoreEmailRule storeEmailRule) { if (storeEmailRule.CustomerEmail && - MailboxAddressValidator.TryParse(Invoice.Metadata.BuyerEmail, out MailboxAddress bmb)) + MailboxAddressValidator.TryParse(Invoice.Metadata.BuyerEmail, out var bmb)) { req.Email ??= string.Empty; req.Email += $",{bmb}"; @@ -36,7 +35,7 @@ public class InvoiceWebhookDeliveryRequest( private string Interpolate(string str) { - string res = str.Replace("{Invoice.Id}", Invoice.Id) + var res = str.Replace("{Invoice.Id}", Invoice.Id) .Replace("{Invoice.StoreId}", Invoice.StoreId) .Replace("{Invoice.Price}", Invoice.Price.ToString(CultureInfo.InvariantCulture)) .Replace("{Invoice.Currency}", Invoice.Currency) diff --git a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookProvider.cs index 62f54d2a9..af7e8f617 100644 --- a/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/InvoiceWebhookProvider.cs @@ -5,7 +5,6 @@ using BTCPayServer.Controllers.Greenfield; using BTCPayServer.Data; using BTCPayServer.Events; using Microsoft.Extensions.Logging; -using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -34,14 +33,14 @@ public class InvoiceWebhookProvider( protected override WebhookSender.WebhookDeliveryRequest CreateDeliveryRequest(InvoiceEvent invoiceEvent, WebhookData webhook) { - WebhookInvoiceEvent webhookEvent = GetWebhookEvent(invoiceEvent)!; - WebhookBlob webhookBlob = webhook?.GetBlob(); + var webhookEvent = GetWebhookEvent(invoiceEvent)!; + var webhookBlob = webhook?.GetBlob(); webhookEvent.InvoiceId = invoiceEvent.InvoiceId; webhookEvent.StoreId = invoiceEvent.Invoice.StoreId; webhookEvent.Metadata = invoiceEvent.Invoice.Metadata.ToJObject(); webhookEvent.WebhookId = webhook?.Id; webhookEvent.IsRedelivery = false; - WebhookDeliveryData delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); + var delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); if (delivery is not null) { webhookEvent.DeliveryId = delivery.Id; @@ -55,14 +54,14 @@ public class InvoiceWebhookProvider( public override WebhookEvent CreateTestEvent(string type, params object[] args) { - string storeId = args[0].ToString(); + var storeId = args[0].ToString(); return new WebhookInvoiceEvent(type, storeId) { InvoiceId = "__test__" + Guid.NewGuid() + "__test__" }; } protected override WebhookInvoiceEvent GetWebhookEvent(InvoiceEvent invoiceEvent) { - InvoiceEventCode eventCode = invoiceEvent.EventCode; - string storeId = invoiceEvent.Invoice.StoreId; + var eventCode = invoiceEvent.EventCode; + var storeId = invoiceEvent.Invoice.StoreId; switch (eventCode) { case InvoiceEventCode.Confirmed: diff --git a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs index 40edbe7ab..8a1c885a4 100644 --- a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookDeliveryRequest.cs @@ -5,7 +5,6 @@ using BTCPayServer.Client.Models; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Services.PaymentRequests; -using MimeKit; using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -21,9 +20,9 @@ public class PaymentRequestWebhookDeliveryRequest( public override Task Interpolate(SendEmailRequest req, UIStoresController.StoreEmailRule storeEmailRule) { - PaymentRequestBlob? blob = evt.Data.GetBlob(); + var blob = evt.Data.GetBlob(); if (storeEmailRule.CustomerEmail && - MailboxAddressValidator.TryParse(blob.Email, out MailboxAddress? bmb)) + MailboxAddressValidator.TryParse(blob.Email, out var bmb)) { req.Email ??= string.Empty; req.Email += $",{bmb}"; @@ -36,11 +35,11 @@ public class PaymentRequestWebhookDeliveryRequest( private string Interpolate(string str, PaymentRequestData data) { - string? id = data.Id; - string trimmedId = $"{id.Substring(0, 7)}...{id.Substring(id.Length - 7)}"; + var id = data.Id; + var trimmedId = $"{id.Substring(0, 7)}...{id.Substring(id.Length - 7)}"; - PaymentRequestBlob? blob = data.GetBlob(); - string res = str.Replace("{PaymentRequest.Id}", id) + var blob = data.GetBlob(); + var res = str.Replace("{PaymentRequest.Id}", id) .Replace("{PaymentRequest.TrimmedId}", trimmedId) .Replace("{PaymentRequest.Amount}", data.Amount.ToString(CultureInfo.InvariantCulture)) .Replace("{PaymentRequest.Currency}", data.Currency) diff --git a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs index f60e3e08f..02b46b501 100644 --- a/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/PaymentRequestWebhookProvider.cs @@ -4,7 +4,6 @@ using BTCPayServer.Client.Models; using BTCPayServer.Data; using BTCPayServer.Services.PaymentRequests; using Microsoft.Extensions.Logging; -using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -25,7 +24,7 @@ public class PaymentRequestWebhookProvider(EventAggregator eventAggregator, ILog public override WebhookEvent CreateTestEvent(string type, object[] args) { - string storeId = args[0].ToString(); + var storeId = args[0].ToString(); return new WebhookPaymentRequestEvent(type, storeId) { PaymentRequestId = "__test__" + Guid.NewGuid() + "__test__" }; } @@ -44,14 +43,14 @@ public class PaymentRequestWebhookProvider(EventAggregator eventAggregator, ILog protected override WebhookSender.WebhookDeliveryRequest CreateDeliveryRequest(PaymentRequestEvent paymentRequestEvent, WebhookData webhook) { - WebhookBlob webhookBlob = webhook?.GetBlob(); - WebhookPaymentRequestEvent webhookEvent = GetWebhookEvent(paymentRequestEvent)!; + var webhookBlob = webhook?.GetBlob(); + var webhookEvent = GetWebhookEvent(paymentRequestEvent)!; webhookEvent.StoreId = paymentRequestEvent.Data.StoreDataId; webhookEvent.PaymentRequestId = paymentRequestEvent.Data.Id; webhookEvent.Status = paymentRequestEvent.Data.Status; webhookEvent.WebhookId = webhook?.Id; webhookEvent.IsRedelivery = false; - WebhookDeliveryData delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); + var delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); if (delivery is not null) { webhookEvent.DeliveryId = delivery.Id; diff --git a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs index 4c612daac..f4389cb8f 100644 --- a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookDeliveryRequest.cs @@ -27,8 +27,8 @@ public class PayoutWebhookDeliveryRequest( private string Interpolate(string str) { - PayoutBlob? blob = evt.Payout.GetBlob(btcPayNetworkJsonSerializerSettings); - string res = str.Replace("{Payout.Id}", evt.Payout.Id) + var blob = evt.Payout.GetBlob(btcPayNetworkJsonSerializerSettings); + var res = str.Replace("{Payout.Id}", evt.Payout.Id) .Replace("{Payout.PullPaymentId}", evt.Payout.PullPaymentDataId) .Replace("{Payout.Destination}", evt.Payout.DedupId ?? blob.Destination) .Replace("{Payout.State}", evt.Payout.State.ToString()); diff --git a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookProvider.cs index c4f42df86..daed7e0a4 100644 --- a/BTCPayServer/HostedServices/Webhooks/PayoutWebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/PayoutWebhookProvider.cs @@ -4,7 +4,6 @@ using BTCPayServer.Client.Models; using BTCPayServer.Data; using BTCPayServer.Services; using Microsoft.Extensions.Logging; -using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -17,16 +16,16 @@ public class PayoutWebhookProvider( { protected override WebhookSender.WebhookDeliveryRequest CreateDeliveryRequest(PayoutEvent payoutEvent, WebhookData webhook) { - WebhookBlob webhookBlob = webhook?.GetBlob(); + var webhookBlob = webhook?.GetBlob(); - WebhookPayoutEvent webhookEvent = GetWebhookEvent(payoutEvent)!; + var webhookEvent = GetWebhookEvent(payoutEvent)!; webhookEvent.StoreId = payoutEvent.Payout.StoreDataId; webhookEvent.PayoutId = payoutEvent.Payout.Id; webhookEvent.PayoutState = payoutEvent.Payout.State; webhookEvent.PullPaymentId = payoutEvent.Payout.PullPaymentDataId; webhookEvent.WebhookId = webhook?.Id; webhookEvent.IsRedelivery = false; - WebhookDeliveryData delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); + var delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); if (delivery is not null) { webhookEvent.DeliveryId = delivery.Id; @@ -49,7 +48,7 @@ public class PayoutWebhookProvider( public override WebhookEvent CreateTestEvent(string type, object[] args) { - string storeId = args[0].ToString(); + var storeId = args[0].ToString(); return new WebhookPayoutEvent(type, storeId) { PayoutId = "__test__" + Guid.NewGuid() + "__test__" }; } diff --git a/BTCPayServer/HostedServices/Webhooks/PendingTransactionDeliveryRequest.cs b/BTCPayServer/HostedServices/Webhooks/PendingTransactionDeliveryRequest.cs index 57994da95..c929061ed 100644 --- a/BTCPayServer/HostedServices/Webhooks/PendingTransactionDeliveryRequest.cs +++ b/BTCPayServer/HostedServices/Webhooks/PendingTransactionDeliveryRequest.cs @@ -17,7 +17,7 @@ public class PendingTransactionDeliveryRequest( public override Task Interpolate(SendEmailRequest req, UIStoresController.StoreEmailRule storeEmailRule) { - PendingTransactionBlob blob = evt.Data.GetBlob(); + var blob = evt.Data.GetBlob(); // if (storeEmailRule.CustomerEmail && // MailboxAddressValidator.TryParse(Invoice.Metadata.BuyerEmail, out var bmb)) // { @@ -32,10 +32,10 @@ public class PendingTransactionDeliveryRequest( private string Interpolate(string str, PendingTransactionBlob blob) { - string id = evt.Data.TransactionId; - string trimmedId = $"{id.Substring(0, 7)}...{id.Substring(id.Length - 7)}"; + var id = evt.Data.TransactionId; + var trimmedId = $"{id.Substring(0, 7)}...{id.Substring(id.Length - 7)}"; - string res = str.Replace("{PendingTransaction.Id}", id) + var res = str.Replace("{PendingTransaction.Id}", id) .Replace("{PendingTransaction.TrimmedId}", trimmedId) .Replace("{PendingTransaction.StoreId}", evt.Data.StoreId) .Replace("{PendingTransaction.SignaturesCollected}", blob.SignaturesCollected?.ToString()) diff --git a/BTCPayServer/HostedServices/Webhooks/PendingTransactionWebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/PendingTransactionWebhookProvider.cs index 6585542bd..759691d1c 100644 --- a/BTCPayServer/HostedServices/Webhooks/PendingTransactionWebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/PendingTransactionWebhookProvider.cs @@ -4,7 +4,6 @@ using BTCPayServer.Client.Models; using BTCPayServer.Data; using Microsoft.Extensions.Logging; using Newtonsoft.Json; -using WebhookDeliveryData = BTCPayServer.Data.WebhookDeliveryData; namespace BTCPayServer.HostedServices.Webhooks; @@ -33,13 +32,13 @@ public class PendingTransactionWebhookProvider( protected override WebhookSender.WebhookDeliveryRequest CreateDeliveryRequest(PendingTransactionService.PendingTransactionEvent evt, WebhookData webhook) { - WebhookBlob webhookBlob = webhook?.GetBlob(); + var webhookBlob = webhook?.GetBlob(); - WebhookPendingTransactionEvent webhookEvent = GetWebhookEvent(evt)!; + var webhookEvent = GetWebhookEvent(evt)!; webhookEvent.StoreId = evt.Data.StoreId; webhookEvent.WebhookId = webhook?.Id; webhookEvent.IsRedelivery = false; - WebhookDeliveryData delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); + var delivery = webhook is null ? null : WebhookExtensions.NewWebhookDelivery(webhook.Id); if (delivery is not null) { webhookEvent.DeliveryId = delivery.Id; @@ -68,7 +67,7 @@ public class PendingTransactionWebhookProvider( public override WebhookEvent CreateTestEvent(string type, params object[] args) { - string storeId = args[0].ToString(); + var storeId = args[0].ToString(); return new WebhookInvoiceEvent(type, storeId) { InvoiceId = "__test__" + Guid.NewGuid() + "__test__" }; } diff --git a/BTCPayServer/HostedServices/Webhooks/WebhookProvider.cs b/BTCPayServer/HostedServices/Webhooks/WebhookProvider.cs index 0209fd3fd..1a923bbbe 100644 --- a/BTCPayServer/HostedServices/Webhooks/WebhookProvider.cs +++ b/BTCPayServer/HostedServices/Webhooks/WebhookProvider.cs @@ -31,8 +31,9 @@ public abstract class WebhookProvider(EventAggregator eventAggregator, ILogge if (GetWebhookEvent(tEvt) is not { } webhookEvent) return; - WebhookData[] webhooks = await webhookSender.GetWebhooks(webhookEvent.StoreId, webhookEvent.Type); - foreach (WebhookData webhook in webhooks) webhookSender.EnqueueDelivery(CreateDeliveryRequest(tEvt, webhook)); + var webhooks = await webhookSender.GetWebhooks(webhookEvent.StoreId, webhookEvent.Type); + foreach (var webhook in webhooks) + webhookSender.EnqueueDelivery(CreateDeliveryRequest(tEvt, webhook)); EventAggregator.Publish(CreateDeliveryRequest(tEvt, null)); } diff --git a/BTCPayServer/HostedServices/Webhooks/WebhookSender.cs b/BTCPayServer/HostedServices/Webhooks/WebhookSender.cs index 6c633e0c6..41c435339 100644 --- a/BTCPayServer/HostedServices/Webhooks/WebhookSender.cs +++ b/BTCPayServer/HostedServices/Webhooks/WebhookSender.cs @@ -63,7 +63,7 @@ public class WebhookSender( public async Task StopAsync(CancellationToken cancellationToken) { - Task stopping = _processingQueue.Abort(cancellationToken); + var stopping = _processingQueue.Abort(cancellationToken); await stopping; } @@ -76,7 +76,7 @@ public class WebhookSender( public async Task Redeliver(string deliveryId) { - WebhookDeliveryRequest? deliveryRequest = await CreateRedeliveryRequest(deliveryId); + var deliveryRequest = await CreateRedeliveryRequest(deliveryId); if (deliveryRequest is null) return null; EnqueueDelivery(deliveryRequest); @@ -85,18 +85,18 @@ public class WebhookSender( private async Task CreateRedeliveryRequest(string deliveryId) { - await using ApplicationDbContext? ctx = dbContextFactory.CreateContext(); + await using var ctx = dbContextFactory.CreateContext(); var webhookDelivery = await ctx.WebhookDeliveries.AsNoTracking() .Where(o => o.Id == deliveryId) .Select(o => new { o.Webhook, Delivery = o }) .FirstOrDefaultAsync(); if (webhookDelivery is null) return null; - WebhookDeliveryBlob? oldDeliveryBlob = webhookDelivery.Delivery.GetBlob(); - WebhookDeliveryData? newDelivery = WebhookExtensions.NewWebhookDelivery(webhookDelivery.Webhook.Id); + var oldDeliveryBlob = webhookDelivery.Delivery.GetBlob(); + var newDelivery = WebhookExtensions.NewWebhookDelivery(webhookDelivery.Webhook.Id); WebhookDeliveryBlob newDeliveryBlob = new(); newDeliveryBlob.Request = oldDeliveryBlob.Request; - WebhookEvent? webhookEvent = newDeliveryBlob.ReadRequestAs(); + var webhookEvent = newDeliveryBlob.ReadRequestAs(); if (webhookEvent.IsPruned()) return null; webhookEvent.DeliveryId = newDelivery.Id; @@ -113,13 +113,13 @@ public class WebhookSender( private WebhookEvent GetTestWebHook(string storeId, string webhookId, string webhookEventType, WebhookDeliveryData delivery) { - IWebhookProvider? webhookProvider = serviceProvider.GetServices() + var webhookProvider = serviceProvider.GetServices() .FirstOrDefault(provider => provider.GetSupportedWebhookTypes().ContainsKey(webhookEventType)); if (webhookProvider is null) throw new ArgumentException($"Unknown webhook event type {webhookEventType}", webhookEventType); - WebhookEvent? webhookEvent = webhookProvider.CreateTestEvent(webhookEventType, storeId); + var webhookEvent = webhookProvider.CreateTestEvent(webhookEventType, storeId); if (webhookEvent is null) throw new ArgumentException("Webhook provider does not support tests"); @@ -135,8 +135,8 @@ public class WebhookSender( public async Task TestWebhook(string storeId, string webhookId, string webhookEventType, CancellationToken cancellationToken) { - WebhookDeliveryData? delivery = WebhookExtensions.NewWebhookDelivery(webhookId); - WebhookData? webhook = (await StoreRepository.GetWebhooks(storeId)).FirstOrDefault(w => w.Id == webhookId); + var delivery = WebhookExtensions.NewWebhookDelivery(webhookId); + var webhook = (await StoreRepository.GetWebhooks(storeId)).FirstOrDefault(w => w.Id == webhookId); WebhookDeliveryRequest deliveryRequest = new( webhookId, GetTestWebHook(storeId, webhookId, webhookEventType, delivery), @@ -155,16 +155,16 @@ public class WebhookSender( { try { - WebhookBlob? wh = (await StoreRepository.GetWebhook(ctx.WebhookId))?.GetBlob(); + var wh = (await StoreRepository.GetWebhook(ctx.WebhookId))?.GetBlob(); if (wh is null || !wh.ShouldDeliver(ctx.WebhookEvent.Type)) return; - DeliveryResult result = await SendAndSaveDelivery(ctx, cancellationToken); + var result = await SendAndSaveDelivery(ctx, cancellationToken); if (ctx.WebhookBlob.AutomaticRedelivery && !result.Success && result.DeliveryId is not null) { - string? originalDeliveryId = result.DeliveryId; - foreach (TimeSpan wait in new[] + var originalDeliveryId = result.DeliveryId; + foreach (var wait in new[] { TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10) @@ -194,22 +194,22 @@ public class WebhookSender( private async Task SendDelivery(WebhookDeliveryRequest ctx, CancellationToken cancellationToken) { Uri uri = new(ctx.WebhookBlob.Url, UriKind.Absolute); - HttpClient httpClient = GetClient(uri); + var httpClient = GetClient(uri); using HttpRequestMessage request = new(); request.RequestUri = uri; request.Method = HttpMethod.Post; - byte[] bytes = ToBytes(ctx.WebhookEvent); + var bytes = ToBytes(ctx.WebhookEvent); ByteArrayContent content = new(bytes); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using HMACSHA256 hmac = new(_utf8.GetBytes(ctx.WebhookBlob.Secret ?? string.Empty)); - string? sig = Encoders.Hex.EncodeData(hmac.ComputeHash(bytes)); + var sig = Encoders.Hex.EncodeData(hmac.ComputeHash(bytes)); content.Headers.Add("BTCPay-Sig", $"sha256={sig}"); request.Content = content; - WebhookDeliveryBlob deliveryBlob = ctx.Delivery.GetBlob() ?? new WebhookDeliveryBlob(); + var deliveryBlob = ctx.Delivery.GetBlob() ?? new WebhookDeliveryBlob(); deliveryBlob.Request = bytes; try { - using HttpResponseMessage response = await httpClient.SendAsync(request, cancellationToken); + using var response = await httpClient.SendAsync(request, cancellationToken); if (!response.IsSuccessStatusCode) { deliveryBlob.Status = WebhookDeliveryStatus.HttpError; @@ -236,7 +236,7 @@ public class WebhookSender( private async Task SendAndSaveDelivery(WebhookDeliveryRequest ctx, CancellationToken cancellationToken) { - DeliveryResult result = await SendDelivery(ctx, cancellationToken); + var result = await SendDelivery(ctx, cancellationToken); await StoreRepository.AddWebhookDelivery(ctx.Delivery); return result; @@ -244,8 +244,8 @@ public class WebhookSender( private byte[] ToBytes(WebhookEvent webhookEvent) { - string str = JsonConvert.SerializeObject(webhookEvent, Formatting.Indented, DefaultSerializerSettings); - byte[] bytes = _utf8.GetBytes(str); + var str = JsonConvert.SerializeObject(webhookEvent, Formatting.Indented, DefaultSerializerSettings); + var bytes = _utf8.GetBytes(str); return bytes; } @@ -291,15 +291,15 @@ public class WebhookSender( //find all instance of {fieldName*} instead str, then run obj.SelectToken(*) on it while (true) { - int start = str.IndexOf($"{{{fieldName}", StringComparison.InvariantCultureIgnoreCase); + var start = str.IndexOf($"{{{fieldName}", StringComparison.InvariantCultureIgnoreCase); if (start == -1) break; start += fieldName.Length + 1; - int end = str.IndexOf("}", start, StringComparison.InvariantCultureIgnoreCase); + var end = str.IndexOf("}", start, StringComparison.InvariantCultureIgnoreCase); if (end == -1) break; - string jsonpath = str.Substring(start, end - start); - string? result = string.Empty; + var jsonpath = str.Substring(start, end - start); + var result = string.Empty; try { if (string.IsNullOrEmpty(jsonpath))