public static XmlElement GetHttpRuntime(XmlDocument configuration, bool createIfMissing = false) { var systemWeb = configuration.SelectSingleElement("/configuration/system.web"); if (systemWeb == null) { if (!createIfMissing) { return null; } systemWeb = configuration.CreateElement("system.web"); configuration.DocumentElement.AppendChild(systemWeb); } var httpRuntime = systemWeb.SelectSingleElement("httpRuntime"); if (httpRuntime != null) { return httpRuntime; } if (!createIfMissing) { return null; } httpRuntime = configuration.CreateElement("httpRuntime"); systemWeb.AppendChild(httpRuntime); return httpRuntime; }
private CategoryConfiguration(XmlDocument configDocument) { XmlNamespaceManager nm = XmlNamespaces.Manager; XmlElement categoryElement = configDocument.SelectSingleElement("c:configuration/c:category", nm); this.Name = categoryElement.GetAttribute("name"); this.Variables = categoryElement.SelectSingleElement("c:variables", nm); this.ConfigurationElement = categoryElement; }
private void SummarizeOverview(XmlDocument resultDoc, string outputPath) { XmlElement resultElement = resultDoc.SelectSingleElement("/internationalization/result"); foreach (XmlElement categoryElem in resultElement.SelectNodes("category")) { XmlElement phrasesElement = categoryElem.AppendElement(resultDoc.CreateElement("phrases")); foreach (XmlElement resourceNode in categoryElem.SelectNodes("resources/resource")) { string resourceName = string.Concat( Regex.Replace(resourceNode.GetAttribute("path"), @"^.*?([^\\]+\\[^\\]+)$", "$1"), "/", resourceNode.GetAttribute("name")).Replace("\\", "/"); foreach (XmlElement phraseNode in resourceNode.SelectNodes("phrases/phrase")) { string phraseID = phraseNode.GetAttribute("id"); XmlElement targetPhrase = phrasesElement.SelectSingleElement(string.Format("phrase[@id='{0}']", phraseID)); if (targetPhrase == null) { targetPhrase = phrasesElement.AppendElement(resultDoc.CreateElement("phrase")); foreach (XmlAttribute attrNode in phraseNode.Attributes) { targetPhrase.SetAttribute(attrNode.Name, attrNode.Value); } } if (targetPhrase.SelectSingleNode(string.Format("resource[text()='{0}']", resourceName)) == null) targetPhrase.AppendElement(resultDoc.CreateElement("resource")).InnerText = resourceName; } } } if (processor == null) { processor = XsltTransform.Create(context, XsltPath); } StringBuilder text = new StringBuilder(); StringWriter writer = new StringWriter(text); processor.Transform(resultDoc, writer, context); string resultPath = Path.Combine(outputPath, string.Format(SummaryXmlName, arguments["category"])); string reportPath = Path.Combine(outputPath, string.Format(SummaryHtmlName, arguments["category"])); if (!Directory.Exists(outputPath)) { try { Directory.CreateDirectory(outputPath); Console.WriteLine("Created report directory at {0}", outputPath); } catch (Exception ex) { Console.WriteLine("Failed to create report directory location '{0}': {1}", outputPath, ex.Message); return; } } try { File.WriteAllText(reportPath, text.ToString()); Console.WriteLine("Saved report HTML to {0}", reportPath); } catch (Exception ex) { Console.WriteLine("Failed to write the result summary to the target location '{0}': {1}", reportPath, ex.Message); return; } try { resultDoc.Save(resultPath); Console.WriteLine("Saved report XML to {0}", resultPath); } catch (Exception ex) { Console.WriteLine("Failed to save the summary xml document to the target location '{0}': {1}", resultPath, ex.Message); return; } return; }