public void SetUp() { // ARRANGE var assemblyPath = typeof(TestManualElementsCommand).Assembly.Location; var cmdletXmlHelpPath = Path.ChangeExtension(assemblyPath, ".dll-Help.xml"); if (File.Exists(cmdletXmlHelpPath)) { File.Delete(cmdletXmlHelpPath); } // ACT var options = new Options(false, assemblyPath); var engine = new Engine(); engine.GenerateHelp(options); // ASSERT Assert.That(File.Exists(cmdletXmlHelpPath)); using (var stream = File.OpenRead(cmdletXmlHelpPath)) { var document = XDocument.Load(stream); rootElement = document.Root; } testManualElementsCommandElement = rootElement.XPathSelectElement("command:command[command:details/command:name/text() = 'Test-ManualElements']", resolver); testMamlElementsCommandElement = rootElement.XPathSelectElement("command:command[command:details/command:name/text() = 'Test-MamlElements']", resolver); testReferencesCommandElement = rootElement.XPathSelectElement("command:command[command:details/command:name/text() = 'Test-References']", resolver); testInputTypesCommandElement = rootElement.XPathSelectElement("command:command[command:details/command:name/text() = 'Test-InputTypes']", resolver); }
public static AssemblyDoc Parse(XElement doc) { return new AssemblyDoc { Name = doc.XPathSelectElement("assembly/name").Value, Types = ParseMembers(doc.XPathSelectElement("members")) }; }
public static PersonalConfiguration FromXml(XElement root) { lock (m_syncRoot) { string name = root.XPathSelectElement("./configuration/personalConfiguration/name").Value; string address = root.XPathSelectElement("./configuration/personalConfiguration/address").Value; return new PersonalConfiguration(name, address); } }
public static DirectoriesConfiguration FromXml(XElement root) { lock (m_syncRoot) { XElement xElement = null; xElement = root.XPathSelectElement("./configuration/directoriesConfiguration/defaultTouchDirectory"); string defaultTouchDirectory = xElement.Value; xElement = root.XPathSelectElement("./configuration/directoriesConfiguration/lastTouchDirectory"); string lastTouchDirectory = xElement.Value; return new DirectoriesConfiguration(defaultTouchDirectory, lastTouchDirectory); } }
public static ExceptionRecord FromXml(XElement exceptionData) { if (exceptionData == null) return null; return new ExceptionRecord { Type = exceptionData.XPathSelectElement("type[1]").Value, Message = exceptionData.XPathSelectElement("message[1]").Value, Stacktrace = exceptionData.XPathSelectElement("stacktrace[1]").Value .Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList(), InnerEception = !string.IsNullOrEmpty(exceptionData.XPathSelectElement("innerexception[1]").Value) ? FromXml(exceptionData.XPathSelectElement("innerexception[1]").Elements().First()) : null }; }
public bool ParagraphIsStageDirection (XElement paragraph) { var next = paragraph.XPathSelectElement ("key[text()='speaker']").NextNode as XElement; var body = next.Value; return body == "STAGE DIRECTION"; }
private void InitialiseMemberBank() { string strProcessCode = string.Empty; string strProcessText = string.Empty; svcPayMember.MemberBank[] ArrMB = null; using (svcPayMember.MemberClient svcInstance = new svcPayMember.MemberClient()) { ArrMB = svcInstance.getBankAccounts(Convert.ToInt64(strOperatorId), strCurrencyCode, strCountryCode, out strProcessCode, out strProcessText); } drpBank.DataSource = ArrMB; if (xeResources.XPathSelectElement("BankNameNative/" + strSelectedLanguage.ToUpper() + "_" + strCurrencyCode.ToUpper()) != null) { drpBank.DataTextField = "bankNameNative"; } else { drpBank.DataTextField = "bankName"; } drpBank.DataValueField = "bankCode"; //drpBank.DataTextField = "bankNameNative"; drpBank.DataBind(); }
public static GeneralConfiguration FromXml(XElement root) { lock (m_syncRoot) { XElement xElement = root.XPathSelectElement("./configuration/generalConfiguration/useRecursionByDefault"); bool useRecursionByDefault = Convert.ToBoolean(xElement.Attribute("useRecursionByDefault").Value); return new GeneralConfiguration(useRecursionByDefault); } }
public static bool DoesElementExist(XElement xElement, string xPathStatement) { bool result = false; if (xElement.XPathSelectElement(xPathStatement) != null) { result = true; } return result; }
public static bool DoesElementHaveValue(XElement xElement, string xPathStatement) { bool result = false; if (string.IsNullOrEmpty(xElement.XPathSelectElement(xPathStatement).Value) == false) { result = true; } return result; }
public CardViewModel(XElement e) { Title = (string)e.XPathSelectElement("title"); IssueKey = (string)e.XPathSelectElement("key"); ProjectName = (string)e.XPathSelectElement("project"); Assignee = (string)e.XPathSelectElement("assignee"); Summary = (string)e.XPathSelectElement("summary"); OriginalEstimate = (string)e.XPathSelectElement("timeoriginalestimate"); Status = (string)e.XPathSelectElement("status"); ProjectKey = (string)e.XPathSelectElement("project").Attribute("key"); }
private ErrorInfo ParseErrorInfo(XElement errorInfoXmlElement) { XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); xmlNamespaceManager.AddNamespace("prefix", ns.NamespaceName); errorInfoXmlElement = errorInfoXmlElement.Element(ns + "Output"); XElement messageElement = errorInfoXmlElement.XPathSelectElement("prefix:ErrorInfo/prefix:Message", xmlNamespaceManager); string message = (messageElement != null) ? messageElement.Value : null; XElement stackTraceElement = errorInfoXmlElement.XPathSelectElement("prefix:ErrorInfo/prefix:StackTrace", xmlNamespaceManager); string stackTrace = (stackTraceElement != null) ? stackTraceElement.Value : null; XElement stdOutElement = errorInfoXmlElement.XPathSelectElement("prefix:StdOut", xmlNamespaceManager); string stdOut = (stdOutElement != null) ? stdOutElement.Value : null; return new ErrorInfo(message, stackTrace, stdOut); }
public static bool GetBooleanValue(XElement xElement, string xPathStatement, bool defaultValue) { bool result = defaultValue; if (DoesElementExist(xElement, xPathStatement) == true) { if (DoesElementHaveValue(xElement, xPathStatement) == true) { result = Convert.ToBoolean(xElement.XPathSelectElement(xPathStatement).Value); } } return result; }
public static int GetIntValue(XElement xElement, string xPathStatement, int defaultValue) { int result = defaultValue; if (DoesElementExist(xElement, xPathStatement) == true) { if (DoesElementHaveValue(xElement, xPathStatement) == true) { result = Convert.ToInt32(xElement.XPathSelectElement(xPathStatement).Value); } } return result; }
public static void SetValue(XElement xElement, string xPathStatement, string elementValue) { if (DoesElementExist(xElement, xPathStatement) == false) { string[] slashSplit = xPathStatement.Split('/'); XElement parentElement = xElement.XPathSelectElement('/' + slashSplit[1]); AddElement(parentElement, slashSplit[2]); } XElement element = xElement.XPathSelectElement(xPathStatement); element.Value = elementValue; }
public static string GetStringValue(XElement xElement, string xPathStatement, string defaultValue) { string result = defaultValue; if (DoesElementExist(xElement, xPathStatement) == true) { if (DoesElementHaveValue(xElement, xPathStatement) == true) { result = xElement.XPathSelectElement(xPathStatement).Value.ToString(); } } return result; }
protected internal IEnumerable<object> BuildXPaths(XElement item, IEnumerable<AbstractSelect> selects) { foreach (var select in selects) if (select is AttributeSelect) { var attributeSelect = select as AttributeSelect; yield return ( ( item.XPathSelectElement(attributeSelect.Path) ?? new XElement("null", "(null)") ).Attribute(attributeSelect.Attribute) ?? new XAttribute("null", "(null)") ).Value; } else yield return ( item.XPathSelectElement(select.Path) ?? new XElement("null", "(null)") ).Value; }
private void CreateControlFlowFromComment( XElement comment ) { var row = comment.XPathSelectElement( "./ancestor::table:table-row", Manager ); var commentValue = comment.Value.Replace( "U+10FFFD", "@" ); var beforeNode = new XText( commentValue + "{" ); var afterNode = new XText( "}" ); row.AddBeforeSelf( beforeNode ); row.AddAfterSelf( afterNode ); comment.Remove(); }
Interaction TransformInteraction(XElement element) { return new Interaction { Request = new Request { Verb = element.XPathSelectElement("request/verb").Value, Path = element.XPathSelectElement("request/path").Value, Body = element.XPathSelectElement("request/body").Value, Headers = MapHeaders(element.XPathSelectElement("request/headers")) }, Response = new Response { Version = element.XPathSelectElement("response/version").Value, Status = MapStatus(element.XPathSelectElement("response/status")), Body = element.XPathSelectElement("response/body").Value, Headers = MapHeaders(element.XPathSelectElement("response/headers")) } }; }
public static IDictionary<string, NamespaceComments> Parse(XElement doc) { var res = doc .XPathSelectElement("members") .XPathSelectElements("member[starts-with(@name,\"N:\")]") .ToArray(); return res .Select(_ => new NamespaceComments { NamespaceName = _.Attribute("name").Value.Substring(2), Comments = _ } ) .ToDictionary(_ => _.NamespaceName, _ => _); }
public XElement ToUDS(XElement physicalService) { string name = physicalService.Attribute("Name").Value; XElement x = new XElement("Service", new XAttribute("Name", name), new XAttribute("Enabled", "true")); XElement def = new XElement("Definition", new XAttribute("Type", "DBHelper")); x.Add(def); XElement handler = physicalService.XPathSelectElement("Property[@Name='Definition']/Service/ServiceDescription/Handler[@ExecType='Util.DBHelper']"); string resourceName = handler.Element("ResourceName").Value; XElement resource = handler.XPathSelectElement("Resources/Resource[@Name='" + resourceName + "']"); foreach (XElement e in resource.Elements()) def.Add(e); return x; }
public XElement ToUDS(System.Xml.Linq.XElement physicalService) { string name = physicalService.Attribute("Name").Value; XElement x = new XElement("Service", new XAttribute("Name", name), new XAttribute("Enabled", "true")); XElement def = new XElement("Definition", new XAttribute("Type", "DBHelper")); x.Add(def); XElement handler = physicalService.XPathSelectElement("Property[@Name='Definition']/Service/ServiceDescription/Handler"); foreach (XElement e in handler.Elements()) { def.Add(e); } return(x); }
private void CreateControlFlowSection( XElement script ) { //TODO: Test this method var parentSection = script.XPathSelectElement( "./ancestor::text:section", Manager ); // TODO: If ParentSection is null, throw specific exception var scriptValue = script.Value.Replace( "U+10FFFD", "@" ); var beforeNode = new XText( scriptValue + "{" ); var afterNode = new XText( "}" ); parentSection.AddBeforeSelf( beforeNode ); parentSection.AddAfterSelf( afterNode ); script.Remove(); }
public virtual void CleanDefaultProperties(XElement xmlWebPart) { //Remove default properties XElement xmlProps = string.IsNullOrEmpty(this.XElementPropertiesPath) ? xmlWebPart : xmlWebPart.XPathSelectElement(this.XElementPropertiesPath); if (null != xmlProps) { var nodes = xmlProps.Nodes().ToList(); for (var i = nodes.Count() - 1; i >= 0; i--) { var xmlProp = nodes[i] as XElement; if ((null != xmlProp) && IsPropertyDefault(xmlProp)) { xmlProp.Remove(); } } } }
/// <summary> /// Update the content of the logging element. /// </summary> /// <param name="loggingElement"> /// The logging element being modified. /// </param> public static void UpdateLoggingElement(XElement loggingElement) { var rootElement = loggingElement.Element("root"); if (rootElement == null) { rootElement = new XElement("root", new XElement("level", new XAttribute("value", "DEBUG"))); loggingElement.Add(rootElement); } else { var levelElt = rootElement.Element("level"); if (levelElt == null) { rootElement.Add(new XElement("level", new XAttribute("value", "DEBUG"))); } else { levelElt.ReplaceAttributes(new XAttribute("value", "DEBUG")); } } var apprendaAppender = loggingElement.XPathSelectElement("//appender[@type='log4net.ApprendaBufferingAppender']"); if (apprendaAppender == null) { loggingElement.Add( new XElement( "appender", new XAttribute("name", "ApprendaAppender"), new XAttribute("type", "log4net.Apprenda.ApprendaAppender, log4net.Apprenda"))); rootElement.Add(new XElement("appender-ref", new XAttribute("ref", "ApprendaAppender"))); } else { var apprendaAppenderName = apprendaAppender.Attribute("name").Value; var appenderRef = rootElement.XPathSelectElement("//appender-ref[@name='" + apprendaAppenderName + "'"); if (appenderRef == null) { rootElement.Add(new XElement("appender-ref", new XAttribute("ref", apprendaAppenderName))); } } }
public static LinkedInPostSummary Parse(XElement xPost) { // Get the timestamp and divide by 1000 (milliseconds to seconds) double timestamp = xPost.GetElementValueOrDefault<long>("creation-timestamp") / 1000.00; // Get the type of the post (post or news) XElement xTypeCode = xPost.XPathSelectElement("type/code"); return new LinkedInPostSummary { Id = xPost.GetElementValueOrDefault<string>("id"), Type = xTypeCode == null ? null : xTypeCode.Value, Url = xPost.GetElementValueOrDefault<string>("site-group-post-url"), Created = SocialUtils.GetDateTimeFromUnixTime(timestamp), Title = xPost.GetElementValueOrDefault<string>("title"), Summary = xPost.GetElementValueOrDefault<string>("summary"), Creator = LinkedInPersonSummary.Parse(xPost.Element("creator")), Likes = LinkedInLikesSummary.Parse(xPost.Element("likes")) }; }
public static XElement getDevice(XElement probe, String deviceId, StreamWriter writer, IData data) { XElement devices = probe.XPathSelectElement("//Devices"); if (devices != null) { XElement device = devices.XPathSelectElement("//Device[@name='" + deviceId + "']"); if (device == null) { Error.createError(data, Error.NO_DEVICE).Save(writer); return null; } else return device; } else //Devices not found from Devices.xml load at initialization { Error.createError(data, Error.INTERNAL_ERROR).Save(writer); return null; } }
public HttpErrorsRedirectType ParseHttpErrorsRedirectType(XElement httpErrors) { var errorElementXPath = string.Format("error[@statusCode='{0}']", _statusCode); var errorElement = httpErrors.XPathSelectElement(errorElementXPath); if (errorElement == null) { return EnumHelpers.GetDefaultEnumValue<HttpErrorsRedirectType>(); } var pathAttribute = errorElement.Attribute("path"); if (pathAttribute == null) { throw new Exception(string.Format("Failed to match redirect for status code {0}.", _statusCode)); } var path = pathAttribute.Value; if (string.Equals(path, _htmPage, StringComparison.OrdinalIgnoreCase)) { return HttpErrorsRedirectType.StaticErrorPage; } if (string.Equals(path, _mvcPage, StringComparison.OrdinalIgnoreCase)) { return HttpErrorsRedirectType.MvcErrorPage; } if (string.Equals(path, _aspxPage, StringComparison.OrdinalIgnoreCase)) { return HttpErrorsRedirectType.AspxErrorPage; } throw new Exception(string.Format("Failed to match redirect {0} for status code {1}.", path, _statusCode)); }
private void BuildHierarchy(IAssetResolver assetResolver, XElement parentNode, LinkedListNode<AssetIdentifier> hierarchy, AssetIdentifier asset, HashSet<AssetIdentifier> references, HashSet<AssetIdentifier> emittedAssets, int phase) { if (hierarchy == null) return; IAssemblyLoader assemblyLoader = new ReflectionOnlyAssemblyLoader(this._cache, this._assemblyPaths.Select(Path.GetDirectoryName)); AssetIdentifier aid = hierarchy.Value; IProcessingContext pctx = new ProcessingContext(this._cache, this._filters, assemblyLoader, assetResolver, parentNode, references, phase); XElement newElement; // add asset to list of generated assets emittedAssets.Add(aid); // dispatch depending on type switch (aid.Type) { case AssetType.Namespace: newElement = parentNode.XPathSelectElement(string.Format("namespace[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateNamespaceElement(pctx, aid); break; case AssetType.Type: newElement = parentNode.XPathSelectElement(string.Format("*[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateTypeElement(pctx, aid); break; case AssetType.Method: newElement = parentNode.XPathSelectElement(string.Format("*[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateMethodElement(pctx, aid); break; case AssetType.Field: newElement = parentNode.XPathSelectElement(string.Format("field[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateFieldElement(pctx, aid); break; case AssetType.Event: newElement = parentNode.XPathSelectElement(string.Format("event[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateEventElement(pctx, aid); break; case AssetType.Property: newElement = parentNode.XPathSelectElement(string.Format("property[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GeneratePropertyElement(pctx, aid); break; case AssetType.Assembly: newElement = parentNode.XPathSelectElement(string.Format("assembly[@assetId = '{0}']", aid)); if (newElement == null) newElement = this.GenerateAssemblyElement(pctx, aid); break; default: throw new ArgumentOutOfRangeException(); } this.BuildHierarchy(assetResolver, newElement, hierarchy.Next, asset, references, emittedAssets, phase); }
internal static XElement GetClipElement(XElement drawingGroupElement, out Rect rect) { rect = default(Rect); if (drawingGroupElement == null) return null; //<DrawingGroup x:Key="cloud_3_icon_DrawingGroup"> // <DrawingGroup> // <DrawingGroup.ClipGeometry> // <RectangleGeometry Rect="0,0,512,512" /> // </DrawingGroup.ClipGeometry> var clipElement = drawingGroupElement.XPathSelectElement("//defns:DrawingGroup.ClipGeometry", _nsManager); if (clipElement != null) { var rectangleElement = clipElement.Element(nsDef + "RectangleGeometry"); if (rectangleElement != null) { var rectAttr = rectangleElement.Attribute("Rect"); if (rectAttr != null) { rect = Rect.Parse(rectAttr.Value); return clipElement; } } } return null; }
public static string TransformDocumentationToHTML(XElement element, string rootNodeName, AssemblyWrapper assemblyWrapper, FrameworkVersion version) { if (element == null) return string.Empty; var rootNode = element.XPathSelectElement(rootNodeName); if (rootNode == null) return string.Empty; //var crossRefTags = new[] { "see", "seealso" }; //foreach (var crossRefTag in crossRefTags) //{ // var crossRefs = rootNode.Descendants(crossRefTag); // if (crossRefs.Any()) // { // foreach (var crossRef in crossRefs) // { // var typeName = BaseWriter.GetCrossReferenceTypeName(crossRef); // string target; // var url = BaseWriter.CrossReferenceTypeToUrl(assemblyWrapper, typeName, version, out target); // var href = url != null ? string.Format("<a href=\"{0}\" {2}>{1}</a>", url, typeName, target) : typeName; // crossRef.ReplaceWith(href); // } // } //} var reader = rootNode.CreateReader(); reader.MoveToContent(); var innerXml = reader.ReadInnerXml(); var innerText = innerXml; innerText = innerText.Replace("<summary>", "<p>"); innerText = innerText.Replace("</summary>", "</p>"); innerText = innerText.Replace("<para>", "<p>"); innerText = innerText.Replace("</para>", "</p>"); //innerText = innerText.Replace("<code", "<pre class=\"code-sample\">"); //innerText = innerText.Replace("</code>", "</pre>"); // scan for <see> and <seealso> cross-reference tags and replace with <a> links with the // content - which // can be a cref indication to a typename, or a href. var scanIndex = innerText.IndexOf(crossReferenceOpeningTagText, StringComparison.Ordinal); while (scanIndex >= 0) { var attrStart = innerText.IndexOf(innerCrefAttributeText, scanIndex, StringComparison.Ordinal); if (attrStart >= 0) { int crossRefTagEndIndex; var cref = ExtractCrefAttributeContent(innerText, attrStart, out crossRefTagEndIndex); var replacement = BaseWriter.CreateCrossReferenceTagReplacement(assemblyWrapper, cref, version); var oldCrossRefTag = innerText.Substring(scanIndex, crossRefTagEndIndex - scanIndex); innerText = innerText.Replace(oldCrossRefTag, replacement); scanIndex += replacement.Length; } else { attrStart = innerText.IndexOf(innerHrefAttributeText, scanIndex, StringComparison.Ordinal); if (attrStart >= 0) { int crossRefTagEndIndex; var url = ExtractHrefAttributeContent(innerText, attrStart, out crossRefTagEndIndex); var replacement = string.Format("<a href=\"{0}\">{0}</a>", url); var oldCrossRefTag = innerText.Substring(scanIndex, crossRefTagEndIndex - scanIndex); innerText = innerText.Replace(oldCrossRefTag, replacement); scanIndex += replacement.Length; } else scanIndex++; } scanIndex = innerText.IndexOf(crossReferenceOpeningTagText, scanIndex, StringComparison.Ordinal); } return innerText; }
public static string FindReturnDocumentation(XElement ndoc) { if (ndoc == null) return string.Empty; var node = ndoc.XPathSelectElement("returns"); if (node == null) return string.Empty; return node.Value; }