Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
 void LongRunningOperation()
 {
     Windows.Clr.FileWatcher myWatcher = new Windows.Clr.FileWatcher("C:\\Work\\RTextNpp\\TestFiles",
                                                                     (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.Renamed += myWatcher_Renamed;
     myWatcher.Changed += myWatcher_Changed;
     myWatcher.Deleted += myWatcher_Deleted;
     Assert.True(myWatcher.IsWatching());
     while (true)
     {
         Thread.Sleep(100000);
     }
 }
Exemplo n.º 5
0
 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..");
     }
 }
Exemplo n.º 6
0
        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..");
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
        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();
        }