public async Task Publish(HashSet <Transaction> increment, DateTime incrementFrom, DateTime incrementTo)
        {
            var fileName        = $"transactions-{incrementTo:s}.csv";
            var bccDestinations = string.Join(", ", _settings.Bcc);

            _log.Info($"Sending transactions increment '{fileName}' via email to address '{_settings.To}' and BCC '{bccDestinations}'...");

            using (var stream = new MemoryStream())
            {
                await _writer.WriteAsync(increment, stream, leaveOpen : true);

                stream.Position = 0;

                var base64Report = Convert.ToBase64String(stream.ToArray());
                var message      = new EmailMessage
                {
                    Subject     = $"Lykke transactions batch for the period {incrementFrom:s} - {incrementTo:s}",
                    TextBody    = $"Hi, please find enclosed the Lykke transactions batch for the period {incrementFrom:s} - {incrementTo:s} UTC, best regards",
                    Attachments = new[]
                    {
                        new EmailAttachment(fileName, "text/csv", base64Report)
                    }
                };
                var to = new EmailAddressee {
                    EmailAddress = _settings.To
                };
                var bcc = _settings.Bcc.Select(x => new EmailAddressee {
                    EmailAddress = x
                });

                await _emailSender.SendAsync(message, to, bcc);
            }

            _log.Info($"Transactions increment with {increment.Count} transactions sent via email");
        }
Esempio n. 2
0
        public async Task Publish(HashSet <Transaction> increment, DateTime incrementFrom, DateTime incrementTo)
        {
            var blobName = $"increment-from-{incrementFrom:s}.csv";

            _log.Info($"Saving transactions increment to the BLOB {blobName}...");

            var blob = _blobContainer.GetBlockBlobReference(blobName);

            using (var stream = new MemoryStream())
            {
                await _writer.WriteAsync(increment, stream, leaveOpen : true);

                stream.Position = 0;

                await blob.UploadFromStreamAsync(stream);
            }

            _log.Info($"Transactions increment with {increment.Count} transactions saved to the BLOB");
        }
Esempio n. 3
0
        public async Task Publish(HashSet <Transaction> increment, DateTime incrementFrom, DateTime incrementTo)
        {
            var fileName = $"transactions-{incrementTo:s}.csv";

            _log.Info($"Uploading transactions increment to Slack {fileName}...");

            using (var stream = new MemoryStream())
            {
                await _writer.WriteAsync(increment, stream, leaveOpen : true);

                stream.Position = 0;

                await _client.UploadFileAsync
                (
                    stream.ToArray(),
                    fileName,
                    new[] { _settings.ReportChannel },
                    title : $"Transactions for the period {incrementFrom:s} - {incrementTo:s}"
                );
            }

            _log.Info($"Transactions increment with {increment.Count} transactions uploaded to Slack");
        }
Esempio n. 4
0
        private static async Task RemoveInvalidAddresses(ILogFactory logFactory)
        {
            var assetsClient       = new AssetsClient(logFactory, new AssetsClientSettings());
            var blockchainProvider = new BlockchainsProvider(assetsClient);
            var addressNormalizer  = new AddressNormalizer
                                     (
                logFactory,
                new IAddressNormalizer[]
            {
                new GeneralAddressNormalizer(),
                new BtcAddressNormalizer(blockchainProvider, new BtcSettings {
                    Network = "mainnet"
                }),
                new BchAddressNormalizer(blockchainProvider, new BchSettings {
                    Network = "mainnet"
                }),
                new LtcAddressNormalizer(blockchainProvider, new LtcSettings {
                    Network = "ltc-main"
                }),
                new EthAddressNormalizer(blockchainProvider),
                new XrpAddressNormalizer(blockchainProvider)
            }
                                     );
            var reportReader = new TransactionsReportReader(addressNormalizer);
            var reportWriter = new TransactionsReportWriter();

            Console.WriteLine("Loading...");

            var readStream           = File.Open("transactions.csv", FileMode.Open, FileAccess.Read, FileShare.Read);
            var originalTransactions = await reportReader.ReadAsync
                                       (
                readStream,
                new Progress <int>
                (
                    transactionCount =>
            {
                if (transactionCount % 1000 == 0)
                {
                    Console.WriteLine(transactionCount);
                }
            }
                ),
                leaveOpen : false
                                       );

            Console.WriteLine("Filtering...");

            var filteredTransactions = originalTransactions
                                       .Where
                                       (
                tx => !string.IsNullOrWhiteSpace(tx.Hash) &&
                !string.IsNullOrWhiteSpace(tx.CryptoCurrency) &&
                tx.UserId != Guid.Empty
                                       )
                                       .ToHashSet();

            Console.WriteLine("Saving...");

            var writeStream = File.Open
                              (
                "filtered-transactions.csv",
                FileMode.Create,
                FileAccess.Write,
                FileShare.Read
                              );
            await reportWriter.WriteAsync
            (
                filteredTransactions,
                writeStream,
                new Progress <int>
                (
                    transactionsCount =>
            {
                if (transactionsCount % 1000 == 0)
                {
                    var percent = transactionsCount * 100 / filteredTransactions.Count;

                    Console.WriteLine($"{percent}%");
                }
            }
                ),
                leaveOpen : false
            );
        }