コード例 #1
0
 private void Monitor()
 {
     while (!FAMWatcher.stop)
     {
         int num;
         lock (this)
         {
             num = FAMWatcher.FAMPending(ref FAMWatcher.conn);
         }
         if (num > 0)
         {
             this.ProcessEvents();
         }
         else
         {
             Thread.Sleep(500);
         }
     }
     lock (this)
     {
         FAMWatcher.thread = null;
         FAMWatcher.stop   = false;
     }
 }
コード例 #2
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();
            }
        }