public Task <string> GetHashAsync(DriveItem driveItem) { var _hashAlgorithm = new QuickXorHash(); using (var stream = File.OpenRead(driveItem.GetAbsolutePath(this.BasePath))) { return(Task.FromResult(Convert.ToBase64String(_hashAlgorithm.ComputeHash(stream)))); } }
public Task <DriveItem> ToFullDriveItem(DriveItem driveItem) { if (driveItem.Type() == DriveItemType.File) { var fileInfo = new FileInfo(driveItem.GetAbsolutePath(this.BasePath)); return(Task.FromResult(fileInfo.ToDriveItem(this.BasePath))); } else { throw new ArgumentException(); } }
public Task <DriveItem> DeleteAsync(DriveItem driveItem) { string fullPath = driveItem.GetAbsolutePath(this.BasePath); switch (driveItem.Type()) { case DriveItemType.Folder: Directory.Delete(fullPath, recursive: true); break; case DriveItemType.File: File.Delete(fullPath); break; case DriveItemType.RemoteItem: default: throw new NotSupportedException(); } return(Task.FromResult(driveItem)); }
public Task SetLastWriteTimeUtcAsync(DriveItem driveItem) { var driveItemPath = driveItem.GetAbsolutePath(this.BasePath); switch (driveItem.Type()) { case DriveItemType.Folder: Directory.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified()); break; case DriveItemType.File: File.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified()); break; case DriveItemType.RemoteItem: default: throw new NotSupportedException(); } return(Task.CompletedTask); }
public Task <bool> ExistsAsync(DriveItem driveItem) { bool result; string fullPath = driveItem.GetAbsolutePath(this.BasePath); switch (driveItem.Type()) { case DriveItemType.Folder: result = Directory.Exists(fullPath); break; case DriveItemType.File: result = File.Exists(fullPath); break; case DriveItemType.RemoteItem: default: throw new NotSupportedException(); } return(Task.FromResult(result)); }
public async Task <DriveItem> CreateOrUpdateAsync(DriveItem driveItem) { var fullPath = driveItem.GetAbsolutePath(this.BasePath); switch (driveItem.Type()) { case DriveItemType.Folder: Directory.CreateDirectory(fullPath); break; case DriveItemType.File: Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); if (driveItem.Content != null) { using (var stream = File.OpenWrite(fullPath)) { driveItem.Content.Seek(0, SeekOrigin.Begin); driveItem.Content.CopyTo(stream); } } else { await new WebClient().DownloadFileTaskAsync(driveItem.Uri(), fullPath); } File.SetLastWriteTimeUtc(fullPath, driveItem.FileSystemInfo.LastModifiedDateTime.Value.DateTime); break; case DriveItemType.RemoteItem: default: throw new NotSupportedException(); } return(driveItem); }
public Task <DriveItem> MoveAsync(DriveItem oldDriveItem, DriveItem newDriveItem) { var fullOldPath = oldDriveItem.GetAbsolutePath(this.BasePath); var fullNewPath = newDriveItem.GetAbsolutePath(this.BasePath); switch (newDriveItem.Type()) { case DriveItemType.Folder: Directory.Move(fullOldPath, fullNewPath); break; case DriveItemType.File: Directory.CreateDirectory(Path.GetDirectoryName(fullNewPath)); File.Move(fullOldPath, fullNewPath); break; case DriveItemType.RemoteItem: default: throw new NotSupportedException(); } return(Task.FromResult(newDriveItem)); }
public Task <DateTime> GetLastWriteTimeUtcAsync(DriveItem driveItem) { return(Task.FromResult(File.GetLastWriteTimeUtc(driveItem.GetAbsolutePath(this.BasePath)))); }
public Task <Uri> GetDownloadUriAsync(DriveItem driveItem) { return(Task.FromResult(new Uri(driveItem.GetAbsolutePath(this.BasePath)))); }