Ejemplo n.º 1
0
        private void SwitchOnWatching(string[] validFileNames)
        {
            _triggerBasedUpdate = new Main.TriggerBasedUpdate(Current.TimerQueue)
            {
                MinimumWaitingTimeAfterUpdate       = TimeSpanExtensions.FromSecondsAccurate(_importOptions.MinimumWaitingTimeAfterUpdateInSeconds),
                MaximumWaitingTimeAfterUpdate       = TimeSpanExtensions.FromSecondsAccurate(Math.Max(_importOptions.MinimumWaitingTimeAfterUpdateInSeconds, _importOptions.MaximumWaitingTimeAfterUpdateInSeconds)),
                MinimumWaitingTimeAfterFirstTrigger = TimeSpanExtensions.FromSecondsAccurate(_importOptions.MinimumWaitingTimeAfterFirstTriggerInSeconds),
                MinimumWaitingTimeAfterLastTrigger  = TimeSpanExtensions.FromSecondsAccurate(_importOptions.MinimumWaitingTimeAfterLastTriggerInSeconds),
                MaximumWaitingTimeAfterFirstTrigger = TimeSpanExtensions.FromSecondsAccurate(Math.Max(_importOptions.MaximumWaitingTimeAfterFirstTriggerInSeconds, _importOptions.MinimumWaitingTimeAfterFirstTriggerInSeconds))
            };

            _triggerBasedUpdate.UpdateAction += EhUpdateByTimerQueue;

            var directories = new HashSet <string>(validFileNames.Select(x => System.IO.Path.GetDirectoryName(x)));
            var watchers    = new List <System.IO.FileSystemWatcher>();

            foreach (var directory in directories)
            {
                try
                {
                    var watcher = new System.IO.FileSystemWatcher(directory)
                    {
                        NotifyFilter = System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.Size
                    };
                    watcher.Changed += EhTriggerByFileSystemWatcher;
                    watcher.IncludeSubdirectories = false;
                    watcher.EnableRaisingEvents   = true;
                    watchers.Add(watcher);
                }
                catch (Exception)
                {
                }
            }
            _fileSystemWatchers = watchers.ToArray();
        }
Ejemplo n.º 2
0
 private void SwitchOnWatching()
 {
     _triggerBasedUpdate = new Main.TriggerBasedUpdate(Current.TimerQueue)
     {
         MinimumWaitingTimeAfterUpdate = TimeSpanExtensions.FromSecondsAccurate(_importOptions.MinimumWaitingTimeAfterUpdateInSeconds),
         MaximumWaitingTimeAfterUpdate = TimeSpanExtensions.FromSecondsAccurate(Math.Max(_importOptions.MinimumWaitingTimeAfterUpdateInSeconds, _importOptions.MaximumWaitingTimeAfterUpdateInSeconds))
     };
     _triggerBasedUpdate.UpdateAction += EhUpdateByTimerQueue;
 }