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));
}