public async Task <IActionResult> Test(
            TestTemplateViewModel model,
            [FromServices] IEmailQueueBlobStore blobStore,
            [FromServices] IEmailQueueSender emailSender,
            CancellationToken cancellationToken)
        {
            if (ModelState.IsValid)
            {
                var token = EmailQueueToken.Create(model.ApplicationId);
                var param = new EmailMessageParams
                {
                    ApplicationId = model.ApplicationId,
                    TemplateId    = model.TemplateId,
                    To            = new List <string> {
                        model.EmailAddress
                    },
                    Culture = model.Language,
                    Data    = JObject.Parse(model.SampleData).ToObject <Dictionary <string, object> >()
                };

                await blobStore.AddAsync(token, param, cancellationToken);

                await emailSender.SendAsync(token, cancellationToken);

                Response.StatusCode = (int)HttpStatusCode.Accepted;
                return(RedirectToAction(nameof(Details), new { id = model.TemplateId }));
            }

            // TODO: reload translations
            return(View(model));
        }
예제 #2
0
        private static void SetupDependencies(
            out IEmailQueueReceiver <AzureEmailQueueMessage> receiver,
            out IEmailQueueBlobStore blobStore,
            out EmailServiceContext context,
            out IMemoryCache cache,
            out IEmailLogWriter logWriter)
        {
            var storageOptions = Options.Create(new AzureStorageOptions
            {
                ConnectionString = Configuration.GetConnectionString("Storage")
            });

            receiver  = new StorageEmailQueue(storageOptions, LoggerFactory);
            blobStore = new AzureEmailQueueBlobStore(storageOptions, LoggerFactory);
            logWriter = new StorageEmailLog(storageOptions, LoggerFactory);

            var cacheOptions = Options.Create(new MemoryCacheOptions
            {
                CompactOnMemoryPressure = true,
                ExpirationScanFrequency = TimeSpan.FromMinutes(1)
            });

            cache = new MemoryCache(cacheOptions);

            var builder = new DbContextOptionsBuilder <EmailServiceContext>();

            builder.UseSqlServer(Configuration.GetConnectionString("SqlServer"));
            builder.UseMemoryCache(cache);
            context = new EmailServiceContext(builder.Options);
        }
 public MessagesController(
     IEmailQueueSender sender,
     IEmailQueueBlobStore blobStore,
     IEmailLogReader logReader,
     IEmailLogWriter logWriter,
     ILoggerFactory loggerFactory)
 {
     _sender    = sender;
     _blobStore = blobStore;
     _logReader = logReader;
     _logWriter = logWriter;
     _logger    = loggerFactory.CreateLogger <MessagesController>();
 }
예제 #4
0
 public QueueProcessor(
     EmailServiceContext db,
     IEmailQueueReceiver <TMessage> receiver,
     IEmailQueueBlobStore blobStore,
     IEmailTransportFactory transportFactory,
     IEmailLogWriter logWriter,
     ILoggerFactory loggerFactory)
 {
     _db               = db;
     _receiver         = receiver;
     _blobStore        = blobStore;
     _transportFactory = transportFactory;
     _logWriter        = logWriter;
     _logger           = loggerFactory.CreateLogger <QueueProcessor <TMessage> >();
 }