private void Watcher_Changed(object source, FileSystemEventArgs e)
        {
            var fileName         = System.IO.Path.GetFileName(e.FullPath);
            var expectedFileName = Configuration.StatisticsFileName;

            if (fileName == expectedFileName)
            {
                var appData = AppDataManager.ReadFromFile <StatisticsData>(expectedFileName);

                CentralService.UpdateSettings(appData);
            }
        }
        public void Start()
        {
            AppData        = AppDataManager.ReadFromFile <AppData>(Configuration.AppFileName);
            StatisticsData = AppDataManager.ReadFromFile <StatisticsData>(Configuration.StatisticsFileName);

            var messageQueueName = Configuration.MessageQueueName;

            _queue = MessageQueue.Exists(messageQueueName) ?
                     new MessageQueue(messageQueueName) : MessageQueue.Create(messageQueueName);

            foreach (var file in Directory.GetFiles(Configuration.DirectoryPath))
            {
                _fileProcessor.ProcessFile(file);
            }
        }
        public void Stop()
        {
            var messageQueueName = Configuration.MessageQueueName;

            MessageQueue.Delete(messageQueueName);

            if (_pdfGenerator.IsSaved)
            {
                return;
            }

            try
            {
                _pdfGenerator.SaveDocument();
                AppData.CountGeneratedPDFFiles++;
                AppDataManager.WrireToFile(Configuration.AppFileName, AppData);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
        private void OnTimedSaveDocumentEvent(object source, ElapsedEventArgs e)
        {
            var milliseconds = _pdfGenerator.LastImageDateTime.HasValue ?
                               (DateTime.Now - _pdfGenerator.LastImageDateTime.Value).Minutes : -1;

            if (milliseconds == -1 || milliseconds < StatisticsData.TimeInterval ||
                _pdfGenerator.PreprocessedImagesCount <= 0 || _pdfGenerator.IsSaved)
            {
                return;
            }

            try
            {
                _pdfGenerator.SaveDocument();
                AppData.CountGeneratedPDFFiles++;
                AppDataManager.WrireToFile(Configuration.AppFileName, AppData);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
        }