예제 #1
0
        static void OnRenamed(object source, RenamedEventArgs e)
        {
            // Show that a file has been renamed.
            WatcherChangeTypes wct = e.ChangeType;

            Console.WriteLine("Renamed {2} from {0} to {1}", e.OldFullPath, e.FullPath, (!Directory.Exists(e.FullPath)) ? "file" : "dir");
            ChangeObj change = new ChangeObj()
            {
                fileType = (!Directory.Exists(e.FullPath)) ? FileType.File : FileType.Dir, type = wct, path = e.OldFullPath, body = Encoding.ASCII.GetBytes(e.FullPath), bytes = e.FullPath.Length
            };

            sendQueue.Enqueue(change);
        }
예제 #2
0
        static void OnChanged(object source, FileSystemEventArgs e)
        {
            ChangeObj          change = null;
            WatcherChangeTypes wct    = e.ChangeType;

            byte[] b;
            Regex  regex = new Regex(@".*\.DS_Store");

            if (!regex.IsMatch(e.FullPath))
            {
                switch (wct)
                {
                case WatcherChangeTypes.Created:
                case WatcherChangeTypes.Deleted:
                    change = new ChangeObj()
                    {
                        fileType = (!Directory.Exists(e.FullPath)) ? FileType.File : FileType.Dir, type = wct, path = e.FullPath, body = new byte[1], bytes = 0
                    };
                    break;

                case WatcherChangeTypes.Changed:
                    if (File.Exists(e.FullPath))
                    {
                        b = new byte[ChangeObj.Size];
                        int count;
                        using (FileStream fs = File.OpenRead(e.FullPath))
                        {
                            UTF8Encoding temp = new UTF8Encoding(true);
                            count = fs.Read(b, 0, ChangeObj.Size);
                        }
                        change = new ChangeObj()
                        {
                            fileType = FileType.File, type = wct, path = e.FullPath, body = b, bytes = count
                        };
                    }
                    break;
                }
                Console.WriteLine("{0} {1} {2}", e.FullPath, (!Directory.Exists(e.FullPath)) ? "file" : "dir", wct.ToString());
                sendQueue.Enqueue(change);
            }
        }