Ejemplo n.º 1
0
        /// <summary>
        /// Send a PATCH request with status = uploaded to mark this upload as finished from the client's perspective.
        /// </summary>
        /// <param name="upload"></param>
        /// <returns></returns>
        public async Task<Upload> FinishUploadAsync(Upload upload)
        {
            _log.Debug("Called FinishUploadAsync with parameter url = \"" + upload.Url + "\".");

            try
            {
                var patchedUpload = await this.PatchUploadAsync(upload, @"{""status"": ""uploaded""}").ConfigureAwait(false);

                return patchedUpload;
            }
            catch (Exception)
            { throw; }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send a DELETE "Upload.Url"-url request which deletes a Deepfreeze upload.
        /// </summary>
        /// <param name="archive"></param>
        /// <returns>bool</returns>
        public async Task<bool> DeleteUploadAsync(Upload upload)
        {
            _log.Debug("Called DeleteUploadAsync with parameter url = \"" + upload.Url + "\".");

            var request = CreateHttpRequestWithSignature(DELETE, upload.Url, false);
            HttpResponseMessage response;

            try
            {
                using (var httpClient = this.CreateHttpClientWithRetryLogic(FASTRETRY))
                {
                    response = await httpClient.SendAsync(request).ConfigureAwait(false);
                }

                //response.EnsureSuccessStatusCode();

                return true;
            }
            catch (Exception e)
            {
                // If the caught exception is a BigStashException, then return it immediately
                // in order to be propagated to the higher caller as is, without wrapping it in
                // a new BigStashException instance.
                if (e is BigStashException)
                    throw;

                throw this.BigStashExceptionHandler(e);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send a PATCH "Upload.Url"-url request which returns a Deepfreeze upload.
        /// This request is responsible for patching an upload resource with the specified patchContent parameter.
        /// </summary>
        /// <param name="upload"></param>
        /// <param name="patchContent"></param>
        /// <returns></returns>
        public async Task<Upload> PatchUploadAsync(Upload upload, string patchContent)
        {
            _log.Debug("Called PatchUploadAsync with parameters url = \"" + upload.Url + "\" and content = \"" + patchContent + "\".");

            var request = CreateHttpRequestWithSignature(PATCH, upload.Url, false);
            request.Content = new StringContent(patchContent, Encoding.UTF8, "application/json");
            HttpResponseMessage response;

            try
            {
                using (var httpClient = this.CreateHttpClientWithRetryLogic(LONGRETRY))
                {
                    response = await httpClient.SendAsync(request).ConfigureAwait(false);
                }

                //response.EnsureSuccessStatusCode();

                string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (content != null)
                {
                    var patchedUpload = JsonConvert.DeserializeObject<Upload>(content);
                    return patchedUpload;
                }
                else
                {
                    throw new Exceptions.BigStashException("Server replied with success but response was empty.");
                }
            }
            catch (Exception e)
            {
                // If the caught exception is a BigStashException, then return it immediately
                // in order to be propagated to the higher caller as is, without wrapping it in
                // a new BigStashException instance.
                if (e is BigStashException)
                    throw;

                throw this.BigStashExceptionHandler(e);
            }
        }