public async Task <FileSystemResult> MoveAsync(IDirectory destination) { if (Parent == null) { return(new FileSystemResult("Unable to move root directory")); } if (!(destination is GoogleDriveDirectory)) { return(new FileSystemResult("Destination should be a Google Drive Directory")); } GoogleDriveDirectory dest = (GoogleDriveDirectory)destination; if (dest.Id == ((GoogleDriveDirectory)Parent).Id) { return(new FileSystemResult("Source Directory and Destination Directory should be different")); } string addParents = dest.Id; string removeParents = ((GoogleDriveDirectory)Parent).Id; string url = GooglePatch.FormatRest(Id); url += "?addParents=" + addParents + "&removeParents=" + removeParents; FileSystemResult <string> ex = await FS.OAuth.CreateMetadataStream <string>(url, null, null, new HttpMethod("PATCH")); if (ex.IsOk) { string oldFullname = this.FullName; this.SetData(ex.Result); ChangeObjectDirectory <GoogleDriveDirectory, GoogleDriveFile>(oldFullname, FS.Refs, this, (GoogleDriveDirectory)Parent, dest); return(new FileSystemResult()); } return(new FileSystemResult <IDirectory>(ex.Error)); }
public async Task <FileSystemResult> CopyAsync(IDirectory destination) { if (Parent == null) { return(new FileSystemResult("Unable to copy root directory")); } if (!(destination is GoogleDriveDirectory)) { return(new FileSystemResult("Destination should be a Google Drive Directory")); } GoogleDriveDirectory dest = (GoogleDriveDirectory)destination; if (dest.Id == ((GoogleDriveDirectory)Parent).Id) { return(new FileSystemResult("Source Directory and Destination Directory should be different")); } string addParents = dest.Id; string url = GooglePatch.FormatRest(Id); url += "?addParents=" + addParents; FileSystemResult <string> ex = await FS.OAuth.CreateMetadataStream <string>(url, null, null, new HttpMethod("PATCH")); if (ex.IsOk) { if (this is GoogleDriveFile) { GoogleDriveFile f = new GoogleDriveFile(destination.FullName, this.FS); f.SetData(this.Metadata, this.MetadataExpanded, this.MetadataMime); f.Parent = destination; dest.Files.Add(f); } else if (this is GoogleDriveDirectory) { GoogleDriveDirectory d = new GoogleDriveDirectory(destination.FullName, this.FS); d.SetData(this.Metadata, this.MetadataExpanded, this.MetadataMime); d.Parent = destination; dest.Directories.Add(d); FS.Refs[d.FullName] = d; } return(new FileSystemResult()); } return(new FileSystemResult <IDirectory>(ex.Error)); }