Example #1
0
        /// <summary>
        /// 初始化FileWatcher类
        /// </summary>
        /// <param name="path">监控路径</param>
        /// <param name="pending"></param>
        /// <param name="filter"></param>
        public FileWatcher(string path, Picture.Pending pending, string filter = "")
        {
            _path    = path;
            _filter  = filter;
            _pending = pending;

            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            if (string.IsNullOrEmpty(_filter))
            {
                _watcher = new FileSystemWatcher(_path);
            }
            else
            {
                _watcher = new FileSystemWatcher(_path, _filter);
            }
            //注册监听事件
            _watcher.Created += new FileSystemEventHandler(OnProcess);
            _watcher.IncludeSubdirectories = true; //是否监视子目录
            _watcher.EnableRaisingEvents   = true; //是否启用组件
            _isWatch = true;
        }
Example #2
0
        static void Main(string[] args)
        {
            SetConsoleCtrlHandler(cancelHandler, true);

            loadConfig();
            DataBase.Load(databaseFile);

            if (monitorFile)//是否监视文件夹
            {
                Picture.Pending pending = new Picture.Pending(OnChange);
                FileWatcher     fw      = new FileWatcher(srcPath, pending);//监视文件夹
            }



            //ImportFile(srcPath);

            //while (Console.Read() != 'q')
            while (true)
            {
                string[] cmd = Console.ReadLine().Split(' ');
                switch (cmd[0].ToLower())
                {
                case "hash":
                    DataBase.List();
                    break;

                case "import":
                    ImportFile(cmd[1]);
                    break;

                default:
                    Console.WriteLine("hash");
                    Console.WriteLine("import");
                    break;
                }
            }
            ;
        }