Example #1
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();
        }
Example #2
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);
        }