コード例 #1
0
ファイル: DropboxService.cs プロジェクト: exactsync/ExactSync
 public async Task<byte[]> DownloadContentAsByteArray(DropboxClient client, DownloadArg arg)
 {
     using (var response = await client.Files.DownloadAsync(arg))
     {
         return await response.GetContentAsByteArrayAsync();
     }
 }
コード例 #2
0
        /// <summary>
        /// Asynchronously downloads the file.
        /// </summary>
        /// <returns></returns>
        protected override async Task <SerializableAPIResult <CloudStorageServiceAPIFile> > DownloadFileAsync()
        {
            SerializableAPIResult <CloudStorageServiceAPIFile> result = new SerializableAPIResult <CloudStorageServiceAPIFile>();

            try
            {
                InitializeCertPinning();
                DownloadArg arg = new DownloadArg($"/{SettingsFileNameWithoutExtension}");
                using (DropboxClient client = GetClient())
                {
                    Task <Stream> response = await client.Files.DownloadAsync(arg)
                                             .ContinueWith(async task => await task.Result.GetContentAsStreamAsync());

                    return(await GetMappedAPIFileAsync(result, response.Result));
                }
            }
            catch (ApiException <DownloadError> ex)
            {
                result.Error = new SerializableAPIError {
                    ErrorMessage = ex.Message
                };
            }
            catch (AuthException exc)
            {
                IsAuthenticated = false;
                result.Error    = new SerializableAPIError {
                    ErrorMessage = exc.Message
                };
            }
            catch (BadInputException exc)
            {
                IsAuthenticated = false;
                result.Error    = new SerializableAPIError {
                    ErrorMessage = exc.Message
                };
            }
            catch (Exception exc)
            {
                result.Error = new SerializableAPIError {
                    ErrorMessage = exc.Message
                };
            }
            finally
            {
                ClearCertPinning();
            }

            return(result);
        }
コード例 #3
0
        public IDropboxResult ExecuteTask(IDropboxClientWrapper client)
        {
            try
            {
                var downloadArg = new DownloadArg(_path);
                IDownloadResponse <FileMetadata> uploadAsync = client.DownloadAsync(downloadArg).Result;
                return(new DropboxDownloadSuccessResult(uploadAsync));
            }
            catch (Exception exception)
            {
                Dev2Logger.Error(exception.Message);

                var hasInnerExc = exception.InnerException != null;
                if (hasInnerExc)
                {
                    if (exception.InnerException.Message.Contains("not_found"))
                    {
                        return(new DropboxFailureResult(new DropboxFileNotFoundException()));
                    }
                    return(exception.InnerException.Message.Contains("not_file") ? new DropboxFailureResult(new DropboxPathNotFileFoundException()) : new DropboxFailureResult(exception.InnerException));
                }
                return(new DropboxFailureResult(exception));
            }
        }
コード例 #4
0
        /// <summary>
        /// <para>Begins an asynchronous send to the download route.</para>
        /// </summary>
        /// <param name="path">The path of the file to download.</param>
        /// <param name="rev">Deprecated. Please specify revision in :field:'path'
        /// instead</param>
        /// <param name="callback">The method to be called when the asynchronous send is
        /// completed.</param>
        /// <param name="callbackState">A user provided object that distinguished this send
        /// from other send requests.</param>
        /// <returns>An object that represents the asynchronous send request.</returns>
        public sys.IAsyncResult BeginDownload(string path,
                                              string rev = null,
                                              sys.AsyncCallback callback = null,
                                              object callbackState = null)
        {
            var downloadArg = new DownloadArg(path,
                                              rev);

            return this.BeginDownload(downloadArg, callback, callbackState);
        }
コード例 #5
0
        /// <summary>
        /// <para>Download a file from a user's Dropbox.</para>
        /// </summary>
        /// <param name="path">The path of the file to download.</param>
        /// <param name="rev">Deprecated. Please specify revision in :field:'path'
        /// instead</param>
        /// <returns>The task that represents the asynchronous send operation. The TResult
        /// parameter contains the response from the server.</returns>
        /// <exception cref="Dropbox.Api.ApiException{DownloadError}">Thrown if there is an
        /// error processing the request; This will contain a <see
        /// cref="DownloadError"/>.</exception>
        public t.Task<enc.IDownloadResponse<FileMetadata>> DownloadAsync(string path,
                                                                         string rev = null)
        {
            var downloadArg = new DownloadArg(path,
                                              rev);

            return this.DownloadAsync(downloadArg);
        }
コード例 #6
0
        /// <summary>
        /// <para>Begins an asynchronous send to the download route.</para>
        /// </summary>
        /// <param name="downloadArg">The request parameters.</param>
        /// <param name="callback">The method to be called when the asynchronous send is
        /// completed.</param>
        /// <param name="state">A user provided object that distinguished this send from other
        /// send requests.</param>
        /// <returns>An object that represents the asynchronous send request.</returns>
        public sys.IAsyncResult BeginDownload(DownloadArg downloadArg, sys.AsyncCallback callback, object state = null)
        {
            var task = this.DownloadAsync(downloadArg);

            return enc.Util.ToApm(task, callback, state);
        }
コード例 #7
0
 /// <summary>
 /// <para>Download a file from a user's Dropbox.</para>
 /// </summary>
 /// <param name="downloadArg">The request parameters</param>
 /// <returns>The task that represents the asynchronous send operation. The TResult
 /// parameter contains the response from the server.</returns>
 /// <exception cref="Dropbox.Api.ApiException{DownloadError}">Thrown if there is an
 /// error processing the request; This will contain a <see
 /// cref="DownloadError"/>.</exception>
 public t.Task<enc.IDownloadResponse<FileMetadata>> DownloadAsync(DownloadArg downloadArg)
 {
     return this.Transport.SendDownloadRequestAsync<DownloadArg, FileMetadata, DownloadError>(downloadArg, "content", "/files/download", DownloadArg.Encoder, FileMetadata.Decoder, DownloadError.Decoder);
 }
コード例 #8
0
 public Task <IDownloadResponse <FileMetadata> > DownloadAsync(DownloadArg downloadArg)
 {
     return(_client.Files.DownloadAsync(downloadArg));
 }
コード例 #9
0
        public async Task<bool> UpdateDocument(Guid guid, string path)
        {
            ExactOnlineClient exactOnlineClient = this.GetExactOnlineClient();

            DropboxClient dropboxClient = this.GetDropboxClient(DropboxModel.AccessToken);
            DownloadArg arg = new DownloadArg(path);

            DocumentAttachment attachment = new DocumentAttachment();
            attachment.Document = guid;
            attachment.FileName = this.GetFileName(path);
            attachment.Attachment = await this.GetDropboxService().DownloadContentAsByteArray(dropboxClient, arg);

            bool isAttached = exactOnlineClient.For<DocumentAttachment>().Insert(ref attachment);

            return isAttached;
        }
コード例 #10
0
        public async Task<bool> NewDocument(string path)
        {
            ExactOnlineClient exactOnlineClient = this.GetExactOnlineClient();

            Document document = new Document();
            document.Subject = this.GetFileName(path);
            document.Type = 183; // Attachment Type
            document.Category = Guid.Parse("3b6d3833-b31b-423d-bc3c-39c62b8f2b12"); // General Category

            bool isCreated = exactOnlineClient.For<Document>().Insert(ref document);

            if (!isCreated)
            {
                throw new Exception("Document fail to create on Exact Online server");
            }

            DropboxClient dropboxClient = this.GetDropboxClient(this.DropboxModel.AccessToken);
            DownloadArg arg = new DownloadArg(path);

            DocumentAttachment attachment = new DocumentAttachment();
            attachment.Document = document.ID;
            attachment.FileName = this.GetFileName(path);
            attachment.Attachment = await this.GetDropboxService().DownloadContentAsByteArray(dropboxClient, arg);

            bool isAttached = exactOnlineClient.For<DocumentAttachment>().Insert(ref attachment);

            return isAttached;
        }
コード例 #11
0
 public Task <IDownloadResponse <FileMetadata> > DownloadAsync(DownloadArg downloadArg) => _client.Files.DownloadAsync(downloadArg);
コード例 #12
0
        /// <summary>
        /// Asynchronously downloads the file.
        /// </summary>
        /// <returns></returns>
        protected override async Task<SerializableAPIResult<CloudStorageServiceAPIFile>> DownloadFileAsync()
        {
            SerializableAPIResult<CloudStorageServiceAPIFile> result = new SerializableAPIResult<CloudStorageServiceAPIFile>();

            try
            {
                DownloadArg arg = new DownloadArg($"/{SettingsFileNameWithoutExtension}");
                using (DropboxClient client = GetClient())
                {
                    Task<Stream> response = await client.Files.DownloadAsync(arg)
                        .ContinueWith(async task => await task.Result.GetContentAsStreamAsync());
                    return await GetMappedAPIFileAsync(result, response.Result);
                }
            }
            catch (ApiException<DownloadError> ex)
            {
                result.Error = new SerializableAPIError { ErrorMessage = ex.Message };
            }
            catch (AuthException exc)
            {
                IsAuthenticated = false;
                result.Error = new SerializableAPIError { ErrorMessage = exc.Message };
            }
            catch (BadInputException exc)
            {
                IsAuthenticated = false;
                result.Error = new SerializableAPIError { ErrorMessage = exc.Message };
            }
            catch (Exception exc)
            {
                result.Error = new SerializableAPIError { ErrorMessage = exc.Message };
            }

            return result;
        }