コード例 #1
0
        public FolderMonitor(IConfigLoader loader, IFileProcessor fileProcessor, IReceiptSender receiptSender, ILogger logger, IDirectoryChecker directoryChecker)
        {
            try
            {
                directoryChecker?.CheckDirectories();
            }
            catch (Exception ex)
            {
                _logger.Log($"{ex.GetType()}:\n{ex.Message}");
                Console.WriteLine($"{ex.GetType()}:\n{ex.Message}");
                throw ex;
            }
            _fileProcessor    = fileProcessor ?? throw new ArgumentNullException(nameof(fileProcessor));
            _config           = loader.Load();
            _watcher          = new FileSystemWatcher(_config.InputFolder);
            _watcher.Created += OnCreatedFile;
            _receiptSender    = receiptSender ?? throw new ArgumentNullException(nameof(receiptSender));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));

            //System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
        }
コード例 #2
0
        private ServiceConfig InitConfig()
        {
            ServiceConfig config;

            try
            {
                config = new ServiceConfig
                {
                    ServiceDescription        = ConfigurationManager.AppSettings.Get("ServiceDescription"),
                    ServiceDisplayName        = ConfigurationManager.AppSettings.Get("ServiceDisplayName"),
                    ServiceName               = ConfigurationManager.AppSettings.Get("ServiceName"),
                    InputFolder               = ConfigurationManager.AppSettings.Get("InputFolder"),
                    CompleteFolder            = ConfigurationManager.AppSettings.Get("CompleteFolder"),
                    GarbageFolder             = ConfigurationManager.AppSettings.Get("GarbageFolder"),
                    FileExtension             = ConfigurationManager.AppSettings.Get("FileExtension"),
                    AttempsToAccessFilesystem = Int32.Parse(ConfigurationManager.AppSettings.Get("AttempsToAccessFilesystem")),
                    DelayForAnotherAttempt    = Int32.Parse(ConfigurationManager.AppSettings.Get("DelayForAnotherAttempt")),
                    LogFileFullName           = ConfigurationManager.AppSettings.Get("LogFileFullName")
                };
            }
            catch (Exception ex) //default
            {
                Console.WriteLine($"Error in {nameof(InitConfig)}:\n{ex.GetType()}:\n{ex.Message}");
                config = new ServiceConfig
                {
                    ServiceDescription        = "_FolderMonitor - test task.",
                    ServiceDisplayName        = "_FolderMonitor",
                    ServiceName               = "_FolderMonitor",
                    InputFolder               = "Input",
                    CompleteFolder            = "Complete",
                    GarbageFolder             = "Garbage",
                    FileExtension             = ".txt",
                    AttempsToAccessFilesystem = 5,
                    DelayForAnotherAttempt    = 20,
                    LogFileFullName           = @"d:\Programs\CS_progs\___TestTasks\Manzana\winservicelog.txt"
                };
            }
            return(config);
        }
コード例 #3
0
 public ConfigLoader()
 {
     _config = InitConfig();
 }