public async Task <IActionResult> Create(string html, CancellationToken cancellationToken = default) { var host = HttpContext.GetHost(); if (string.IsNullOrWhiteSpace(host)) { return(BadRequest()); } if (await smtpConfigsRepository.Get(c => c.Active, cancellationToken) is Smtp config) { var email = NotificationModelFactory.CreateNotificationModel <IEmailNotificationModel>() .SetConfiguration(config.Host, config.Port, config.Username, config.Password, (SecureSocketOptions)config.SecureSocketOption) .SetAuthors("*****@*****.**", "*****@*****.**") .SetRecipients("*****@*****.**") .SetSubject("Testowa wiadomość") .SetBody(TextFormat.Html, $"<h1>Uruchomiono generator PDF - {DateTime.UtcNow}</h1>") .Encrypt(Keys.RSA.PublicKey); notificationService.Save(email.Serialize()); } var bytes = await this.pdfService.Generate(html, host, cancellationToken); if (bytes is null) { return(BadRequest()); } return(File(bytes, "application/pdf")); }
private Task Scan() { try { this.connection = this.connectionFactory.CreateConnection(); this.model = this.connection.CreateModel(); this.model.BasicQos(prefetchSize: 0, prefetchCount: ushort.MaxValue, global: false); this.consumer = new AsyncEventingBasicConsumer(this.model); this.consumer.Received += async(o, a) => { var body = a.Body.ToArray(); var message = Encoding.UTF8.GetString(body); var type = (NotificationType)JsonConvert.DeserializeObject <JObject>(message).GetValue("notification_type").Value <long>(); switch (type) { case NotificationType.Email: var email = NotificationModelFactory.CreateNotificationModel <IEmailNotificationModel>(message); if (email.Encrypted) { email.Decrypt(Keys.RSA.PrivateKey); } SendEmail(email); break; case NotificationType.Sms: var sms = NotificationModelFactory.CreateNotificationModel <ISmsNotificationModel>(message); if (sms.Encrypted) { sms.Decrypt(Keys.RSA.PrivateKey); } SendSms(sms); break; } Console.WriteLine($"Message Get: {a.DeliveryTag}"); this.model.BasicAck(a.DeliveryTag, false); await Task.Yield(); }; this.model.BasicConsume(this.queue, false, this.consumer); return(Task.CompletedTask); } catch (System.Exception ex) { return(Task.FromException(ex)); } }