Ejemplo n.º 1
0
        private async Task CreateReport(CancellationToken token)
        {
            ITradesFetcher         tradesFetcher    = new TradesFetcher(ConfigurationManager.Service, ConfigurationManager.TradeType, this.logger);
            ITradeVolumeCalculator volumeCalculator = new TradeVolumeCalculator(this.logger);
            IReportCreator         reportCreator    = new ReportCreator(tradesFetcher, volumeCalculator);

            while (!token.IsCancellationRequested)
            {
                await reportCreator.CreateTradeVolumeReportAsync(DateTime.Now, ConfigurationManager.TradeReportsPath);

                this.logger.LogEvent(ServiceEvent.ReportCreatedSuccessfully);

                ConfigurationManager.RefreshAppSettings();

                TimeSpan newInterval = ConfigurationManager.GenerationIntervalInMinutes;

                if (this.IntervalChanged(newInterval))
                {
                    this.logger.LogEvent(ServiceEvent.GenerationIntervalChanged, string.Format("Interval changed to: {0}", newInterval));
                }

                this.logger.LogEvent(ServiceEvent.Sleeping);

                await Task.Delay(newInterval, token);
            }

            this.logger.LogEvent(ServiceEvent.ServiceStopped);
        }
Ejemplo n.º 2
0
        private static async Task CreateReport()
        {
            ITradesFetcher         tradesFetcher    = new TradesFetcher(ConfigurationManager.Service, ConfigurationManager.TradeType, logger);
            ITradeVolumeCalculator volumeCalculator = new TradeVolumeCalculator(logger);
            IReportCreator         reportCreator    = new ReportCreator(tradesFetcher, volumeCalculator);

            while (true)
            {
                await reportCreator.CreateTradeVolumeReportAsync(DateTime.Now, ConfigurationManager.TradeReportsPath);

                logger.LogEvent(ServiceEvent.ReportCreatedSuccessfully);

                ConfigurationManager.RefreshAppSettings();

                TimeSpan newInterval = ConfigurationManager.GenerationIntervalInMinutes;

                if (IntervalChanged(newInterval))
                {
                    initialInterval = newInterval;

                    logger.LogEvent(ServiceEvent.GenerationIntervalChanged, string.Format("Interval changed to: {0}", newInterval));
                }

                logger.LogEvent(ServiceEvent.Sleeping);

                await Task.Delay(newInterval);
            }
        }