Пример #1
0
        public void WatchFile(string path)
        {
            if (!path.ToLower().Contains(":\\progra"))
            {
                return;
            }
            var dir = Path.GetDirectoryName(path);

            if (!Path.IsPathRooted(dir))
            {
                dir = Path.GetFullPath(dir);
            }

            if (!Directory.Exists(dir))
            {
                Logging.Error("ignored watch on missing folder {0}", dir);
                return;
            }

            DirectoryWatcher w;

            if (!dwatchers.TryGetValue(dir, out w))
            {
                if (!FileExists(path))
                {
                    Logging.Error("ignored watch on missing file {0}", path);
                    return;
                }

                Logging.Emit("create new watcher for {0}", dir);
                w = new DirectoryWatcher(dir);
                dwatchers.Add(dir, w);
                w.FileChanged += OnWatchedFileChanged;
                w.Enable();
            }
            var file = Path.GetFileName(path);

            w.Watch(file);
        }