public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var bankTransactionRepository           = new TableStorageService <BankTransaction>(log, ConnectionString, $"{My_Name}BankTransaction");
            var bankTransactionStatisticsRepository = new TableStorageService <BankTransactionStatistics>(log, ConnectionString, $"{My_Name}BankTransactionStatistics");

            SeedData(bankTransactionRepository);

            // Generate BankTransactionStatistics from all senders by aggregating the total sum of their transactions

            var entries     = bankTransactionRepository.GetAllEntries();
            var listOfUsers = new Dictionary <string, double>();

            foreach (var user in entries)
            {
                if (listOfUsers.ContainsKey(user.PartitionKey))
                {
                    listOfUsers[user.PartitionKey] += user.Ammount;
                }
                else
                {
                    listOfUsers.Add(user.PartitionKey, user.Ammount);
                }
            }

            foreach (var stat in listOfUsers)
            {
                bankTransactionStatisticsRepository.InsertOrUpdateEntry(new BankTransactionStatistics());
            }
        }
Exemplo n.º 2
0
        public static void Run([ServiceBusTrigger("myqueue-1", Connection = "ConnectionStringKey")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

            var myValuesRepository = new TableStorageService <MyValue>(log, TableStorageConnectionString, MyValuesTableName);
            var mySumRepository    = new TableStorageService <MyValue>(log, TableStorageConnectionString, MySumTableName);

            var myValue = JsonConvert.DeserializeObject <MyValue>(myQueueItem);

            myValuesRepository.InsertOrUpdateEntry(myValue);

            // this is not memory efficient
            var latestValues = myValuesRepository.GetAllEntries().OrderBy(v => v.Timestamp).TakeLast(10);
            var totalSum     = latestValues.Sum(v => v.Value);

            var myNewestSum = new MyValue()
            {
                Value = totalSum
            };

            mySumRepository.InsertOrUpdateEntry(myNewestSum);
        }
        public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var bankTransactionRepository           = new TableStorageService <BankTransaction>(log, ConnectionString, $"{My_Name}BankTransaction");
            var bankTransactionStatisticsRepository = new TableStorageService <BankTransactionStatistics>(log, ConnectionString, $"{My_Name}BankTransactionStatistics");

            SeedData(bankTransactionRepository);

            // Generate BankTransactionStatistics from all senders by aggregating the total sum of their transactions

            var entities = bankTransactionRepository.GetAllEntries();
            var senders  = entities.Select(e => e.PartitionKey).Distinct();

            foreach (var sender in senders)
            {
                var transactions = bankTransactionRepository.GetByPartitionId(sender);
                var totalAmmount = transactions.Sum(t => t.Ammount);

                var existingBankTransactionStatistics = bankTransactionStatisticsRepository.GetByPartitionId(sender).FirstOrDefault();

                if (existingBankTransactionStatistics != null)
                {
                    existingBankTransactionStatistics.Ammount = totalAmmount;
                }
                else
                {
                    existingBankTransactionStatistics = new BankTransactionStatistics(Guid.NewGuid().ToString(), sender)
                    {
                        Ammount = totalAmmount
                    };
                }

                bankTransactionStatisticsRepository.InsertOrUpdateEntry(existingBankTransactionStatistics);
            }
        }
Exemplo n.º 4
0
 public IEnumerable <MyValue> Get()
 {
     return(valuesRepository.GetAllEntries());
 }