Exemple #1
0
 public static void Validate(SyncManagerConfig config)
 {
     if (string.IsNullOrEmpty(config.RemoteFilename))
     {
         throw new FormatException($"Failed to convert null or empty value to remote config filename");
     }
     if (string.IsNullOrEmpty(config.LocalFilename))
     {
         throw new FormatException($"Failed to convert null or empty value to local config filename");
     }
     if (config.Interval < 0)
     {
         throw new FormatException($"Failed to convert {config.Interval} to sync interval");
     }
     if (config.FilterKey == null)
     {
         throw new FormatException($"Failed to convert null to filter key");
     }
     if (config.FilterValue == null)
     {
         throw new FormatException($"Failed to convert null to filter value");
     }
     if (string.IsNullOrEmpty(config.LocalConfigsPath))
     {
         throw new FormatException($"Failed to convert null or empty value to local configs path");
     }
     if (string.IsNullOrEmpty(config.WorkDirectory))
     {
         throw new FormatException($"Failed to convert null or empty value to work directory");
     }
 }
Exemple #2
0
        public SyncManager(ILogger <SyncManager> logger, IOptions <SyncManagerConfig> options, IServiceScopeFactory scopeFactory)
        {
            _logger = logger;
            SyncManagerConfig.Validate(options.Value);
            _remoteFilename   = options.Value.RemoteFilename;
            _localFilename    = options.Value.LocalFilename;
            _filter           = new KeyValuePair <string, string>(options.Value.FilterKey, options.Value.FilterValue);
            _localConfigsPath = options.Value.LocalConfigsPath;
            _workDirectory    = options.Value.WorkDirectory;
            var scope = scopeFactory.CreateScope();

            _remoteManager  = scope.ServiceProvider.GetRequiredService <AsterManagerRemote>();
            _localManager   = scope.ServiceProvider.GetRequiredService <AsterManagerLocal>();
            _timer          = new Timer(TimeSpan.FromSeconds(options.Value.Interval).TotalMilliseconds);
            _timer.Elapsed += TimerElapsed;
            SetupLocalDirectory(_workDirectory);
        }