private async Task AddCategoriesXml(XmlElement categoriesNode, XmlElement containerNode, XmlRestRequestHelper.XmlRequestResult result) { if (categoriesNode.Attributes.Any(a => a.NodeName == "href")) { string href = XmlHelper.GetUrl(categoriesNode, "@href", result.uri); if (href != null && href.Length > 0) { Uri uri = new Uri(href); if (result.uri == null || !uri.Equals(result.uri)) // detect simple cycles { XmlDocument doc = await xmlRestRequestHelper.Get(RequestFilter, result); XmlElement categories = (XmlElement)doc.SelectSingleNodeNS(@"app:categories", _nsMgr.ToNSMethodFormat()); if (categories != null) { await AddCategoriesXml(categories, containerNode, result); } } } } else { containerNode.AppendChild(containerNode.OwnerDocument.ImportNode(categoriesNode, true)); } }
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); }
private void ParseFeedDoc(XmlDocument xmlDoc, Uri baseUri, bool includeTitle, ref string homepageUrl, ref string title) { if (includeTitle) { XmlElement titleEl = xmlDoc.SelectSingleNodeNS(@"atom:feed/atom:title", _nsMgr.ToNSMethodFormat()) as XmlElement; if (titleEl != null) { title = _atomVer.TextNodeToPlaintext(titleEl); } } foreach (XmlElement linkEl in xmlDoc.SelectNodesNS(@"atom:feed/atom:link[@rel='alternate']", _nsMgr.ToNSMethodFormat())) { IDictionary contentTypeInfo = MimeHelper.ParseContentType(linkEl.GetAttribute("type"), true); switch (contentTypeInfo[""] as string) { case "text/html": case "application/xhtml+xml": homepageUrl = XmlHelper.GetUrl(linkEl, "@href", baseUri); return; } } }
protected async Task <BlogInfo[]> GetUsersBlogsInternal() { XmlRestRequestHelper.XmlRequestResult xmlResult = new XmlRestRequestHelper.XmlRequestResult(); xmlResult.uri = FeedServiceUrl; XmlDocument xmlDoc = await xmlRestRequestHelper.Get(RequestFilter, xmlResult); // Either the FeedServiceUrl points to a service document OR a feed. if (xmlDoc.SelectSingleNodeNS("/app:service", _nsMgr.ToNSMethodFormat()) != null) { ArrayList blogInfos = new ArrayList(); foreach (XmlElement coll in xmlDoc.SelectNodesNS("/app:service/app:workspace/app:collection", _nsMgr.ToNSMethodFormat())) { bool promote = ShouldPromote(coll); // does this collection accept entries? XmlNodeList acceptNodes = coll.SelectNodesNS("app:accept", _nsMgr.ToNSMethodFormat()); bool acceptsEntries = false; if (acceptNodes.Count == 0) { acceptsEntries = true; } else { foreach (XmlElement acceptNode in acceptNodes) { if (AcceptsEntry(acceptNode.InnerText)) { acceptsEntries = true; break; } } } if (acceptsEntries) { string feedUrl = XmlHelper.GetUrl(coll, "@href", xmlResult.uri); if (feedUrl == null || feedUrl.Length == 0) { continue; } // form title StringBuilder titleBuilder = new StringBuilder(); foreach (XmlElement titleContainerNode in new XmlElement[] { coll.ParentNode as XmlElement, coll }) { Debug.Assert(titleContainerNode != null); if (titleContainerNode != null) { XmlElement titleNode = titleContainerNode.SelectSingleNodeNS("atom:title", _nsMgr.ToNSMethodFormat()) as XmlElement; if (titleNode != null) { string titlePart = _atomVer.TextNodeToPlaintext(titleNode); if (titlePart.Length != 0) { //Res.LOCME("loc the separator between parts of the blog name"); if (titleBuilder.Length != 0) { titleBuilder.Append(" - "); } titleBuilder.Append(titlePart); } } } } // get homepage URL string homepageUrl = ""; string dummy = ""; XmlRestRequestHelper.XmlRequestResult xmlResult2 = new XmlRestRequestHelper.XmlRequestResult(); xmlResult2.uri = new Uri(feedUrl); XmlDocument feedDoc = await xmlRestRequestHelper.Get(RequestFilter, xmlResult2); ParseFeedDoc(feedDoc, xmlResult2.uri, false, ref homepageUrl, ref dummy); // TODO: Sniff out the homepage URL BlogInfo blogInfo = new BlogInfo(feedUrl, titleBuilder.ToString().Trim(), homepageUrl); if (promote) { blogInfos.Insert(0, blogInfo); } else { blogInfos.Add(blogInfo); } } } return((BlogInfo[])blogInfos.ToArray(typeof(BlogInfo))); } else { string title = string.Empty; string homepageUrl = string.Empty; ParseFeedDoc(xmlDoc, xmlResult.uri, true, ref homepageUrl, ref title); return(new BlogInfo[] { new BlogInfo(UrlHelper.SafeToAbsoluteUri(FeedServiceUrl), title, homepageUrl) }); } }
public virtual async Task <bool> EditPost(string blogId, BlogPost post, INewCategoryContext newCategoryContext, bool publish, EditPostResult result) { if (!publish && !Options.SupportsPostAsDraft) { //Debug.Fail("Post to draft not supported on this provider"); throw new BlogClientPostAsDraftUnsupportedException(); } Login(); FixupBlogId(ref blogId); XmlDocument doc = post.AtomRemotePost; XmlElement entryNode = doc.SelectSingleNodeNS("/atom:entry", _nsMgr.ToNSMethodFormat()) as XmlElement; // No documentUri is needed because we ensure xml:base is set on the root // when we retrieve from XmlRestRequestHelper Populate(post, null, entryNode, publish); string etagToMatch = FilterWeakEtag(post.ETag); try { retry: try { XmlRestRequestHelper.XmlRequestResult xmlResult2 = new XmlRestRequestHelper.XmlRequestResult(); xmlResult2.uri = PostIdToPostUri(post.Id); await xmlRestRequestHelper.Put(etagToMatch, RequestFilter, ENTRY_CONTENT_TYPE, doc, _clientOptions.CharacterSet, true, xmlResult2); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { if (((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.PreconditionFailed) { if (etagToMatch != null && etagToMatch.Length > 0) { HttpRequestHelper.LogException(we); string currentEtag = await GetEtag(UrlHelper.SafeToAbsoluteUri(PostIdToPostUri(post.Id))); if (currentEtag != null && currentEtag.Length > 0 && currentEtag != etagToMatch) { if (ConfirmOverwrite()) { etagToMatch = currentEtag; goto retry; } else { throw new BlogClientOperationCancelledException(); } } } } } throw; } } catch (Exception e) { if (!AttemptEditPostRecover(e, blogId, post, newCategoryContext, publish, result)) { // convert to a provider exception if this is a 404 (allow us to // catch this case explicitly and attempt a new post to recover) if (e is WebException) { WebException webEx = e as WebException; HttpWebResponse response = webEx.Response as HttpWebResponse; if (response != null && response.StatusCode == HttpStatusCode.NotFound) { throw new BlogClientProviderException("404", e.Message); } } // no special handling, just re-throw throw; } } XmlRestRequestHelper.XmlRequestResult xmlResult = new XmlRestRequestHelper.XmlRequestResult(); xmlResult.uri = PostIdToPostUri(post.Id); xmlResult.responseHeaders = new HttpResponseMessage().Headers; result.remotePost = await xmlRestRequestHelper.Get(RequestFilter, xmlResult); result.etag = FilterWeakEtag(xmlResult.responseHeaders["ETag"]); //Debug.Assert(remotePost != null, "After successful PUT, remote post could not be retrieved"); if (Options.SupportsNewCategories) { foreach (BlogPostCategory category in post.NewCategories) { newCategoryContext.NewCategoryAdded(category); } } return(true); }
private AppxManifest() { Task t = Task.Run(async () => { Uri u = new Uri("ms-appx:///AppxManifest.xml"); var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(u); var stream = await file.OpenStreamForReadAsync(); var streamReader = new StreamReader(stream); var xml = await streamReader.ReadToEndAsync(); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(xml); IXmlNode phoneNode = xdoc.SelectSingleNodeNS("/appx:Package/mp:PhoneIdentity", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\""); if (phoneNode != null) { IXmlNode phoneIdNode = phoneNode.Attributes.GetNamedItem("PhoneProductId"); if (phoneIdNode != null) { PhoneProductId = new Guid(phoneIdNode.InnerText); } } //parse xml IXmlNode nameNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Properties/appx:DisplayName", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\""); if (nameNode != null) { DisplayName = nameNode.InnerText; } IXmlNode publisherNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Properties/appx:PublisherDisplayName", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\""); if (publisherNode != null) { PublisherDisplayName = publisherNode.InnerText; } IXmlNode visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/uap:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\" xmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\""); if (visualElementsNode == null) { visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/m3:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:m3=\"http://schemas.microsoft.com/appx/2014/manifest\""); } if (visualElementsNode == null) { visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/m2:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\""); } if (visualElementsNode != null) { /*IXmlNode toastCapableNode = visualElementsNode.Attributes.GetNamedItem("ToastCapable"); if (toastCapableNode != null) { bool toastCapable = bool.Parse(toastCapableNode.InnerText); if (toastCapable) { Capabilities |= Capability.PushNotification; } }*/ IXmlNode bgColorNode = visualElementsNode.Attributes.GetNamedItem("BackgroundColor"); if (bgColorNode != null) { string color = bgColorNode.InnerText; if (color.StartsWith("#")) { // hex color if (color.Length == 7) { var r = byte.Parse(color.Substring(1, 2), global::System.Globalization.NumberStyles.HexNumber); var g = byte.Parse(color.Substring(3, 2), global::System.Globalization.NumberStyles.HexNumber); var b = byte.Parse(color.Substring(5, 2), global::System.Globalization.NumberStyles.HexNumber); BackgroundColor = Color.FromArgb(0xff, r, g, b); } else if (color.Length == 9) { var a = byte.Parse(color.Substring(1, 2), global::System.Globalization.NumberStyles.HexNumber); var r = byte.Parse(color.Substring(3, 2), global::System.Globalization.NumberStyles.HexNumber); var g = byte.Parse(color.Substring(5, 2), global::System.Globalization.NumberStyles.HexNumber); var b = byte.Parse(color.Substring(7, 2), global::System.Globalization.NumberStyles.HexNumber); BackgroundColor = Color.FromArgb(a, r, g, b); } } else { // color name foreach (PropertyInfo pi in typeof(Colors).GetRuntimeProperties()) { if (pi.Name.ToLower() == color) { BackgroundColor = (Color)pi.GetValue(null); break; } } } } IXmlNode descriptionNode = visualElementsNode.Attributes.GetNamedItem("Description"); if(descriptionNode != null) { Description = descriptionNode.InnerText; } } IXmlNode logoNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Properties/appx:Logo", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\""); if (logoNode != null) { Logo = new Uri("ms-appx:///" + logoNode.InnerText.Replace("\\", "/")); } IXmlNode capabilitiesNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Capabilities", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\""); if (capabilitiesNode != null) { foreach (IXmlNode element in capabilitiesNode.ChildNodes) { if (element.NodeType == NodeType.ElementNode) { IXmlNode capNode = element.Attributes.GetNamedItem("Name"); string cap = capNode.InnerText; switch (cap) { case "appointments": Capabilities |= Capability.Appointments; break; case "contacts": Capabilities |= Capability.Contacts; break; case "musicLibrary": Capabilities |= Capability.Music; break; case "picturesLibrary": Capabilities |= Capability.Pictures; break; case "videosLibrary": Capabilities |= Capability.Videos; break; case "internetClient": Capabilities |= Capability.Internet; break; case "internetClientServer": Capabilities |= Capability.Internet; break; case "location": DeviceCapabilities |= DeviceCapability.Location; break; case "proximity": DeviceCapabilities |= DeviceCapability.Proximity; break; case "microphone": DeviceCapabilities |= DeviceCapability.Microphone; break; case "webcam": DeviceCapabilities |= DeviceCapability.Camera; break; case "removableStorage": Capabilities |= Capability.RemovableStorage; break; case "enterpriseAuthentication": Capabilities |= Capability.EnterpriseAuthentication; break; case "sharedUserCertificates": Capabilities |= Capability.SharedUserCertificates; break; } } } } }); t.Wait(); }