Esempio n. 1
0
 public myFileSystemWatcher(FileSystemWatcher w, FolderAndCommand fold)
 {
     this.watcher   = w;
     this.fold      = fold;
     timer          = new System.Timers.Timer();
     timerHandler   = new System.Timers.ElapsedEventHandler(OnTimedEvent);
     timer.Elapsed += timerHandler;
 }
Esempio n. 2
0
        public bool AddItem(string folderName, string commandName)
        {
            var item = new FolderAndCommand(folderName, commandName);

            if (_itemList.Contains(item))
            {
                return(false);
            }

            _itemList.Add(item);

            return(true);
        }
Esempio n. 3
0
        public void LoadItems()
        {
            try
            {
                this._itemList = FolderAndCommand.LoadItems(this._itemListPath);
            } catch (Exception e)
            {
                this._logger.WriteToFile(e.Message);
                return;
            }

            this.myWatch.ForEach(i =>
            {
                i.Dispose();
            });
            this.myWatch.Clear();

            this._itemList.ForEach(i =>
            {
                this.CreateFileWatcher(i);
            });
        }
Esempio n. 4
0
        private void CreateFileWatcher(FolderAndCommand foldComm)
        {
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();

            this._logger.WriteToFile($"Watch At: {foldComm.folderName} ");
            this._logger.WriteToFile($"Execute: {foldComm.commandPath} ");
            watcher.Path = System.IO.Path.GetDirectoryName(foldComm.folderName);

            /* Watch for changes in LastAccess and LastWrite times, and
             * the renaming of files or directories. */
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            // Only watch text files.

            var filterExt = "*" + Path.GetExtension(foldComm.folderName);

            //var filterExt = "*.xls";
            watcher.Filter = filterExt;



            //watcher.Changed += new FileSystemEventHandler(this.OnChanged);
            //watcher.Created += new FileSystemEventHandler(this.OnChanged);
            //watcher.Deleted += new FileSystemEventHandler(this.OnChanged);
            //watcher.Renamed += new RenamedEventHandler(OnRenamed);

            // Begin watching.
            watcher.EnableRaisingEvents = true;


            var m  = new myFileSystemWatcher(watcher, foldComm);
            var ev = new FileSystemEventHandler((sender, e) => RunCommandEvent(sender, e, m, foldComm));

            m.setEvent(ev);


            this.myWatch.Add(m);
        }
Esempio n. 5
0
        //If app already doing something, then add item to queue, else, add it to queue, execute and lau
        public void RunCommandEvent(object sender, EventArgs e, myFileSystemWatcher watcher, FolderAndCommand comm)
        {
            //if task already exist in queue - return
            this._logger.WriteToFile($"Try to add event in execution queue - {comm.folderName}");
            if (this.executionQueue.Contains(comm))
            {
                return;
            }

            //if not - add to queu
            this._logger.WriteToFile($"Add to excution queue new Item - {comm.folderName}");
            this.executionQueue.Add(comm);
            watcher.PospondeToAvoidUnreasonableEventsCalls();
            //if queue already executer - return
            if (!isReadyForNewTaskExecute)
            {
                return;
            }
            //start queu execution.
            this._logger.WriteToFile($"Run task -  {comm.folderName}");
            RunNextTaskFromQueue();
        }
Esempio n. 6
0
 private void ExecuteCommand(FolderAndCommand command)
 {
     this._logger.WriteToFile($" ExecuteCommand: {command.commandPath} ");
     this.RunScript(command.commandPath);
 }
Esempio n. 7
0
 public void SaveItems(string path)
 {
     FolderAndCommand.SaveItems(path, this._itemList);
 }
Esempio n. 8
0
 public void RemoveItem(FolderAndCommand item)
 {
     this._itemList.Remove(item);
 }