protected virtual void UpdateETag(IFileUploadContext uploadContext, string editUri)
 {
     try
     {
         string newEtag = AtomClient.GetEtag(editUri, _requestFilter);
         uploadContext.Settings.SetString(MEDIA_ETAG, newEtag);
     }
     catch (Exception)
     {
     }
 }
        protected virtual async Task UpdateImage(bool allowWriteStreamBuffering, string editMediaUri, string path, string editEntryUri, string etag, bool getEditInfo, PostNewImageResult result)
        {
            HttpResponseMessage response = null;

            try
            {
                response = await RedirectHelper.GetResponse(editMediaUri,
                                                            new RedirectHelper.RequestFactory(new ImageUploadHelper(this, path, "PUT", etag, allowWriteStreamBuffering).Create));
            }
            catch (WebException we)
            {
                bool recovered = false;

                if (we.Status == WebExceptionStatus.ProtocolError && we.Response != null)
                {
                    HttpWebResponse errResponse = we.Response as HttpWebResponse;
                    if (errResponse != null && errResponse.StatusCode == HttpStatusCode.PreconditionFailed)
                    {
                        string newEtag = await AtomClient.GetEtag(editMediaUri, _requestFilter);

                        if (newEtag != null && newEtag.Length > 0 && newEtag != etag)
                        {
                            if (!AtomClient.ConfirmOverwrite())
                            {
                                throw new BlogClientOperationCancelledException();
                            }

                            try
                            {
                                response = await RedirectHelper.GetResponse(editMediaUri,
                                                                            new RedirectHelper.RequestFactory(new ImageUploadHelper(this, path, "PUT", newEtag, allowWriteStreamBuffering).Create));
                            }
                            finally
                            {
                                if (response != null)
                                {
                                    response.Dispose();
                                }
                            }

                            recovered = true;
                        }
                    }
                    else if (!allowWriteStreamBuffering)
                    {
                        // The error may have been due to the server requiring stream buffering (WinLive 114314, 252175)
                        // Try again with stream buffering.
                        await UpdateImage(true, editMediaUri, path, editEntryUri, etag, getEditInfo, result);

                        recovered = true;
                    }
                }
                if (!recovered)
                {
                    throw;
                }
            }

            // Check to see if we are going to get the src url and the etag, in most cases we will want to get this
            // information, but in the case of a photo album, since we never edit the image or link directly to them
            // we don't need the information and it can saves an http request.
            if (getEditInfo)
            {
                string selfPage;

                XmlRestRequestHelper.XmlRequestResult xmlResult = new XmlRestRequestHelper.XmlRequestResult();
                xmlResult.uri = new Uri(editEntryUri);
                XmlDocument mediaLinkEntry = await xmlRestRequestHelper.Get(_requestFilter, xmlResult);

                ParseResponse(mediaLinkEntry, result);
            }
            else
            {
                //thumbnailSmall = null;
                //thumbnailLarge = null;
                //srcUrl = null;
            }
        }
Пример #3
0
 public NewPostRequest(AtomClient parent, string slug)
 {
     _parent = parent;
     _slug   = slug;
 }
Пример #4
0
 public NewPostRequest(AtomClient parent, string slug)
 {
     _parent = parent;
     _slug = slug;
 }