예제 #1
0
        /// <summary>
        /// Создает экземпляры <see cref="FileSystemWatcher"/> для указаных папок
        /// </summary>
        /// <param name="folderPaths">Список путей к папкам для прослушивания</param>
        /// <param name="handlers">Список обработчиков</param>
        private void CreateWatchers(ListenedFolderPathElementCollection folderPaths, List <FileSystemEventHandler> handlers)
        {
            if (folderPaths != null)
            {
                foreach (ListenedFolderPathElement folderPath in folderPaths)
                {
                    try
                    {
                        FileSystemWatcher watcher = new FileSystemWatcher(folderPath.FolderPath);

                        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

                        //определяем обработчики события создания файла
                        if (handlers != null)
                        {
                            foreach (var item in handlers)
                            {
                                watcher.Created += item;
                            }
                        }

                        watcher.EnableRaisingEvents = true;

                        watchers.Add(watcher);
                    }
                    catch (ArgumentException e)
                    {
                        loger.PrintError(e.Message);
                    }
                }
            }
        }
예제 #2
0
 private static void CreateDirectory(ListenedFolderPathElementCollection folders)
 {
     foreach (ListenedFolderPathElement folder in folders)
     {
         if (!Directory.Exists(folder.FolderPath))
         {
             Directory.CreateDirectory(folder.FolderPath);
         }
     }
 }
예제 #3
0
        private static void Initialize()
        {
            var configFile    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var configuration = (CustomConfigurationSection)configFile.Sections["customSection"];

            CultureInfo culture = new CultureInfo(configuration.Culture.Culture);


            CultureInfo.DefaultThreadCurrentCulture   = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;

            CreateDirectory(configuration.Paths);

            listenedFolders = configuration.Paths;
        }
예제 #4
0
 public MyWatcher(ListenedFolderPathElementCollection folderPaths, List <FileSystemEventHandler> handlers, ILoger loger)
 {
     this.loger = loger;
     CreateWatchers(folderPaths, handlers);
 }