Ejemplo n.º 1
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initialise new FileChangeWatcher that will watch the given files.
        /// </summary>
        /// <param name="fileNames">
        /// names of files to watch. Each file will be watched only the once, no
        /// matter how many times it might be mentioned.</param>
        public FileChangeWatcher(ICollection <string> fileNames)
        {
            var dirWatchersByDirName = new Dictionary <string, DirWatcher>();

            _dirWatchers = new List <DirWatcher>();

            foreach (string fileName in fileNames)
            {
                var dir  = Misc.GetPathDirectoryName(fileName);
                var name = Misc.GetPathFileName(fileName);

                if (dir == null || name == null)
                {
                    continue;
                }

                DirWatcher dirWatcher;

                if (!dirWatchersByDirName.TryGetValue(dir, out dirWatcher))
                {
                    dirWatcher = new DirWatcher(this, dir);

                    dirWatchersByDirName.Add(dir, dirWatcher);
                    _dirWatchers.Add(dirWatcher);
                }

                dirWatcher.AddFileName(name);
            }

            foreach (DirWatcher dirWatcher in _dirWatchers)
            {
                dirWatcher.BeginWatching();
            }
        }