コード例 #1
0
        public void Monitoring()
        {
            PopulatingWatchingList();
            _threadList = new List <BaseWatcher>();

            Console.WriteLine("starting watchers.......");
            foreach (BaseWatchingObject watchingObject in _watchingList)
            {
                string      watchType   = watchingObject.GetWatchType();
                BaseWatcher baseWatcher = MonitoringAux(watchType, watchingObject);

                _threadList.Add(baseWatcher);
            }

            foreach (BaseWatcher watcher in _threadList)
            {
                watcher.Start();
            }
            Console.WriteLine("Press \'q\' to quite the program");
            while (Console.Read() != 'q')
            {
                ;
            }
            foreach (BaseWatcher watcher in _threadList)
            {
                watcher.Finish();
            }
        }
コード例 #2
0
        private BaseWatcher MonitoringAux(string watchType, BaseWatchingObject watchingObject)
        {
            BaseWatcher baseWatcher = null;

            switch (watchType)
            {
            case "file":
                WatchingFileObject watchingFileObject = (WatchingFileObject)watchingObject;
                string             path     = watchingFileObject.GetPath();
                string             fileName = watchingFileObject.GetFileName();
                baseWatcher = new FileWatcher(watchingFileObject.GetWatchId(), path, "*." + watchingFileObject.GetFileType(), fileName, new FileInfo(path + "\\" + fileName).Length);

                if (fileName.Equals("watcher.config"))
                {
                    ((FileWatcher)baseWatcher).ConfigFileUpdated += MainConfigFileUpdated;
                }

                break;

            case "database":
                WatchingDatabaseObject watchingDataObject = (WatchingDatabaseObject)watchingObject;
                baseWatcher = new DatabaseWatcher(watchingDataObject.GetWatchId(), watchingDataObject.GetDataSource(), watchingDataObject.GetDatabaseName(), watchingDataObject.GetUserId());
                break;
            }

            return(baseWatcher);
        }
コード例 #3
0
        public void MainConfigFileUpdated(object sender, EventArgs e)
        {
            BaseWatchingObject watchingObejct = PopulatingWatchingListAux((XmlNode)sender);
            BaseWatcher        baseWatcher    = MonitoringAux(watchingObejct.GetWatchType(), watchingObejct);

            baseWatcher.Start();

            Object locker = new Object();

            lock (locker)
            {
                _threadList.Add(baseWatcher);
            }

            Console.WriteLine($"e type: {((FileSystemEventArgs)e).ChangeType}, Initiating one more watcher({watchingObejct.GetWatchType()})....");
        }