public void GetNotifiedOnModificationOfWatchedFile() { MakeSureTestFileIsDeleted(); CreateTestFile(); var fileWatcher = new FileWatcher(); bool isUpdated = false; fileWatcher.Updated += () => isUpdated = true; fileWatcher.SetFile(FilePath); ModifyTestFileAndWait(); Assert.IsTrue(isUpdated); }
public MainWindow() { InitializeComponent(); WindowWatcher.AddWindow(this); FileWatcher watcher = new FileWatcher("C:\\"); Start(); updateFlag = true; timerFlag = false; timer.Interval = TimeSpan.FromMinutes(30); timer.Tick += timer_Tick; timer.Start(); }
public void CreateFile() { string tempDir = Path.GetTempPath(); fileName = Path.Combine(tempDir, "temp.txt"); tempFileName = Path.Combine(tempDir, "newTempFile.txt"); StreamWriter writer = new StreamWriter(fileName); writer.Write("Hello"); writer.Close(); handler = new CounterEventHandler(); watcher = new FileWatcher(fileName, watcherDelayMs); watcher.Changed += new FileChangedHandler(handler.OnChanged); watcher.Start(); }
/// <summary> /// When file events have finished it means we should should remove them from the cache /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnFileActivityFinishedEvent(object sender, FileWatcher.FileActivityFinishedEventArgs e) { var outputUri = (Uri)e.UserState; if (e.FileEventItems.Any(x => x.FileEventType != FileEventType.InDirectory)) { RemoveGroup(outputUri); } }
public void Add(string filePath) { FileWatcher fw = new FileWatcher(new FileInfo( filePath )); fw.Watcher.Path = fw.Info.DirectoryName; fw.Watcher.Filter = fw.Info.Name; fw.Watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite; fw.Watcher.Changed+=new FileSystemEventHandler(OnChanged); fw.Watcher.EnableRaisingEvents = false; this.fileWatchers.Add(fw); }
/// <summary> /// Set things in motion so your service can do its work. /// </summary> protected override void OnStart(string[] args) { try { // for debug use System.Threading.Thread.Sleep(10000); // 10 seconds //Start logging log4net.Config.XmlConfigurator.Configure(); // go get the work records TransferMainService transferMainService = new TransferMainService(); TList<TransferMain> transferMainList = transferMainService.GetAll(); foreach (TransferMain transferMain in transferMainList) { if (transferMain.Active) { switch ((TransferTypeList)transferMain.TransferTypeId) { case TransferTypeList.FileWatchAndProcess: case TransferTypeList.FileWatchFtpPut: case TransferTypeList.FileWatchFtpPutGet: if (transferMain.WatchDir != null) { //TODO: Implement InterfaceProcessType ProcessType = (InterfaceProcessType)transferMain.InterfaceProcessTypeID; // Account for any files or unfinished work in the watchdirs when the service starts. DirectoryInfo di = new DirectoryInfo(transferMain.WatchDir); FileInfo[] files = di.GetFiles(transferMain.FileMask); FileWatcher fw = new FileWatcher(transferMain.WatchDir, 0, transferMain.TransferRefId); // tell the watcher there are previous files if (files.Length > 0) { fw.PreviousFilesExist = true; } FileWatchChange fwc = new FileWatchChange(); fw.Filter = transferMain.FileMask; watcherThread = new System.Threading.Thread(new System.Threading.ThreadStart(fw.StartWatcher)); fw.Changed += new FileWatcher.ChangedEventHandler(fwc.OnFileWatchChange); watcherThread.Name = "StartWatcher " + transferMain.Name; watcherThread.Start(); watcherThreads.Add(watcherThread); LogManager.GetLogger("SiteLogger").Debug("Created Watcher Thread for " + transferMain.WatchDir + "\\" + transferMain.FileMask); //logger.logEntry(this.ServiceName, "Created Watcher Thread for " + transferMain.WatchDir + "\\" + transferMain.FileMask, LogMsgSeverity.Trace, false); } else { LogManager.GetLogger("SiteLogger").Warn(transferMain.Name + " Watch dir is empty, can't start transfer process."); } break; case TransferTypeList.FtpGetPut: case TransferTypeList.FtpGet: // create new instance of Scheduler class if (transferMain.ScheduleRefId.HasValue) { ftpGetSchedulerList.Add(new TransferScheduler(transferMain.FileMask, transferMain.TransferRefId)); } else { LogManager.GetLogger("SiteLogger").Warn(transferMain.Name + " Schedule is empty, can't start transfer process."); //logger.logEntry(this.ServiceName, transferMain.Name + " Schedule is empty, can't start transfer process.", LogMsgSeverity.Warning, false); } break; } } } } catch (System.Exception ex) { LogManager.GetLogger("SiteLogger").Fatal("OnStart Error: ",ex); //logger.logEntry("OnStart Error: " + ex.Message, this.ServiceName, LogMsgSeverity.Critical, false); } }
public PipelineController(IView view) { _actionStack = new ActionStack(); Selection = new Selection(); View = view; View.Attach(this); ProjectOpen = false; _watcher = new FileWatcher(this, view); _templateItems = new List<ContentItemTemplate>(); LoadTemplates(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Templates")); }
/// <summary> /// Adds file watcher and subscribes to events. /// </summary> /// <param name="fileWatcher">File watcher to add.</param> private void AddFileWatcherToController(FileWatcher fileWatcher) { fileWatcher.SystemChanged += new EventHandler<FileWatcherEventArgs>(OnSystemChanged); fileWatcher.BufferError += new EventHandler<FileWatcherBufferErrorEventArgs>(OnBufferError); fileWatcher.FileWatcherStarted += new EventHandler<FileWatcherStartedEventArgs>(OnFileWatcherStarted); fileWatcher.FileWatcherStarting += new EventHandler<FileWatcherStartingEventArgs>(OnFileWatcherStarting); fileWatcher.FileWatcherStopped += new EventHandler<FileWatcherStoppedEventArgs>(OnFileWatcherStopped); fileWatcher.FileWatcherSearchError += new EventHandler<FileWatcherSearchErrorEventArgs>(OnFileWatcherSearchError); fileWatcher.FileWatcherSearchProgress += new EventHandler<FileWatcherSearchProgressEventArgs>(OnFileWatcherSearchProgress); fileWatcher.FileWatcherRecycle += new EventHandler<FileWatcherRecycledEventArgs>(OnFileWatcherRecycle); _fileWatchers.Add(fileWatcher.DaemonName, fileWatcher); }