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();
            }
        }
		// Locked by caller
		public static bool GetInstance (out IFileWatcher watcher)
		{
			if (instance != null) {
				watcher = instance;
				return true;
			}

			instance = new DefaultWatcher ();
			watcher = instance;
			return true;
		}
Ejemplo n.º 3
0
 public static bool GetInstance(out IFileWatcher watcher)
 {
     if (DefaultWatcher.instance != null)
     {
         watcher = DefaultWatcher.instance;
         return(true);
     }
     DefaultWatcher.instance = new DefaultWatcher();
     watcher = DefaultWatcher.instance;
     return(true);
 }
Ejemplo n.º 4
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void DoFiles(DefaultWatcherData data, string directory, bool dispatch)
        {
            bool flag = Directory.Exists(directory);

            if (flag && data.IncludeSubdirs)
            {
                foreach (string directory2 in Directory.GetDirectories(directory))
                {
                    this.DoFiles(data, directory2, dispatch);
                }
            }
            string[] array = null;
            if (!flag)
            {
                array = DefaultWatcher.NoStringsArray;
            }
            else if (!data.NoWildcards)
            {
                array = Directory.GetFileSystemEntries(directory, data.FileMask);
            }
            else if (File.Exists(data.FileMask) || Directory.Exists(data.FileMask))
            {
                array = new string[]
                {
                    data.FileMask
                };
            }
            else
            {
                array = DefaultWatcher.NoStringsArray;
            }
            foreach (object obj in data.Files.Keys)
            {
                string   key      = (string)obj;
                FileData fileData = (FileData)data.Files[key];
                if (fileData.Directory == directory)
                {
                    fileData.NotExists = true;
                }
            }
            foreach (string text in array)
            {
                FileData fileData2 = (FileData)data.Files[text];
                if (fileData2 == null)
                {
                    try
                    {
                        data.Files.Add(text, DefaultWatcher.CreateFileData(directory, text));
                    }
                    catch
                    {
                        data.Files.Remove(text);
                        goto IL_1BD;
                    }
                    if (dispatch)
                    {
                        DefaultWatcher.DispatchEvents(data.FSW, FileAction.Added, text);
                    }
                }
                else if (fileData2.Directory == directory)
                {
                    fileData2.NotExists = false;
                }
                IL_1BD :;
            }
            if (!dispatch)
            {
                return;
            }
            ArrayList arrayList = null;

            foreach (object obj2 in data.Files.Keys)
            {
                string   text2     = (string)obj2;
                FileData fileData3 = (FileData)data.Files[text2];
                if (fileData3.NotExists)
                {
                    if (arrayList == null)
                    {
                        arrayList = new ArrayList();
                    }
                    arrayList.Add(text2);
                    DefaultWatcher.DispatchEvents(data.FSW, FileAction.Removed, text2);
                }
            }
            if (arrayList != null)
            {
                foreach (object obj3 in arrayList)
                {
                    string key2 = (string)obj3;
                    data.Files.Remove(key2);
                }
                arrayList = null;
            }
            foreach (object obj4 in data.Files.Keys)
            {
                string   text3     = (string)obj4;
                FileData fileData4 = (FileData)data.Files[text3];
                DateTime creationTime;
                DateTime lastWriteTime;
                try
                {
                    creationTime  = File.GetCreationTime(text3);
                    lastWriteTime = File.GetLastWriteTime(text3);
                }
                catch
                {
                    if (arrayList == null)
                    {
                        arrayList = new ArrayList();
                    }
                    arrayList.Add(text3);
                    DefaultWatcher.DispatchEvents(data.FSW, FileAction.Removed, text3);
                    continue;
                }
                if (creationTime != fileData4.CreationTime || lastWriteTime != fileData4.LastWriteTime)
                {
                    fileData4.CreationTime  = creationTime;
                    fileData4.LastWriteTime = lastWriteTime;
                    DefaultWatcher.DispatchEvents(data.FSW, FileAction.Modified, text3);
                }
            }
            if (arrayList != null)
            {
                foreach (object obj5 in arrayList)
                {
                    string key3 = (string)obj5;
                    data.Files.Remove(key3);
                }
            }
        }
Ejemplo n.º 6
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();
            }
        }