Esempio n. 1
0
        public void StartDispatching(FileSystemWatcher fsw)
        {
            FAMData famdata;

            lock (this)
            {
                if (FAMWatcher.thread == null)
                {
                    FAMWatcher.thread = new Thread(new ThreadStart(this.Monitor));
                    FAMWatcher.thread.IsBackground = true;
                    FAMWatcher.thread.Start();
                }
                famdata = (FAMData)FAMWatcher.watches[fsw];
            }
            if (famdata == null)
            {
                famdata                = new FAMData();
                famdata.FSW            = fsw;
                famdata.Directory      = fsw.FullPath;
                famdata.FileMask       = fsw.MangledFilter;
                famdata.IncludeSubdirs = fsw.IncludeSubdirectories;
                if (famdata.IncludeSubdirs)
                {
                    famdata.SubDirs = new Hashtable();
                }
                famdata.Enabled = true;
                FAMWatcher.StartMonitoringDirectory(famdata, false);
                lock (this)
                {
                    FAMWatcher.watches[fsw] = famdata;
                    FAMWatcher.requests[famdata.Request.ReqNum] = famdata;
                    FAMWatcher.stop = false;
                }
            }
        }
Esempio n. 2
0
        private static void StartMonitoringDirectory(FAMData data, bool justcreated)
        {
            FAMRequest request;

            if (FAMWatcher.FAMMonitorDirectory(ref FAMWatcher.conn, data.Directory, out request, IntPtr.Zero) == -1)
            {
                throw new System.ComponentModel.Win32Exception();
            }
            FileSystemWatcher fsw = data.FSW;

            data.Request = request;
            if (data.IncludeSubdirs)
            {
                foreach (string text in Directory.GetDirectories(data.Directory))
                {
                    FAMData famdata = new FAMData();
                    famdata.FSW            = data.FSW;
                    famdata.Directory      = text;
                    famdata.FileMask       = data.FSW.MangledFilter;
                    famdata.IncludeSubdirs = true;
                    famdata.SubDirs        = new Hashtable();
                    famdata.Enabled        = true;
                    if (justcreated)
                    {
                        FileSystemWatcher obj = fsw;
                        lock (obj)
                        {
                            RenamedEventArgs renamedEventArgs = null;
                            fsw.DispatchEvents(FileAction.Added, text, ref renamedEventArgs);
                            if (fsw.Waiting)
                            {
                                fsw.Waiting = false;
                                System.Threading.Monitor.PulseAll(fsw);
                            }
                        }
                    }
                    FAMWatcher.StartMonitoringDirectory(famdata, justcreated);
                    data.SubDirs[text] = famdata;
                    FAMWatcher.requests[famdata.Request.ReqNum] = famdata;
                }
            }
            if (justcreated)
            {
                foreach (string filename in Directory.GetFiles(data.Directory))
                {
                    FileSystemWatcher obj2 = fsw;
                    lock (obj2)
                    {
                        RenamedEventArgs renamedEventArgs2 = null;
                        fsw.DispatchEvents(FileAction.Added, filename, ref renamedEventArgs2);
                        fsw.DispatchEvents(FileAction.Modified, filename, ref renamedEventArgs2);
                        if (fsw.Waiting)
                        {
                            fsw.Waiting = false;
                            System.Threading.Monitor.PulseAll(fsw);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void ProcessEvents()
        {
            ArrayList arrayList = null;

            lock (this)
            {
                string text;
                int    num;
                int    num2;
                while (FAMWatcher.InternalFAMNextEvent(ref FAMWatcher.conn, out text, out num, out num2) == 1)
                {
                    bool flag;
                    switch (num)
                    {
                    case 1:
                    case 2:
                    case 5:
                        flag = FAMWatcher.requests.ContainsKey(num2);
                        break;

                    case 3:
                    case 4:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        goto IL_75;

                    default:
                        goto IL_75;
                    }
IL_7D:
                    if (flag)
                    {
                        FAMData famdata = (FAMData)FAMWatcher.requests[num2];
                        if (famdata.Enabled)
                        {
                            FileSystemWatcher fsw              = famdata.FSW;
                            NotifyFilters     notifyFilter     = fsw.NotifyFilter;
                            RenamedEventArgs  renamedEventArgs = null;
                            FileAction        fileAction       = (FileAction)0;
                            if (num == 1 && (notifyFilter & (NotifyFilters.Attributes | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size)) != (NotifyFilters)0)
                            {
                                fileAction = FileAction.Modified;
                            }
                            else if (num == 2)
                            {
                                fileAction = FileAction.Removed;
                            }
                            else if (num == 5)
                            {
                                fileAction = FileAction.Added;
                            }
                            if (fileAction != (FileAction)0)
                            {
                                if (fsw.IncludeSubdirectories)
                                {
                                    string fullPath = fsw.FullPath;
                                    string text2    = famdata.Directory;
                                    if (text2 != fullPath)
                                    {
                                        int length = fullPath.Length;
                                        int num3   = 1;
                                        if (length > 1 && fullPath[length - 1] == Path.DirectorySeparatorChar)
                                        {
                                            num3 = 0;
                                        }
                                        string path = text2.Substring(fullPath.Length + num3);
                                        text2 = Path.Combine(text2, text);
                                        text  = Path.Combine(path, text);
                                    }
                                    else
                                    {
                                        text2 = Path.Combine(fullPath, text);
                                    }
                                    if (fileAction == FileAction.Added && Directory.Exists(text2))
                                    {
                                        if (arrayList == null)
                                        {
                                            arrayList = new ArrayList(4);
                                        }
                                        arrayList.Add(new FAMData
                                        {
                                            FSW            = fsw,
                                            Directory      = text2,
                                            FileMask       = fsw.MangledFilter,
                                            IncludeSubdirs = true,
                                            SubDirs        = new Hashtable(),
                                            Enabled        = true
                                        });
                                        arrayList.Add(famdata);
                                    }
                                }
                                if (!(text != famdata.Directory) || fsw.Pattern.IsMatch(text))
                                {
                                    FileSystemWatcher obj = fsw;
                                    lock (obj)
                                    {
                                        fsw.DispatchEvents(fileAction, text, ref renamedEventArgs);
                                        if (fsw.Waiting)
                                        {
                                            fsw.Waiting = false;
                                            System.Threading.Monitor.PulseAll(fsw);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (FAMWatcher.FAMPending(ref FAMWatcher.conn) <= 0)
                    {
                        goto IL_28F;
                    }
                    continue;
IL_75:
                    flag = false;
                    goto IL_7D;
                }
                return;
            }
IL_28F:
            if (arrayList != null)
            {
                int count = arrayList.Count;
                for (int i = 0; i < count; i += 2)
                {
                    FAMData famdata2 = (FAMData)arrayList[i];
                    FAMData famdata3 = (FAMData)arrayList[i + 1];
                    FAMWatcher.StartMonitoringDirectory(famdata2, true);
                    FAMWatcher.requests[famdata2.Request.ReqNum] = famdata2;
                    FAMData obj2 = famdata3;
                    lock (obj2)
                    {
                        famdata3.SubDirs[famdata2.Directory] = famdata2;
                    }
                }
                arrayList.Clear();
            }
        }