/// <inheritdoc /> public async Task <IDocument> CopyToAsync(ICollection collection, string name, CancellationToken cancellationToken) { var dir = (DotNetDirectory)collection; var targetFileName = System.IO.Path.Combine(dir.DirectoryInfo.FullName, name); File.Copy(FileInfo.FullName, targetFileName, true); var fileInfo = new FileInfo(targetFileName); var doc = new DotNetFile(dir.DotNetFileSystem, dir, fileInfo, dir.Path.Append(fileInfo.Name, false)); var sourcePropStore = FileSystem.PropertyStore; var destPropStore = collection.FileSystem.PropertyStore; if (sourcePropStore != null && destPropStore != null) { var sourceProps = await sourcePropStore.GetAsync(this, cancellationToken).ConfigureAwait(false); await destPropStore.RemoveAsync(doc, cancellationToken).ConfigureAwait(false); await destPropStore.SetAsync(doc, sourceProps, cancellationToken).ConfigureAwait(false); } else if (destPropStore != null) { await destPropStore.RemoveAsync(doc, cancellationToken).ConfigureAwait(false); } return(doc); }
/// <inheritdoc /> public async Task <IDocument> MoveToAsync(ICollection collection, string name, CancellationToken cancellationToken) { var sourcePropStore = FileSystem.PropertyStore; var destPropStore = collection.FileSystem.PropertyStore; IReadOnlyCollection <XElement> sourceProps; if (sourcePropStore != null && destPropStore != null) { sourceProps = await sourcePropStore.GetAsync(this, cancellationToken).ConfigureAwait(false); } else { sourceProps = null; } var dir = (DotNetDirectory)collection; var targetFileName = System.IO.Path.Combine(dir.DirectoryInfo.FullName, name); if (File.Exists(targetFileName)) { File.Delete(targetFileName); } File.Move(FileInfo.FullName, targetFileName); var fileInfo = new FileInfo(targetFileName); var doc = new DotNetFile(dir.DotNetFileSystem, dir, fileInfo, dir.Path.Append(fileInfo.Name, false)); if (destPropStore != null) { await destPropStore.RemoveAsync(doc, cancellationToken).ConfigureAwait(false); if (sourceProps != null) { await destPropStore.SetAsync(doc, sourceProps, cancellationToken).ConfigureAwait(false); } } return(doc); }