Beispiel #1
0
        /// <summary>
        /// Upload file to Disk as asynchronous
        /// </summary>
        /// <param name="destFileName">The path to the resource in the Disk. Path in the parameter value should be encoded in the URL format. Example 'old/new/good.txt'</param>
        /// <param name="sourceFileName">Path to file on local computer.</param>
        /// <param name="overwrite">Overwrite existing file.</param>
        /// <param name="progress">Function for display progress download</param>
        /// <returns>The return value of the ErrorResponse structure with null values if successful, else error message</returns>
        public async Task <ErrorResponse> UploadResourceAsync(string destFileName, string sourceFileName, bool overwrite = false, IProgress <double> progress = null)
        {
            bool          success = false;
            string        url;
            string        content;
            Param         param         = new Param();
            ErrorResponse errorResponse = new ErrorResponse();

            param.Path      = destFileName;
            param.Overwrite = overwrite;

            content = CommandDisk(Oauth, YandexDiskAsk.Get_link_uploadable_file, param);

            if (content != null)
            {
                JObject json = JObject.Parse(content);
                url     = (string)json.SelectToken("href");
                success = await YandexDiskUtils.UploadFileAsync(url, sourceFileName, progress);

                errorResponse = errorResponse.GetError(content);
            }

            if (!success && errorResponse.Error == null)
            {
                errorResponse.Description = "Connection error.";
                errorResponse.Error       = "Http request exception.";
                errorResponse.Message     = "Upload failure.";
            }

            return(errorResponse);
        }
Beispiel #2
0
        /// <summary>
        /// Download file or folder from Disk, if is folder is downloaded to zip archive
        /// </summary>
        /// <param name="sourceFileName">The path to the resource in the Disk. Path in the parameter value should be encoded in the URL format. Example 'old/new/good.txt'</param>
        /// <param name="destFileName">Destination file name</param>
        /// <returns>The return value of the ErrorResponse structure with null values if successful, else error message</returns>
        public ErrorResponse DownloadResource(string sourceFileName, string destFileName)
        {
            bool          success = false;
            string        url;
            string        content;
            Param         param         = new Param();
            ErrorResponse errorResponse = new ErrorResponse();

            param.Path = sourceFileName;

            content = CommandDisk(Oauth, YandexDiskAsk.Get_link_downloadable_file, param);

            if (content != null)
            {
                JObject json = JObject.Parse(content);
                url           = (string)json.SelectToken("href");
                success       = YandexDiskUtils.DownloadFile(url, destFileName);
                errorResponse = errorResponse.GetError(content);
            }

            if (!success && errorResponse.Error == null)
            {
                errorResponse.Description = "Connection error.";
                errorResponse.Error       = "Http request exception.";
                errorResponse.Message     = "Download failure.";
            }

            return(errorResponse);
        }