Пример #1
0
        public FolderWatcher WatchFolder(FolderRegistration folder, FolderEventHandler handler,
                                         FolderEventHandler changedHandler = null,
                                         FolderEventHandler removedHandler = null)
        {
            if (!DebugOptions.GetOption(null, DebugOptions.WATCHER_ENABLED))
            {
                return(null);
            }

            FolderWatcher watcher;

            if (!_folderWatchers.TryGetValue(folder, out watcher))
            {
                watcher = new FolderWatcher();
                _folderWatchers.TryAdd(folder, watcher);
            }

            watcher.Discovered += handler;
            if (changedHandler != null)
            {
                watcher.Changed += changedHandler;
            }
            if (removedHandler != null)
            {
                watcher.Removed += removedHandler;
            }

            // Check existing folders for events
            foreach (ZPushFolder existing in _allFolders)
            {
                if (folder.IsApplicable(existing.Folder))
                {
                    DispatchFolderEvent(folder, watcher, existing, EventKind.Discovered);
                }
            }

            return(watcher);
        }
Пример #2
0
 private void DispatchFolderEvent(FolderRegistration reg, FolderWatcher watcher, ZPushFolder folder, EventKind kind)
 {
     Logger.Instance.Debug(this, "Folder event: {0}, {1}, {2}", folder, reg, kind);
     watcher.Dispatch(folder, kind);
 }