コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
 public Task <LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu = null, IProgress <LiveOperationProgress> progress = null)
 {
     return(this.DownloadAsync(path, btu, new CancellationToken(false), progress));
 }
コード例 #9
0
        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));
        }
コード例 #10
0
 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));
 }
コード例 #11
0
        /// <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;
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        /// <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));
        }
コード例 #14
0
 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);
 }
コード例 #15
0
 public Task<LiveDownloadOperationResult> DownloadAsync(string path, IBackgroundTransferProvider btu = null, IProgress<LiveOperationProgress> progress = null)
 {
     return this.DownloadAsync(path, btu, new CancellationToken(false), progress);
 }
コード例 #16
0
        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;
        }