Inheritance: IFileWatcher
Exemple #1
0
        // Locked by caller
        public static bool GetInstance(out IFileWatcher watcher)
        {
            if (failed == true)
            {
                watcher = null;
                return(false);
            }

            if (instance != null)
            {
                watcher = instance;
                return(true);
            }

            watches = Hashtable.Synchronized(new Hashtable());
            var conn = kqueue();

            if (conn == -1)
            {
                failed  = true;
                watcher = null;
                return(false);
            }
            close(conn);

            instance = new KeventWatcher();
            watcher  = instance;
            return(true);
        }
Exemple #2
0
 public static bool GetInstance(out IFileWatcher watcher)
 {
     if (KeventWatcher.failed)
     {
         watcher = null;
         return(false);
     }
     if (KeventWatcher.instance != null)
     {
         watcher = KeventWatcher.instance;
         return(true);
     }
     KeventWatcher.watches  = Hashtable.Synchronized(new Hashtable());
     KeventWatcher.requests = Hashtable.Synchronized(new Hashtable());
     KeventWatcher.conn     = KeventWatcher.kqueue();
     if (KeventWatcher.conn == -1)
     {
         KeventWatcher.failed = true;
         watcher = null;
         return(false);
     }
     KeventWatcher.instance = new KeventWatcher();
     watcher = KeventWatcher.instance;
     return(true);
 }
Exemple #3
0
        public void StartDispatching(FileSystemWatcher fsw)
        {
            KeventData keventData;

            lock (this)
            {
                if (KeventWatcher.thread == null)
                {
                    KeventWatcher.thread = new Thread(new ThreadStart(this.Monitor));
                    KeventWatcher.thread.IsBackground = true;
                    KeventWatcher.thread.Start();
                }
                keventData = (KeventData)KeventWatcher.watches[fsw];
            }
            if (keventData == null)
            {
                keventData                = new KeventData();
                keventData.FSW            = fsw;
                keventData.Directory      = fsw.FullPath;
                keventData.FileMask       = fsw.MangledFilter;
                keventData.IncludeSubdirs = fsw.IncludeSubdirectories;
                keventData.Enabled        = true;
                lock (this)
                {
                    KeventWatcher.StartMonitoringDirectory(keventData);
                    KeventWatcher.watches[fsw] = keventData;
                    KeventWatcher.stop         = false;
                }
            }
        }
Exemple #4
0
        private void PostEvent(string filename, FileSystemWatcher fsw, FileAction fa, FileSystemInfo changedFsi)
        {
            RenamedEventArgs renamedEventArgs = null;

            if (fa == (FileAction)0)
            {
                return;
            }
            if (fsw.IncludeSubdirectories && fa == FileAction.Added && changedFsi is DirectoryInfo)
            {
                KeventData keventData = new KeventData();
                keventData.FSW            = fsw;
                keventData.Directory      = changedFsi.FullName;
                keventData.FileMask       = fsw.MangledFilter;
                keventData.IncludeSubdirs = fsw.IncludeSubdirectories;
                keventData.Enabled        = true;
                lock (this)
                {
                    KeventWatcher.StartMonitoringDirectory(keventData);
                }
            }
            if (!fsw.Pattern.IsMatch(filename, true))
            {
                return;
            }
            lock (fsw)
            {
                fsw.DispatchEvents(fa, filename, ref renamedEventArgs);
                if (fsw.Waiting)
                {
                    fsw.Waiting = false;
                    System.Threading.Monitor.PulseAll(fsw);
                }
            }
        }
Exemple #5
0
 private void Monitor()
 {
     while (!KeventWatcher.stop)
     {
         kevent ev = default(kevent);
         ev.udata = IntPtr.Zero;
         kevent kevent = default(kevent);
         kevent.udata = IntPtr.Zero;
         timespec timespec = default(timespec);
         timespec.tv_sec  = 0;
         timespec.tv_usec = 0;
         int num;
         lock (this)
         {
             num = KeventWatcher.kevent(KeventWatcher.conn, ref kevent, 0, ref ev, 1, ref timespec);
         }
         if (num > 0)
         {
             KeventData data = (KeventData)KeventWatcher.requests[ev.ident];
             KeventWatcher.StopMonitoringDirectory(data);
             KeventWatcher.StartMonitoringDirectory(data);
             this.ProcessEvent(ev);
         }
         else
         {
             Thread.Sleep(500);
         }
     }
     lock (this)
     {
         KeventWatcher.thread = null;
         KeventWatcher.stop   = false;
     }
 }
        void InitWatcher()
        {
            lock (lockobj)
            {
                if (watcher != null)
                {
                    return;
                }

                string managed = Environment.GetEnvironmentVariable("MONO_MANAGED_WATCHER");
                int    mode    = 0;
                if (managed == null)
                {
                    mode = InternalSupportsFSW();
                }

                bool ok = false;
                switch (mode)
                {
                case 1: // windows
                    ok = DefaultWatcher.GetInstance(out watcher);
                    //ok = WindowsWatcher.GetInstance (out watcher);
                    break;

                case 2: // libfam
                    ok = FAMWatcher.GetInstance(out watcher, false);
                    break;

                case 3: // kevent
                    ok = KeventWatcher.GetInstance(out watcher);
                    break;

                case 4: // libgamin
                    ok = FAMWatcher.GetInstance(out watcher, true);
                    break;

                case 5: // inotify
                    ok = InotifyWatcher.GetInstance(out watcher, true);
                    break;
                }

                if (mode == 0 || !ok)
                {
                    if (String.Compare(managed, "disabled", true) == 0)
                    {
                        NullFileWatcher.GetInstance(out watcher);
                    }
                    else
                    {
                        DefaultWatcher.GetInstance(out watcher);
                    }
                }

                ShowWatcherInfo();
            }
        }
Exemple #7
0
        private void InitWatcher()
        {
            object obj = FileSystemWatcher.lockobj;

            lock (obj)
            {
                if (FileSystemWatcher.watcher == null)
                {
                    string environmentVariable = Environment.GetEnvironmentVariable("MONO_MANAGED_WATCHER");
                    int    num = 0;
                    if (environmentVariable == null)
                    {
                        num = FileSystemWatcher.InternalSupportsFSW();
                    }
                    bool flag = false;
                    switch (num)
                    {
                    case 1:
                        flag = DefaultWatcher.GetInstance(out FileSystemWatcher.watcher);
                        break;

                    case 2:
                        flag = FAMWatcher.GetInstance(out FileSystemWatcher.watcher, false);
                        break;

                    case 3:
                        flag = KeventWatcher.GetInstance(out FileSystemWatcher.watcher);
                        break;

                    case 4:
                        flag = FAMWatcher.GetInstance(out FileSystemWatcher.watcher, true);
                        break;

                    case 5:
                        flag = InotifyWatcher.GetInstance(out FileSystemWatcher.watcher, true);
                        break;
                    }
                    if (num == 0 || !flag)
                    {
                        if (string.Compare(environmentVariable, "disabled", true) == 0)
                        {
                            NullFileWatcher.GetInstance(out FileSystemWatcher.watcher);
                        }
                        else
                        {
                            DefaultWatcher.GetInstance(out FileSystemWatcher.watcher);
                        }
                    }
                }
            }
        }
Exemple #8
0
 public void StopDispatching(FileSystemWatcher fsw)
 {
     lock (this)
     {
         KeventData keventData = (KeventData)KeventWatcher.watches[fsw];
         if (keventData != null)
         {
             KeventWatcher.StopMonitoringDirectory(keventData);
             KeventWatcher.watches.Remove(fsw);
             if (KeventWatcher.watches.Count == 0)
             {
                 KeventWatcher.stop = true;
             }
             if (!keventData.IncludeSubdirs)
             {
             }
         }
     }
 }
Exemple #9
0
        private static void StartMonitoringDirectory(KeventData data)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(data.Directory);

            if (data.DirEntries == null)
            {
                data.DirEntries = new Hashtable();
                foreach (FileSystemInfo fileSystemInfo in directoryInfo.GetFileSystemInfos())
                {
                    data.DirEntries.Add(fileSystemInfo.FullName, new KeventFileData(fileSystemInfo, fileSystemInfo.LastAccessTime, fileSystemInfo.LastWriteTime));
                }
            }
            int    num = KeventWatcher.open(data.Directory, 0, 0);
            kevent ev  = default(kevent);

            ev.udata = IntPtr.Zero;
            timespec timespec = default(timespec);

            timespec.tv_sec  = 0;
            timespec.tv_usec = 0;
            if (num > 0)
            {
                ev.ident  = num;
                ev.filter = -4;
                ev.flags  = 21;
                ev.fflags = 31u;
                ev.data   = 0;
                ev.udata  = Marshal.StringToHGlobalAuto(data.Directory);
                kevent kevent = default(kevent);
                kevent.udata = IntPtr.Zero;
                KeventWatcher.kevent(KeventWatcher.conn, ref ev, 1, ref kevent, 0, ref timespec);
                data.ev = ev;
                KeventWatcher.requests[num] = data;
            }
            if (!data.IncludeSubdirs)
            {
                return;
            }
        }
Exemple #10
0
		// Locked by caller
		public static bool GetInstance (out IFileWatcher watcher)
		{
			if (failed == true) {
				watcher = null;
				return false;
			}

			if (instance != null) {
				watcher = instance;
				return true;
			}

			watches = Hashtable.Synchronized (new Hashtable ());
			requests = Hashtable.Synchronized (new Hashtable ());
			conn = kqueue();
			if (conn == -1) {
				failed = true;
				watcher = null;
				return false;
			}

			instance = new KeventWatcher ();
			watcher = instance;
			return true;
		}
Exemple #11
0
        void InitWatcher()
        {
            lock (lockobj) {
                if (watcher_handle != null)
                {
                    return;
                }

                string managed = Environment.GetEnvironmentVariable("MONO_MANAGED_WATCHER");
                int    mode    = 0;
                if (managed == null)
                {
                    mode = InternalSupportsFSW();
                }

                bool ok = false;
                switch (mode)
                {
                case 1:                 // windows
                    ok             = DefaultWatcher.GetInstance(out watcher);
                    watcher_handle = this;
                    break;

                case 2:                 // libfam
                    ok             = FAMWatcher.GetInstance(out watcher, false);
                    watcher_handle = this;
                    break;

                case 3:                 // kevent
                    ok             = KeventWatcher.GetInstance(out watcher);
                    watcher_handle = this;
                    break;

                case 4:                 // libgamin
                    ok             = FAMWatcher.GetInstance(out watcher, true);
                    watcher_handle = this;
                    break;

                case 6:                 // CoreFX
                    ok             = CoreFXFileSystemWatcherProxy.GetInstance(out watcher);
                    watcher_handle = (watcher as CoreFXFileSystemWatcherProxy).NewWatcher(this);
                    break;
                }

                if (mode == 0 || !ok)
                {
                    if (String.Compare(managed, "disabled", true) == 0)
                    {
                        NullFileWatcher.GetInstance(out watcher);
                    }
                    else
                    {
                        DefaultWatcher.GetInstance(out watcher);
                        watcher_handle = this;
                    }
                }
                this.inited = true;

                ShowWatcherInfo();
            }
        }
Exemple #12
0
 private static void StopMonitoringDirectory(KeventData data)
 {
     KeventWatcher.close(data.ev.ident);
 }