Esempio n. 1
0
        public async Task CreateReport(AssetTransactionReportQueueCommand command)
        {
            try
            {
                await _log.WriteInfoAsync(nameof(AssetTransactionsQueueFunctions),
                                          nameof(CreateReport),
                                          command.ToJson(), "Started");

                await _metadataRepository.SetProcessing(command.AssetId);

                var reportDate = DateTime.UtcNow;

                var reportData = await _reportService.GetTransactionsReport(command.AssetId);


                var saveResult = await _reportStorage.SaveXlsxReport(command.AssetId, reportData);

                var emailMes = new EmailMessage
                {
                    Subject  = $"Report for assetId {command.AssetId} at {reportDate:f}",
                    TextBody = $"Report for assetId {command.AssetId} at {reportDate:f} - {saveResult.Url}",
                };

                if (!string.IsNullOrEmpty(command.Email))
                {
                    await _emailSenderProducer.SendAsync(emailMes, new EmailAddressee()
                    {
                        DisplayName = command.Email, EmailAddress = command.Email
                    });
                }

                await _metadataRepository.SetDone(command.AssetId, saveResult.Url);

                await _log.WriteInfoAsync(nameof(AssetTransactionsQueueFunctions),
                                          nameof(CreateReport),
                                          command.ToJson(), "Done");
            }
            catch (Exception e)
            {
                await _log.WriteFatalErrorAsync(nameof(AssetTransactionsQueueFunctions),
                                                nameof(CreateReport),
                                                command.ToJson(), e);

                await _metadataRepository.SetError(command.AssetId, e.ToString());

                throw;
            }
        }
Esempio n. 2
0
        public async Task CreateCommand(string assetId, string email)
        {
            var msg = new AssetTransactionReportQueueCommand
            {
                AssetId = assetId,
                Email   = email
            };

            await _queue.PutRawMessageAsync(msg.ToJson());
        }