protected virtual async Task <XmlDocument> GetCategoryXml(string blogId) { // Get the service document Login(); FixupBlogId(ref blogId); XmlRestRequestHelper.XmlRequestResult result = new XmlRestRequestHelper.XmlRequestResult(); result.uri = FeedServiceUrl; var xmlDoc = await xmlRestRequestHelper.Get(RequestFilter, result); foreach (XmlElement entryEl in xmlDoc.SelectNodesNS("app:service/app:workspace/app:collection", _nsMgr.ToNSMethodFormat())) { string href = XmlHelper.GetUrl(entryEl, "@href", result.uri); if (blogId == href) { XmlDocument results = new XmlDocument(); XmlElement rootElement = results.CreateElement("categoryInfo"); results.AppendChild(rootElement); foreach (XmlElement categoriesNode in entryEl.SelectNodesNS("app:categories", _nsMgr.ToNSMethodFormat())) { await AddCategoriesXml(categoriesNode, rootElement, result); } return(results); } } //Debug.Fail("Couldn't find collection in service document:\r\n" + xmlDoc.OuterXml); return(new XmlDocument()); }
/// <summary> /// /// </summary> /// <param name="entryEl"></param> /// <param name="nsMgr"></param> /// <param name="rel"></param> /// <param name="contentType">e.g. application/atom+xml</param> /// <param name="contentSubType">e.g. "entry"</param> /// <param name="baseUri"></param> /// <returns></returns> public static string GetLink(IXmlNode entryEl, XmlNamespaceManager nsMgr, string rel, string contentType, string contentSubType, Uri baseUri) { Debug.Assert(contentSubType == null || contentType != null, "contentSubType is only used if contentType is also provided"); string xpath = string.Format(CultureInfo.InvariantCulture, @"atom:link[@rel='{0}']", rel); foreach (XmlElement link in entryEl.SelectNodesNS(xpath, nsMgr.ToNSMethodFormat())) { if (contentType != null) { string mimeType = link.GetAttribute("type"); if (mimeType == null || mimeType == "") { continue; } IDictionary mimeData = MimeHelper.ParseContentType(mimeType, true); if (contentType != (string)mimeData[""]) { continue; } if (contentSubType != null && contentSubType != (string)mimeData["type"]) { continue; } } return(XmlHelper.GetUrl(link, "@href", baseUri)); } return(""); }
private static AtomContentValue ToTextValue(IXmlNode target) { string type = "text"; var attrType = target.Attributes.SingleOrDefault(a => a.NodeValue == "type"); if (attrType != null) { type = (string)attrType.NodeValue; } switch (type) { case "html": return(new AtomContentValue(AtomContentValueType.HTML, target.InnerText.Trim())); case "xhtml": { XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); var div = target.SelectSingleNodeNS("xhtml:div", nsMgr.ToNSMethodFormat()); if (div != null) { return(new AtomContentValue(AtomContentValueType.XHTML, (string)div.NodeValue)); } else { return(new AtomContentValue(AtomContentValueType.XHTML, string.Empty)); } } default: case "text": return(new AtomContentValue(AtomContentValueType.Text, target.InnerText.Trim())); } }
private string GetRdfAltInnerText(string xpath) { // get description var xmlNode = doc.SelectSingleNodeNS(xpath, NamespaceManager.ToNSMethodFormat()); if (xmlNode != null && xmlNode.ChildNodes.Count > 0) { return(xmlNode.ChildNodes[0].InnerText); } return(null); }
public override void RemoveAllCategories(IXmlNode node, string categoryScheme, Uri documentUri) { XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("dc", DC_URI); IXmlNode category; while (null != (category = node.SelectSingleNodeNS("dc:subject", nsMgr.ToNSMethodFormat()))) { category.ParentNode.RemoveChild(category); } }
private DateTime GetPublishDate(DateTime defaultValue) { var target = _entryNode.SelectSingleNodeNS("atom:published", _nsMgr.ToNSMethodFormat()); if (target == null) { return(defaultValue); } string val = target.InnerText; if (val == null) { return(defaultValue); } val = val.Trim(); if (val.Length == 0) { return(defaultValue); } return(ParseRfc3339(val)); }
public override BlogPostCategory[] ExtractCategories(XmlElement entry, string categoryScheme, Uri documentUri) { XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("dc", DC_URI); ArrayList results = new ArrayList(); foreach (XmlElement el in entry.SelectNodesNS("dc:subject", nsMgr.ToNSMethodFormat())) { string subject = el.InnerText; if (subject != string.Empty) { results.Add(new BlogPostCategory(subject, subject)); } } return((BlogPostCategory[])results.ToArray(typeof(BlogPostCategory))); }
public override BlogPostCategory[] ExtractCategories(XmlElement entry, string categoryScheme, Uri documentUri) { if (categoryScheme == null) { return(new BlogPostCategory[0]); } XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("atom", NamespaceUri); ArrayList results = new ArrayList(); foreach (XmlElement el in entry.SelectNodesNS("atom:category", nsMgr.ToNSMethodFormat())) { if (!SchemesEqual(el.GetAttribute("scheme"), categoryScheme)) { continue; } string term = el.GetAttribute("term"); string label = el.GetAttribute("label"); bool noTerm = term == null || term == string.Empty; bool noLabel = label == null || label == string.Empty; if (noTerm && noLabel) { continue; } if (noTerm) { term = label; } if (noLabel) { label = term; } results.Add(new BlogPostCategory(term, label)); } return((BlogPostCategory[])results.ToArray(typeof(BlogPostCategory))); }
public async Task <string> GetBlogImagesAlbum(string albumName) { const string FEED_REL = "http://schemas.google.com/g/2005#feed"; const string GPHOTO_NS_URI = "http://schemas.google.com/photos/2007"; Uri picasaUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default"); try { Uri reqUri = picasaUri; var albumListDoc = await AtomClient.xmlRestRequestHelper.Get(await CreateAuthorizationFilter(), new XmlRestRequestHelper.XmlRequestResult() { uri = reqUri }, "kind", "album"); foreach (var entryEl in albumListDoc.SelectNodesNS(@"/atom:feed/atom:entry", _nsMgr.ToNSMethodFormat())) { var titleNode = entryEl.SelectSingleNodeNS(@"atom:title", _nsMgr.ToNSMethodFormat()); if (titleNode != null) { string titleText = AtomProtocolVersion.V10DraftBlogger.TextNodeToPlaintext(titleNode); if (titleText == albumName) { XmlNamespaceManager nsMgr2 = new XmlNamespaceManager(new NameTable()); nsMgr2.AddNamespace("gphoto", "http://schemas.google.com/photos/2007"); var numPhotosRemainingNode = entryEl.SelectSingleNodeNS("gphoto:numphotosremaining/text()", nsMgr2.ToNSMethodFormat()); if (numPhotosRemainingNode != null) { int numPhotosRemaining; if (int.TryParse((string)numPhotosRemainingNode.NodeValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out numPhotosRemaining)) { if (numPhotosRemaining < 1) { continue; } } } string selfHref = AtomEntry.GetLink(entryEl, _nsMgr, FEED_REL, "application/atom+xml", null, reqUri); if (selfHref.Length > 1) { return(selfHref); } } } } } catch (WebException we) { HttpWebResponse httpWebResponse = we.Response as HttpWebResponse; if (httpWebResponse != null) { HttpRequestHelper.DumpResponse(httpWebResponse); if (httpWebResponse.StatusCode == HttpStatusCode.NotFound) { throw new BlogClientOperationCancelledException(); } } throw; } throw new Exception("Could not find a Google Photos album called 'NetWriter'. Create an Album in Google Photos called 'NetWriter' and try again."); //var newDoc = new Windows.Data.Xml.Dom.XmlDocument(); //var newEntryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:entry"); //newDoc.AppendChild(newEntryEl); //var newTitleEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:title"); //newTitleEl.SetAttribute("type", "text"); //newTitleEl.InnerText = albumName; //newEntryEl.AppendChild(newTitleEl); //var newSummaryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:summary"); //newSummaryEl.SetAttribute("type", "text"); //newSummaryEl.InnerText = "This album is used to store pictures from blog posts published by Net Writer."; //newEntryEl.AppendChild(newSummaryEl); //var newAccessEl = newDoc.CreateElementNS(GPHOTO_NS_URI, "gphoto:access"); //newAccessEl.InnerText = "private"; //newEntryEl.AppendChild(newAccessEl); //var newCategoryEl = newDoc.CreateElementNS(AtomProtocolVersion.V10DraftBlogger.NamespaceUri, "atom:category"); //newCategoryEl.SetAttribute("scheme", "http://schemas.google.com/g/2005#kind"); //newCategoryEl.SetAttribute("term", "http://schemas.google.com/photos/2007#album"); //newEntryEl.AppendChild(newCategoryEl); //XmlRestRequestHelper.XmlRequestResult result = new XmlRestRequestHelper.XmlRequestResult() {uri = picasaUri}; //var newAlbumResult = await AtomClient.xmlRestRequestHelper.Post(await CreateAuthorizationFilter(), "application/atom+xml", newDoc, null, result); //var newAlbumResultEntryEl = newAlbumResult.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()); //Debug.Assert(newAlbumResultEntryEl != null); //return AtomEntry.GetLink(newAlbumResultEntryEl, _nsMgr, FEED_REL, "application/atom+xml", null, result.uri); }
public override void RemoveAllCategories(IXmlNode node, string categoryScheme, Uri documentUri) { if (categoryScheme == null) { return; } XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("atom", NamespaceUri); ArrayList nodesToRemove = new ArrayList(); foreach (XmlElement categoryEl in node.SelectNodesNS("atom:category", nsMgr.ToNSMethodFormat())) { string scheme = categoryEl.GetAttribute("scheme"); if (SchemesEqual(scheme, categoryScheme)) { nodesToRemove.Add(categoryEl); } } foreach (XmlElement categoryEl in nodesToRemove) { categoryEl.ParentNode.RemoveChild(categoryEl); } }
private static AtomContentValue ToTextValue(IXmlNode node) { string type = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "type").NodeValue; string mode = (string)node.Attributes.SingleOrDefault(a => a.NodeName == "mode")?.NodeValue; if (string.IsNullOrEmpty(mode)) { mode = "xml"; } string content; switch (mode) { case "escaped": content = node.InnerText; break; case "base64": content = Encoding.UTF8.GetString(Convert.FromBase64String((string)node.NodeValue)); break; default: case "xml": content = node.InnerText; if (type == string.Empty && node.SelectSingleNode("./*") != null) { type = "application/xhtml+xml"; } break; } AtomContentValue tv; switch (type) { case "text/html": tv = new AtomContentValue(AtomContentValueType.HTML, content); break; case "application/xhtml+xml": XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable()); nsMgr.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); if (mode == "xml") { var div = node.SelectSingleNodeNS("xhtml:div", nsMgr.ToNSMethodFormat()); if (div != null) { tv = new AtomContentValue(AtomContentValueType.XHTML, (string)div.NodeValue); } else { tv = new AtomContentValue(AtomContentValueType.XHTML, string.Empty); } } else { tv = new AtomContentValue(AtomContentValueType.XHTML, content); } break; default: case "text/plain": tv = new AtomContentValue(AtomContentValueType.Text, content); break; } return(tv); }