public DataProdiverCache(ISubcaseDataProdiver dataProvider, ILogger logger, TimeSpan refreshTimeout)
 {
     _dataProdiver   = dataProvider;
     _refreshTimeout = refreshTimeout;
     _logger         = logger;
     _cache          = new Dictionary <string, CachedSubcases>();
 }
Ejemplo n.º 2
0
        public Uploader(ISubcaseDataProdiver dataProdiver, DocumentClient documentClient, ILogger logger)
        {
            _dataProdiver   = dataProdiver;
            _documentClient = documentClient;
            _logger         = logger;

            InitializeAsync().Wait();
        }
Ejemplo n.º 3
0
        public void StartMonitoring()
        {
            try
            {
                var builder = new ConfigurationBuilder()
                              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                              .AddUserSecrets("28e6f711-a4c4-4cef-9e37-50ebfee35f91");
                var configuration = builder.Build();

                var dataProviderName = configuration["SubcaseDataProvider"];
                _logger.LogInformation($"Data provider: {dataProviderName}");

                ISubcaseDataProdiver dataProvider = null;
                if (String.Equals("Random", dataProviderName, StringComparison.OrdinalIgnoreCase))
                {
                    _logger.LogInformation("Using random data provider");
                    dataProvider = new RandomDataProvider();
                }
                else if (String.Equals("Report", dataProviderName, StringComparison.OrdinalIgnoreCase))
                {
                    _logger.LogInformation("Using SSRS report data provider");
                    var reportServerClient = _serviceProvider.GetService <IReportServerClient>();
                    dataProvider = new ReportServerDataProvider(_loggerFactory.CreateLogger("ReportServerDataProvider"), reportServerClient);
                }
                else
                {
                    throw new ApplicationException($"Unsupported data provider: {dataProviderName}");
                }

                var endpointUri = configuration["CosmosDB:EndpointUri"];
                var primaryKey  = configuration["CosmosDB:PrimaryKey"];

                _logger.LogInformation("Using database endpoint {0}", endpointUri);
                var documentClient = new DocumentClient(new Uri(endpointUri), primaryKey);

                var uploader = new Uploader(dataProvider, documentClient, _loggerFactory.CreateLogger("Uploader"));

                _timer.Elapsed += (sender, e) =>
                {
                    _logger.LogInformation("Update started...");

                    uploader.UpdateAsync().Wait();
                    _logger.LogInformation("Update completed");
                };

                _timer.AutoReset = true;
                _timer.Enabled   = true;
                _timer.Start();

                _logger.LogInformation($"Periodic update started at every {_timer.Interval/60000} min.");

                // await TestReadSubcasesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Ejemplo n.º 4
0
 public SubcasesController(ISubcaseDataProdiver dataProdiver, ILogger <SubcasesController> logger)
 {
     dataProdiver_ = dataProdiver;
     logger_       = logger;
 }