Example #1
0
        /// <summary>Contructor.</summary>
        /// <param name="path">File path to monitor</param>
        /// <param name="ttl">Cache time-to-live</param>
        /// <param name="items">Items to watch</param>
        public FileSystemCache(string path, double ttl, List <FileSystemEntry> items)
        {
            CheckAndAddPath(path);

            this.ttl     = ttl;
            this.path    = path;
            watchedItems = items;
            try
            {
                watcher = WatcherFactory.CreateWatcher(path, new WatcherDelegates()
                {
                    ChangedHandler = OnFileChange,
                    CreatedHandler = OnFileCreated,
                    DeletedHandler = OnFileDeleted,
                    RenamedHandler = OnFileRenamed
                });
                watcher.EnableRaisingEvents = true;
                CreateTimer();
                timer.Start();
                creationTime = DateTime.UtcNow;
            }
            catch (Exception e)
            {
                lock (_lock)
                {
                    watchedPaths.Remove(path);
                }
                timer.Stop();
                throw e;
            }
        }
Example #2
0
        /// <summary>Constuctor.</summary>
        /// <param name="path">File path to monitor</param>
        /// <param name="ttl">Cache time-to-live</param>
        public FileSystemCache(string path, double ttl)
        {
            CheckAndAddPath(path);

            Partial      = true;
            this.ttl     = ttl;
            this.path    = path;
            watchedItems = new List <FileSystemEntry>(10);

            try
            {
                watcher = WatcherFactory.CreateWatcher(path, new WatcherDelegates()
                {
                    ChangedHandler = OnFileChange,
                    CreatedHandler = OnFileCreated,
                    DeletedHandler = OnFileDeleted,
                    RenamedHandler = OnFileRenamed
                });
                watcher.EnableRaisingEvents = true;
            }
            catch (Exception e) // catching exception because we are re-throwing it
            {
                lock (_lock)
                {
                    watchedPaths.Remove(path);
                }
                throw e;
            }

            CreateTimer();
            timer.Start();
            creationTime = DateTime.UtcNow;
        }
Example #3
0
        public IFbWatcher <TModel> CreateWatcher <TModel>()
            where TModel : IModel, new()
        {
            var factory        = new WatcherFactory <TModel>();
            var watcherOptions = new WatcherOptions(TestsContext.MainDbConnectionString,
                                                    TestsContext.TempDbConnectionString);

            return(factory.CreateWatcher(watcherOptions));
        }
Example #4
0
        private TaskInfo CreateTaskInfo(string filter, GatheringPointsInfo gInfo, WatcherType type = WatcherType.NONE)
        {
            try
            {
                var taskInfo = new TaskInfo();

                if (gInfo != null && ConfigInfo != null)
                {
                    taskInfo.Filter = filter;
                    taskInfo.Index  = gInfo.NO;
                }

                taskInfo.Watcher        = WatcherFactory.CreateWatcher(gInfo, ConfigInfo, FtpInfo, SetFilter(filter), type);
                taskInfo.ProcessingTask = new Task(StartProcessing, taskInfo, TaskCreationOptions.LongRunning);

                return(taskInfo);
            }
            catch (Exception ex)
            {
                AppEvents.Instance.OnUpdateScreen("Error : " + ex.Message);
                return(null);
            }
        }
Example #5
0
 public WatcherBL()
 {
     IWatcher = WatcherFactory.CreateWatcher();
 }