public void EnsureNonExistantDirIsNotWatched() { Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher(@"", (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.atm", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); Assert.IsFalse(myWatcher.IsWatching()); myWatcher.Dispose(); }
public void EnsureExistantDirIsWatched() { string aBinDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher(aBinDir, (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.atm", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); Assert.IsTrue(myWatcher.IsWatching()); myWatcher.Dispose(); }
public void EnduranceTestCreationDeletion() { for (uint j = 0; j < 5; ++j) { try { Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher(System.IO.Path.GetDirectoryName(_testFile), (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.txt", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); bool notificationFired = false; int count = 0; EventHandler <System.IO.FileSystemEventArgs> handler = (s, e) => { notificationFired = true; ++count; }; myWatcher.Changed += handler; for (uint i = 0; i < 10; ++i) { //modify file using (var aFile = System.IO.File.OpenWrite(_testFile)) { var aBytesToWrite = GetBytes("Some extra stuff"); aFile.Write(aBytesToWrite, 0, aBytesToWrite.Length); } System.Threading.Thread.Sleep(1000); } Assert.True(notificationFired); Assert.AreEqual(count, 10); myWatcher.Changed -= handler; myWatcher.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public void SmokeTest() { try { var myWatcher = new Windows.Clr.FileWatcher(@"C:\FooDirectoryLALALALALALALAWLWWLWLWL", (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.atm", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); myWatcher.Dispose(); } catch { Console.WriteLine("Exception.."); } }
public void FileModificationTest() { Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher(System.IO.Path.GetDirectoryName(_testFile), (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.txt", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); myWatcher.Renamed += myWatcher_Renamed; try { bool notificationFired = false; int count = 0; EventHandler <System.IO.FileSystemEventArgs> handler = (s, e) => { notificationFired = true; ++count; Console.WriteLine(String.Format("Full path : {0}, name : {1}, change : {2}", e.FullPath, e.Name, e.ChangeType)); }; myWatcher.Changed += handler; //modify file using (var aFile = System.IO.File.OpenWrite(_testFile)) { var aBytesToWrite = GetBytes("Some extra stuff"); aFile.Write(aBytesToWrite, 0, aBytesToWrite.Length); } System.Threading.Thread.Sleep(1000); Assert.True(notificationFired); Assert.AreEqual(count, 1); myWatcher.Changed -= handler; myWatcher.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void EnduranceTestCreationDeletion() { for (uint j = 0; j < 5; ++j) { try { Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher(System.IO.Path.GetDirectoryName(_testFile), (uint)(System.IO.NotifyFilters.FileName | System.IO.NotifyFilters.LastWrite | System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.Size | System.IO.NotifyFilters.LastAccess | System.IO.NotifyFilters.Attributes), true, @"*.txt", string.Empty, false, Windows.Clr.FileWatcherBase.STANDARD_BUFFER_SIZE); bool notificationFired = false; int count = 0; EventHandler<System.IO.FileSystemEventArgs> handler = (s, e) => { notificationFired = true; ++count; }; myWatcher.Changed += handler; for (uint i = 0; i < 10; ++i) { //modify file using (var aFile = System.IO.File.OpenWrite(_testFile)) { var aBytesToWrite = GetBytes("Some extra stuff"); aFile.Write(aBytesToWrite, 0, aBytesToWrite.Length); } System.Threading.Thread.Sleep(1000); } Assert.True(notificationFired); Assert.AreEqual(count, 10); myWatcher.Changed -= handler; myWatcher.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }