Пример #1
0
            private void GetCopyDirectoryOperations(DirectoryInfo curSrcDir, DirectoryInfo curDstDir)
            {
                try
                {
                    foreach (var srcFsi in curSrcDir.EnumerateFileSystemInfos())
                    {
                        if (srcFsi is FileInfo srcFile)
                        {
                            var dstFile = new FileInfo(Path.Combine(curDstDir.FullName, srcFsi.Name));
                            _detector.OnOperationFound(new CopyFileOperation(srcFile, dstFile));
                        }
                        else if (srcFsi is DirectoryInfo srcDir)
                        {
                            var dstDir = new DirectoryInfo(Path.Combine(curDstDir.FullName, srcFsi.Name));

                            _detector.OnOperationFound(new CreateDirectoryOperation(dstDir));

                            if (ContainsSpecialDirectoryAttributes(srcDir.Attributes))
                            {
                                _detector.OnOperationFound(new EditAttributesOperation(dstDir, srcDir.Attributes));
                            }

                            _stack.Add(srcDir);
                            _stack.Add(dstDir);
                        }
                    }
                }
                catch (Exception ex) when(ex is IOException ||
                                          ex is UnauthorizedAccessException ||
                                          ex is SecurityException)
                {
                    _detector.OnError(new FileSystemInfoException(curSrcDir, ex));
                }
            }
Пример #2
0
 private void GetDeleteDirectoryOperations(DirectoryInfo curDir)
 {
     try
     {
         foreach (var fsi in curDir.EnumerateFileSystemInfos())
         {
             if (fsi is FileInfo file)
             {
                 _operationsStack.Add(new DeleteFileOperation(file));
             }
             else if (fsi is DirectoryInfo dir)
             {
                 _stack.Add(dir);
                 _operationsStack.Add(new DestroyDirectoryOperation(dir));
             }
         }
     }
     catch (Exception ex) when(ex is IOException ||
                               ex is UnauthorizedAccessException ||
                               ex is SecurityException)
     {
         _detector.OnError(new FileSystemInfoException(curDir, ex));
     }
 }