コード例 #1
0
        private void FolderWatcher_Created(object sender, FileSystemEventArgs e)
        {
            //  Console.WriteLine("Creating: "+e.Name);

            if (e.ChangeType == WatcherChangeTypes.Deleted)
            {
                Console.WriteLine("deleted");
                return;
            }

            var path = e.FullPath;
            var watchType = WatcherType.FileCreate;
            if (IsDir(path) && !IsInSubFolder(path))
            {//creating folder
                watchType = WatcherType.FolderCreate;
                subFolders.Add(path);

                var subfw =
                    new FolderCompleteWatcher(new WatcherItem() { FullPath = path, WatcherType = watchType }, 5000);// if the folder created, and 5 seconds passed the folder size not changed then the folder create completed.
                subfw.FolderCompleted += Subfw_FolderCompleted;
                subfw.Start();
                subfolderWatcher.Add(subfw);
            }
            if (IsInSubFolder(path))
            {// in creating folder 'file, do not care.

            }
            else if (IsSubFolderFile(path))
            {//if current file in exist subfolder ,do not care

            }
            else
            {
                //single file  creating
                var fileWatchFype = WatcherType.FileCreate;
                // isReplace ? WatcherType.FileReplace : WatcherType.FileCreate;
                //Console.WriteLine(fileWatcher);
                if (!files.Contains(path))
                {
                    files.Add(path);

                    //  Console.WriteLine("changed file :" + path);
                    var fw = new FileCompleteWatcher(new WatcherItem() { FullPath = path, WatcherType = fileWatchFype });
                    fw.FileCompleted += Fw_FileCompleted;
                    fw.Start();
                    fileWatcher.Add(fw);
                }
            }

            // OnFolderCreated(new FolderFileEventArgs() {FullPath = path});

        }
コード例 #2
0
        private void FolderWatcher_Changed(object sender, FileSystemEventArgs e)
        {
          //   Console.WriteLine("changing:{0}",e.FullPath);
            var path = e.FullPath;
            // var isReplace = File.Exists(path);


            if (IsDir(path) && !IsInSubFolder(path))
            {
                //ignore this issue, do not care.
                // if folder copy 
                // Console.WriteLine("copying folder :" + path);

                //subFolders.Add(path);

                //var subfw =
                //    new FolderCompleteWatcher(new WatcherItem() { FullPath = path, WatcherType = WatcherType.FolderCopy });
                //subfw.FolderCompleted += Subfw_FolderCompleted;
                //subfw.Start();
                //subfolderWatcher.Add(subfw);
            }
            else if (IsInSubFolder(path))
            {// in copying folder 'file, do not care.

            }
            else if (IsSubFolderFile(path))
            {// if is file,and in existing subdir,then current is subfolder replacing
                var subDirItem = GetSubFolderItem(path);

                //  Console.WriteLine("replacing folder :" + subDirItem);

                subFolders.Add(subDirItem);

                var subfw =
                    new FolderCompleteWatcher(new WatcherItem() { FullPath = subDirItem, WatcherType = WatcherType.FolderReplace });
                subfw.FolderCompleted += Subfw_FolderCompleted;
                subfw.Start();
                subfolderWatcher.Add(subfw);
            }
            else
            {// single file copy

                var fileWatchFype = WatcherType.FileReplace;// isReplace ? WatcherType.FileReplace : WatcherType.FileCreate;
                //Console.WriteLine(fileWatcher);
                if (!files.Contains(path))
                {
                    files.Add(path);

                    //  Console.WriteLine("changed file :" + path);
                    var fw = new FileCompleteWatcher(new WatcherItem() { FullPath = path, WatcherType = fileWatchFype });
                    fw.FileCompleted += Fw_FileCompleted;
                    fw.Start();
                    fileWatcher.Add(fw);
                }
            }
        }