protected void CopyItemInternal(string path, string destination, bool recurse, bool deleteOriginal = false, bool exactDest = false) { var sourceDrive = PathResolver.FindDrive(path); var targetDrive = PathResolver.FindDrive(destination); if (sourceDrive is AzureTableServiceDriveInfo && targetDrive is AzureTableServiceDriveInfo) { var sd = sourceDrive as AzureTableServiceDriveInfo; var td = targetDrive as AzureTableServiceDriveInfo; sd.CopyTo(PathResolver.GetSubpath(path), td, PathResolver.GetSubpath(destination), deleteOriginal); return; } if (sourceDrive.IsItemContainer(PathResolver.GetSubpath(path))) { if (!recurse) { throw new Exception(path + " is a container"); } if (targetDrive.IsItemContainer(PathResolver.GetSubpath(destination)) && !exactDest) { destination = MakePath(destination, PathResolver.SplitPath(path).Last()); } targetDrive.NewItem(PathResolver.GetSubpath(destination), "Directory", null); foreach (var c in sourceDrive.GetChildNamesList(PathResolver.GetSubpath(path), PathType.Item)) { CopySingleItem(MakePath(path, c), MakePath(destination, c), exactDest: true); } foreach (var c in sourceDrive.GetChildNamesList(PathResolver.GetSubpath(path), PathType.Container)) { CopyItemInternal(MakePath(path, c), MakePath(destination, c), recurse, deleteOriginal, exactDest: true); } } else { CopySingleItem(path, destination); } }
protected void CopySingleItem(string path, string destination, bool exactDest = false) { var sourceDrive = PathResolver.FindDrive(path); var targetDrive = PathResolver.FindDrive(destination); var sourcePath = PathResolver.GetSubpath(path); string targetDir, targetFile; if (targetDrive.IsItemContainer(PathResolver.GetSubpath(destination)) && !exactDest) { targetDir = PathResolver.GetSubpath(destination); targetFile = PathResolver.SplitPath(path).Last(); } else { targetDir = PathResolver.GetSubpathDirectory(destination); targetFile = PathResolver.SplitPath(destination).Last(); } using (var sourceStream = sourceDrive.CopyFrom(sourcePath)) using (var targetStream = targetDrive.CopyTo(targetDir, targetFile)) { sourceStream.Seek(0, SeekOrigin.Begin); sourceStream.CopyTo(targetStream); } }