コード例 #1
0
        private void DoWork(object state)
        {
            DateTime currentTime = DateTime.Now;

            _logger.LogInformation($"• Start DB syncronization - Started at {currentTime}");
            //
            using (IServiceScope scope = _serviceProvider.CreateScope())
            {
                _dbContext = scope.ServiceProvider.GetRequiredService <DbContextCropioProxy>();
                var api = CropioApi.CreateUsingConfigFile();
                //
                foreach (var ids in api.GetObjectsIds <CO_User>().Data.Paginate(100))
                {
                    foreach (var e in api.GetObjects <CO_User>(ids).Data)
                    {
                        var user = User.FromCropioObj(e);
                        _dbContext.Users.Add(user);
                    }
                    _dbContext.SaveChanges();
                }
                _logger.LogInformation($"  DB syncronization - Users synchronized at {currentTime}");
                //
                foreach (var ids in api.GetObjectsIds <CO_Alert>().Data.Paginate(100))
                {
                    foreach (var e in api.GetObjects <CO_Alert>(ids).Data)
                    {
                        var alert = Alert.FromCropioObj(e);
                        _dbContext.Alerts.Add(alert);
                    }
                    _dbContext.SaveChanges();
                }
                _logger.LogInformation($"  DB syncronization - Alerts synchronized at {currentTime}");
                _logger.LogInformation($"• DB syncronization - Finished at 4{currentTime}");
            }
        }
コード例 #2
0
 public BackgroundTaskService(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
 {
     _serviceProvider = serviceProvider;
     _logger          = loggerFactory.CreateLogger("FileLogger");
     var api = CropioApi.CreateUsingConfigFile();
 }