Esempio n. 1
0
        public static async Task Run([QueueTrigger("SalesDataQueue")] SaleDataObtainmentResult saleDataObtainmentResult, TraceWriter log)
        {
            log.Info($"C# Queue trigger function processed: SalesDataSaverFunction");

            ISalesHandlerFactory handlerFactory = DependencyContainer.Container.Resolve <ISalesHandlerFactory>();
            SalesHandlerBase     salesHandler   = handlerFactory.GetSalesHandler();
            await salesHandler.HandleSaleDataAsync(saleDataObtainmentResult);
        }
Esempio n. 2
0
        public async virtual Task ConsumeHookAsync(string hookJson)
        {
            if (salesHandlerFactory == null || hookParser == null)
            {
                return;
            }

            var fileEntries = hookParser.GetFileEntriesFromHook(hookJson);

            List <Task>             tasks    = new List <Task>();
            List <SalesHandlerBase> handlers = new List <SalesHandlerBase>();

            foreach (var entry in fileEntries)
            {
                SalesHandlerBase saleFileHandler = salesHandlerFactory.GetSalesHandler();
                handlers.Add(saleFileHandler);

                ISaleDataSource saleDataSource = new GithubSaleDataSource(entry, token);

                Task task = saleDataSource.GetSaleDataAsync()
                            .ContinueWith(saleDataTask =>
                {
                    var saleDataResult = saleDataTask.Result;
                    saleFileHandler.HandleSaleDataAsync(saleDataResult).Wait();
                });
                tasks.Add(task);
            }
            await Task.WhenAll(tasks).ConfigureAwait(false);

            for (int handlerIndex = 0; handlerIndex < handlers.Count; handlerIndex++)
            {
                try
                {
                    handlers[handlerIndex]?.Dispose();
                }
                catch { }
            }
        }