private async Task SendProduct(Product product) { IConfigurationSection cfgColors = _config.GetSection("BackgroundColors"); List <Webhook> webhooks = GetWebhooks(); WebhookPayload payload = new WebhookPayload(product); Dictionary <string, int> colors = cfgColors.Get <Dictionary <string, int> >(); List <Webhook> webhooksInArchive = _archive.GetWebhooksOfProduct(product.ProductUrl); foreach (Embed embed in payload.embeds) { string[] elems = product.MachineName.Split("_"); string key = elems[elems.Length - 1]; if (colors.ContainsKey(key)) { embed.color = colors[key]; } } List <Task> tasks = new List <Task>(); List <Webhook> sentWebhooks = new List <Webhook>(); try { foreach (Webhook wh in webhooks) { if (webhooksInArchive.Any(w => w.Hash == wh.Hash) == false) { tasks.Add(SendWebhook(wh.url, payload)); sentWebhooks.Add(wh); } } await Task.WhenAll(tasks); } catch (Exception e) { Log.Logger.Error(e.Message); } finally { UrlWithWebhooks productLabel = new UrlWithWebhooks(); productLabel.Webhooks = webhooksInArchive; productLabel.Url = product.ProductUrl; for (int i = 0; i < tasks.Count; i++) { if (tasks[i].IsCompletedSuccessfully) { productLabel.Webhooks.Add(sentWebhooks[i]); } } if (productLabel.Webhooks.Count > 0) { _archive.AddUrl(productLabel); } } }
public void CanBeSerialized() { Webhook webhook = new Webhook("www.google.com"); UrlWithWebhooks urlWithWebhooks = new UrlWithWebhooks("www.microsoft.com", new List <Webhook>() { webhook }); JsonSerializer.Serialize(urlWithWebhooks); }