Exemplo n.º 1
0
        public void Start()
        {
            var fileOptions = _systemConfiguration.GetConfigurationClass(new WatcherOptions());

            Logger.LogFilePath = fileOptions.GetOption <string>("LogFilePath");

            Logger.RecordStatusAsync("The service starts...");
            var serverOptions = _systemConfiguration.GetConfigurationClass(new ServerOptions());

            var        connectionString = (string)serverOptions.GetField("connectionString").GetValue(null);
            DataAccess dataAccess       = new DataAccess(connectionString);

            Logger.DataAccess = dataAccess;

            sourceDirectory = fileOptions.GetOption <string>("SourceDirectory");
            XMLGenerator xmlGenerator    = new XMLGenerator();
            Reporter     reporter        = new Reporter(sourceDirectory, dataAccess, xmlGenerator);
            var          reporterOptions = _systemConfiguration.GetConfigurationClass(new ReporterOptions());
            var          hours           = reporterOptions.GetOption <int>("FrequencyOfReportHours");
            var          minutes         = reporterOptions.GetOption <int>("FrequencyOfReportMinutes");
            var          seconds         = reporterOptions.GetOption <int>("FrequencyOfReportSeconds");

            Logger.RecordStatusAsync("The service started...");
            while (_enabled)
            {
                reporter.CreateNewReportAsync();
                Thread.Sleep(new TimeSpan(hours, minutes, seconds));
            }
        }
Exemplo n.º 2
0
        public void Start()
        {
            SystemConfiguration = new SystemConfiguration(xmlFileName: "config.xml");
            _watcherOptions     = SystemConfiguration.GetConfigurationClass(new WatcherOptions());
            Logger.LogFilePath  = _watcherOptions.GetOption <string>("LogFilePath");
            try
            {
                _isNeedToLogWatcher = _watcherOptions.GetOption <bool>("NeedToLog");
            }
            catch
            {
                Logger.RecordStatus("Warning, watcher need to log option was not found in the config");
                _isNeedToLogWatcher = true;
            }
            if (_isNeedToLogWatcher)
            {
                Logger.RecordStatus("System configuration has been injected to the program...");
                Logger.RecordStatus("The service starts...");
            }
            var tempAes   = Aes.Create();
            var aesKey    = tempAes.Key;
            var aesIV     = tempAes.IV;
            var extractor = new Extractor(_watcherOptions.GetOption <string>("TargetDirectory"), aesKey, aesIV);

            this._extractor                = extractor;
            this._watchedFolder            = _watcherOptions.GetOption <string>("SourceDirectory");
            _watcher                       = new FileSystemWatcher(_watchedFolder);
            _watcher.Deleted              += WatcherDeleted;
            _watcher.Created              += WatcherCreated;
            _watcher.Renamed              += WatcherRenamed;
            _watcher.IncludeSubdirectories = true;
            _watcher.EnableRaisingEvents   = true;
            if (_isNeedToLogWatcher)
            {
                Logger.RecordStatus("The service started...");
            }
            _enabled = true;
            while (_enabled)
            {
                Thread.Sleep(1000);
            }
        }