创建文件夹触发两次

时间:2016-04-22 12:17:37

标签: c# asp.net wpf mvvm

当我从桌面创建新文件夹时,我的应用程序双向同步应用程序创建一个名为“新文件夹”的额外文件夹

private void FileSystemWatcherCreated(object sender,FileSystemEventArgs e)         {             尝试             {                 var parentDirectory = Directory.GetParent(e.FullPath).FullName;

                if (!this.IsWatchedObject(e.FullPath))
                {
                    return;
                }

                if (!this.IsFileOrDirectoryExists(e.FullPath))
                {
                    if (!string.IsNullOrWhiteSpace(e.FullPath))
                    {
                        this.Debug("FileSystemWatcherCreated", "Delete '{0}' from the icon overlay system...", e.FullPath);
                        var success = CloudFuzeIconOverlayAssystent.DeleteFileFolderRecord(e.FullPath, true, this.LogService);
                        this.Debug("FileSystemWatcherCreated", success.BooleanToSuccessFailLogString());
                        this.SendFileSystemItemChangedRecursively(e.FullPath);
                    }

                    return;
                }
                else
                {
                    if (Directory.Exists(e.FullPath))
                    { //http://stackoverflow.com/questions/16301598/filesystemwatcher-files-in-subdirectory
                        foreach (string file in Directory.GetFiles(e.FullPath))
                        {
                            var eventArgs = new FileSystemEventArgs(
                                WatcherChangeTypes.Created,
                                Path.GetDirectoryName(file),
                                Path.GetFileName(file));
                            FileSystemWatcherCreated(sender, eventArgs);
                        }
                    }
                }

                if (this.IsFileFolderAddedToRootFolder(this.cloudFuzeDirectory, e.FullPath))
                {
                    return;
                }

                if (this.cloudFuzeDirectory == parentDirectory)
                {
                    return;
                }

                var type = Directory.Exists(e.FullPath) ? WellKnownFileFoderTypes.Folder : WellKnownFileFoderTypes.File;

                this.Debug("FileSystemWatcherCreated", "Add '{0}' in the queue for registration in the local storage...", e.FullPath);
                this.addedFileFolders.Enqueue(new FileFolder
                {
                    SavedFilePath = e.FullPath,
                    FileType = type,
                    Type = type
                });


        }
        catch (Exception exc)
        {
            this.Error("FileSystemWatcherCreated", exc);
        }
    }

0 个答案:

没有答案