public string NewPost(string blogId, BlogPost post, INewCategoryContext newCategoryContext, bool publish, out string etag, out XmlDocument remotePost) { if (!publish && !Options.SupportsPostAsDraft) { Trace.Fail("Post to draft not supported on this provider"); throw new BlogClientPostAsDraftUnsupportedException(); } Login(); FixupBlogId(ref blogId); XmlDocument doc = new XmlDocument(); XmlElement entryNode = doc.CreateElement(_atomNS.Prefix, "entry", _atomNS.Uri); doc.AppendChild(entryNode); Populate(post, null, entryNode, publish); string slug = null; if (Options.SupportsSlug) { slug = post.Slug; } WebHeaderCollection responseHeaders; Uri uri = new Uri(blogId); XmlDocument result = xmlRestRequestHelper.Post( ref uri, new HttpRequestFilter(new NewPostRequest(this, slug).RequestFilter), ENTRY_CONTENT_TYPE, doc, _clientOptions.CharacterSet, out responseHeaders); etag = FilterWeakEtag(responseHeaders["ETag"]); string location = responseHeaders["Location"]; if (string.IsNullOrEmpty(location)) { throw new BlogClientInvalidServerResponseException("POST", "The HTTP response was missing the required Location header.", ""); } if (location != responseHeaders["Content-Location"] || result == null) { Uri locationUri = new Uri(location); WebHeaderCollection getResponseHeaders; result = xmlRestRequestHelper.Get(ref locationUri, RequestFilter, out getResponseHeaders); etag = FilterWeakEtag(getResponseHeaders["ETag"]); } remotePost = (XmlDocument)result.Clone(); Parse(result.DocumentElement, true, uri); if (Options.SupportsNewCategories) { foreach (BlogPostCategory category in post.NewCategories) { newCategoryContext.NewCategoryAdded(category); } } return(PostUriToPostId(location)); }
public async Task <string> NewPost(string blogId, BlogPost post, INewCategoryContext newCategoryContext, bool publish, PostResult postResult) { if (!publish && !Options.SupportsPostAsDraft) { //Debug.Fail("Post to draft not supported on this provider"); throw new BlogClientPostAsDraftUnsupportedException(); } Login(); FixupBlogId(ref blogId); XmlDocument doc = new XmlDocument(); XmlElement entryNode = doc.CreateElementNS(_atomNS.Uri, _atomNS.Prefix + ":entry"); doc.AppendChild(entryNode); Populate(post, null, entryNode, publish); string slug = null; if (Options.SupportsSlug) { slug = post.Slug; } XmlRestRequestHelper.XmlRequestResult xmlResult2 = new XmlRestRequestHelper.XmlRequestResult(); xmlResult2.uri = new Uri(blogId); XmlDocument result = await xmlRestRequestHelper.Post( new HttpAsyncRequestFilter(new NewPostRequest(this, slug).RequestFilter), ENTRY_CONTENT_TYPE, doc, _clientOptions.CharacterSet, xmlResult2); postResult.ETag = FilterWeakEtag(xmlResult2.responseHeaders["ETag"]); string location = xmlResult2.responseHeaders["Location"]; if (string.IsNullOrEmpty(location)) { throw new BlogClientInvalidServerResponseException("POST", "The HTTP response was missing the required Location header.", ""); } if (location != xmlResult2.responseHeaders["Content-Location"] || result == null) { XmlRestRequestHelper.XmlRequestResult xmlResult = new XmlRestRequestHelper.XmlRequestResult(); xmlResult.uri = new Uri(location); result = await xmlRestRequestHelper.Get(RequestFilter, xmlResult); postResult.ETag = FilterWeakEtag(xmlResult.responseHeaders["ETag"]); } postResult.AtomRemotePost = (XmlDocument)result.CloneNode(true); Parse(result.DocumentElement, true, xmlResult2.uri); if (Options.SupportsNewCategories) { foreach (BlogPostCategory category in post.NewCategories) { newCategoryContext.NewCategoryAdded(category); } } return(PostUriToPostId(location)); }