public Task<LiveOperationResult> UploadAsync(string path, IFileSource fileSource, OverwriteOption option, IBackgroundTransferProvider btu, CancellationToken ct, IProgress<LiveOperationProgress> progress) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == fileSource) { throw new ArgumentNullException( "fileSource", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullParameter"), "fileSource")); } if (null != fileSource && string.IsNullOrEmpty(fileSource.Filename)) { throw new ArgumentException( "fileName", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullOrEmptyParameter"), "fileName")); } if (null == btu) { btu = new Microsoft.Live.Transfers.BasicTransferProvider(); } ApiOperation op = btu.GetUploadOperation(this, this.GetResourceUri(path, ApiMethod.Upload), fileSource, option, progress, syncContext); return this.ExecuteApiOperation(op, ct); }
/// <summary> /// Downloads the contents of a file represented by this OneDriveItem. /// </summary> /// <param name="btp"></param> /// <param name="progress"></param> /// <returns></returns> public async Task <System.IO.Stream> DownloadContentsAsync(IBackgroundTransferProvider btp = null, IProgress <LiveOperationProgress> progress = null) { if (this.ItemType != OneDriveItemType.GenericFile) { throw new InvalidOperationException("Cannot download items that are not files"); } LiveDownloadOperationResult result = await Client.LiveClient.DownloadAsync(string.Format("/{0}/content", this.Identifier), btp, progress); return(result.Stream); }
public Task <LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu, CancellationToken ct, IProgress <LiveOperationProgress> progress) { if (path == null) { throw new ArgumentNullException("path"); } if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == btu) { btu = new Microsoft.Live.Transfers.BasicTransferProvider(); } return(this.InternalDownloadAsync(path, null, btu, ct, progress)); }
public Task<LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu, CancellationToken ct, IProgress<LiveOperationProgress> progress) { if (path == null) { throw new ArgumentNullException("path"); } if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == btu) { btu = new Microsoft.Live.Transfers.BasicTransferProvider(); } return this.InternalDownloadAsync(path, null, btu, ct, progress); }
public Task<LiveDownloadOperationResult> DownloadAsync(string path, IFileSource destination, IBackgroundTransferProvider btu = null, IProgress<LiveOperationProgress> progress = null) { if (path == null) { throw new ArgumentNullException("path"); } if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == destination) { throw new ArgumentNullException("destination", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullParameter"), "destination")); } return this.InternalDownloadAsync(path, destination, btu, new CancellationToken(false), progress); }
internal Task <LiveDownloadOperationResult> InternalDownloadAsync(string path, IFileSource destination, IBackgroundTransferProvider btu, CancellationToken ct, IProgress <LiveOperationProgress> progress) { if (this.Session == null) { throw new LiveConnectException(ApiOperation.ApiClientErrorCode, ResourceHelper.GetString("UserNotLoggedIn")); } var tcs = new TaskCompletionSource <LiveDownloadOperationResult>(); var op = btu.GetDownloadOperation(this, this.GetResourceUri(path, ApiMethod.Download), destination, progress, syncContext); op.OperationCompletedCallback = (LiveDownloadOperationResult result) => { if (result.IsCancelled) { tcs.TrySetCanceled(); } else if (result.Error != null) { tcs.TrySetException(result.Error); } else { tcs.TrySetResult(result); } }; ct.Register(op.Cancel); op.Execute(); return(tcs.Task); }
public Task <LiveDownloadOperationResult> DownloadAsync(string path, IFileSource destination, IBackgroundTransferProvider btu = null, IProgress <LiveOperationProgress> progress = null) { if (path == null) { throw new ArgumentNullException("path"); } if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == destination) { throw new ArgumentNullException("destination", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullParameter"), "destination")); } return(this.InternalDownloadAsync(path, destination, btu, new CancellationToken(false), progress)); }
public Task <LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu = null, IProgress <LiveOperationProgress> progress = null) { return(this.DownloadAsync(path, btu, new CancellationToken(false), progress)); }
public Task <LiveOperationResult> UploadAsync(string path, IFileSource fileSource, OverwriteOption option, IBackgroundTransferProvider btu, CancellationToken ct, IProgress <LiveOperationProgress> progress) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException( "path", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), "path")); } if (null == fileSource) { throw new ArgumentNullException( "fileSource", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullParameter"), "fileSource")); } if (null != fileSource && string.IsNullOrEmpty(fileSource.Filename)) { throw new ArgumentException( "fileName", String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("InvalidNullOrEmptyParameter"), "fileName")); } if (null == btu) { btu = new Microsoft.Live.Transfers.BasicTransferProvider(); } ApiOperation op = btu.GetUploadOperation(this, this.GetResourceUri(path, ApiMethod.Upload), fileSource, option, progress, syncContext); return(this.ExecuteApiOperation(op, ct)); }
public Task <LiveOperationResult> UploadAsync(string path, IFileSource fileSource, OverwriteOption option, IBackgroundTransferProvider btu = null, IProgress <LiveOperationProgress> progress = null) { return(this.UploadAsync(path, fileSource, option, btu, new CancellationToken(false), progress)); }
/// <summary> /// Downloads the contents of a file represented by this OneDriveItem. /// </summary> /// <param name="btp"></param> /// <param name="progress"></param> /// <returns></returns> public async Task<System.IO.Stream> DownloadContentsAsync(IBackgroundTransferProvider btp = null, IProgress<LiveOperationProgress> progress = null) { if (this.ItemType != OneDriveItemType.GenericFile) { throw new InvalidOperationException("Cannot download items that are not files"); } LiveDownloadOperationResult result = await Client.LiveClient.DownloadAsync(string.Format("/{0}/content", this.Identifier), btp, progress); return result.Stream; }
/// <summary> /// Uploads a file into the OneDriveItem this command is called on. This command is only available on OneDriveItem instances that represents /// a folder or album. /// </summary> /// <param name="sourceItem"></param> /// <param name="option"></param> /// <param name="btp"></param> /// <param name="progress"></param> /// <returns></returns> public async Task<OneDriveItem> UploadFileAsync(IFileSource sourceItem, OverwriteOption option, IBackgroundTransferProvider btp = null, IProgress<LiveOperationProgress> progress = null) { if (this.ItemType != OneDriveItemType.Folder && this.ItemType != OneDriveItemType.Album) { throw new InvalidOperationException("Cannot upload files to items that do not represent a folder or album"); } LiveOperationResult result = await Client.LiveClient.UploadAsync( string.Format("/{0}", this.Identifier), sourceItem, option, btp, progress); System.Diagnostics.Debug.WriteLine("UploadFile Result: {0}", result.RawResult); FileUploadResult fur = FileUploadResult.FromJson(result.RawResult); return await this.Client.GetItemFromIdentifier(fur.Identifier); }
/// <summary> /// Uploads a file into the OneDriveItem this command is called on. This command is only available on OneDriveItem instances that represents /// a folder or album. /// </summary> /// <param name="sourceItem"></param> /// <param name="option"></param> /// <param name="btp"></param> /// <param name="progress"></param> /// <returns></returns> public async Task <OneDriveItem> UploadFileAsync(IFileSource sourceItem, OverwriteOption option, IBackgroundTransferProvider btp = null, IProgress <LiveOperationProgress> progress = null) { if (this.ItemType != OneDriveItemType.Folder && this.ItemType != OneDriveItemType.Album) { throw new InvalidOperationException("Cannot upload files to items that do not represent a folder or album"); } LiveOperationResult result = await Client.LiveClient.UploadAsync( string.Format("/{0}", this.Identifier), sourceItem, option, btp, progress); System.Diagnostics.Debug.WriteLine("UploadFile Result: {0}", result.RawResult); FileUploadResult fur = FileUploadResult.FromJson(result.RawResult); return(await this.Client.GetItemFromIdentifier(fur.Identifier)); }
public Task<LiveOperationResult> UploadAsync(string path, IFileSource fileSource, OverwriteOption option, IBackgroundTransferProvider btu = null, IProgress<LiveOperationProgress> progress = null) { return this.UploadAsync(path, fileSource, option, btu, new CancellationToken(false), progress); }
public Task<LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu = null, IProgress<LiveOperationProgress> progress = null) { return this.DownloadAsync(path, btu, new CancellationToken(false), progress); }
internal Task<LiveDownloadOperationResult> InternalDownloadAsync(string path, IFileSource destination, IBackgroundTransferProvider btu, CancellationToken ct, IProgress<LiveOperationProgress> progress) { if (this.Session == null) { throw new LiveConnectException(ApiOperation.ApiClientErrorCode, ResourceHelper.GetString("UserNotLoggedIn")); } var tcs = new TaskCompletionSource<LiveDownloadOperationResult>(); var op = btu.GetDownloadOperation(this, this.GetResourceUri(path, ApiMethod.Download), destination, progress, syncContext); op.OperationCompletedCallback = (LiveDownloadOperationResult result) => { if (result.IsCancelled) { tcs.TrySetCanceled(); } else if (result.Error != null) { tcs.TrySetException(result.Error); } else { tcs.TrySetResult(result); } }; ct.Register(op.Cancel); op.Execute(); return tcs.Task; }