public static Menu CreateFromXML(XmlElement menuElement, Menu parentMenu) { if (menuElement.Name != "menu") { throw new ArgumentException("argument must be a menu element", "menuElement"); } MenuItemBaseProperties baseProperties = new MenuItemBaseProperties(); baseProperties.FillFromXml(menuElement, parentMenu); Menu menu = new Menu(baseProperties, TextParser.ParseNullableXmlBoolean(menuElement.Attributes["returnToMainMenu"])); List <MenuItem> menuItems = new List <MenuItem>(); foreach (XmlNode node in menuElement) { if (node is XmlElement element) { switch (element.Name) { case "menu": menuItems.Add(CreateFromXML(element, menu)); break; case "query": menuItems.Add(Query.CreateFromXML(element, menu)); break; case "task": menuItems.Add(Task.CreateFromXML(element, menu)); break; } } } menu.MenuItems = menuItems.ToArray(); return(menu); }
public virtual void FillFromXml(XmlElement element, Menu parentMenu) { ParentMenu = parentMenu; XmlAttribute compatibleProductModelsAttribute = element.Attributes["compatibleProductModels"]; string[] compatibleProductModels = null; if (compatibleProductModelsAttribute != null) { compatibleProductModels = TextParser.ParseProductModels(compatibleProductModelsAttribute.Value); } CompatibleProductModels = compatibleProductModels; XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable()); namespaceManager.AddNamespace("cf", "http://schema.vanbergen.local/Tools/CherryUpdater/CommandFile"); List <Requirement> requirementList = new List <Requirement>(); XmlNodeList requireNodes = element.SelectNodes("child::cf:require", namespaceManager); foreach (XmlElement requireElement in requireNodes) { requirementList.Add(Requirement.CreateFromXML(requireElement)); } Requirements = requirementList.Count > 0 ? requirementList.ToArray() : null; XmlElement helpTextElement = element["helpText"]; string helpText = null; if (helpTextElement != null) { helpText = TextParser.ParseMultilineElementText(helpTextElement.InnerText.Trim()); } HelpText = helpText; XmlElement preMessageElement = element["preMessage"]; if (preMessageElement != null) { MessageBoxButtons?showButtons = null; XmlAttribute showButtonsAttribute = preMessageElement.Attributes["showButtons"]; if (showButtonsAttribute != null) { switch (showButtonsAttribute.Value) { case "ok": showButtons = MessageBoxButtons.OK; break; case "okCancel": showButtons = MessageBoxButtons.OKCancel; break; case "yesNo": showButtons = MessageBoxButtons.YesNo; break; } } MessageBoxIcon?messageTypeIcon = null; XmlAttribute messageTypeAttribute = preMessageElement.Attributes["messageType"]; if (messageTypeAttribute != null) { switch (messageTypeAttribute.Value) { case "neutral": messageTypeIcon = MessageBoxIcon.None; break; case "information": messageTypeIcon = MessageBoxIcon.Information; break; case "question": messageTypeIcon = MessageBoxIcon.Question; break; case "warning": messageTypeIcon = MessageBoxIcon.Warning; break; } } PreMessage = new DecoratedMessage(TextParser.ParseMultilineElementText(preMessageElement.InnerText.Trim()), preMessageElement.Attributes["caption"].Value, TextParser.ParseNullableXmlBoolean(preMessageElement.Attributes["showOnce"]), false, showButtons, messageTypeIcon); } Title = element.Attributes["title"].Value; }
public override void FillFromXml(XmlElement element) { base.FillFromXml(element); Message = TextParser.ParseMultilineElementText(element.InnerText); }
public static Query CreateFromXML(XmlElement queryElement, Menu parentMenu) { if (queryElement.Name != "query") { throw new ArgumentException("argument must be a query element", "queryElement"); } MenuItemBaseProperties baseProperties = new MenuItemBaseProperties(); baseProperties.FillFromXml(queryElement, parentMenu); List <IProcessor> processorList = new List <IProcessor>(); XmlElement processorsElement = queryElement["processors"]; if (processorsElement != null) { string processorElementName; foreach (XmlNode node in processorsElement) { if (node is XmlElement element) { processorElementName = element.Name; if (mProcessorParsers.ContainsKey(processorElementName)) { processorList.Add(mProcessorParsers[processorElementName].CreateFromXML(element)); } } } } return(new Query(baseProperties, queryElement.Attributes["command"].Value, processorList.ToArray(), TextParser.ParseNullableXmlBoolean(queryElement.Attributes["offerClipboardCopy"]))); }
public IProcessor CreateFromXML(XmlElement element) { if (element.Name != cElementName) { throw new ArgumentException(string.Format("argument must be a {0} element", cElementName), "element"); } XmlElement defaultTextElement = element["defaultText"]; TranslateProcessor processor = new TranslateProcessor(defaultTextElement != null ? TextParser.ParseMultilineElementText(defaultTextElement.InnerText) ?? "" : null); foreach (XmlNode node in element) { if (node is XmlElement childElement && childElement.Name == "item") { processor.Items[childElement.Attributes["from"].Value] = TextParser.ParseMultilineElementText(childElement.InnerText); } } return(processor); }
public static Task CreateFromXML(XmlElement taskElement, Menu parentMenu) { if (taskElement.Name != "task") { throw new ArgumentException("argument must be a task element", "taskElement"); } MenuItemBaseProperties baseProperties = new MenuItemBaseProperties(); baseProperties.FillFromXml(taskElement, parentMenu); DecoratedMessage postMessage = null; XmlElement postMessageElement = taskElement["postMessage"]; if (postMessageElement != null) { MessageBoxIcon?messageTypeIcon = null; XmlAttribute messageTypeAttribute = postMessageElement.Attributes["messageType"]; if (messageTypeAttribute != null) { switch (messageTypeAttribute.Value) { case "neutral": messageTypeIcon = MessageBoxIcon.None; break; case "information": messageTypeIcon = MessageBoxIcon.Information; break; case "warning": messageTypeIcon = MessageBoxIcon.Warning; break; } } postMessage = new DecoratedMessage(TextParser.ParseMultilineElementText(postMessageElement.InnerText.Trim()), postMessageElement.Attributes["caption"].Value, false, TextParser.ParseNullableXmlBoolean(postMessageElement.Attributes["showIfFailed"]), null, messageTypeIcon); } return(new Task(baseProperties, taskElement.Attributes["progressCaption"].Value, TextParser.ParseActivities(taskElement["activities"].InnerText), TextParser.ParseNullableXmlBoolean(taskElement.Attributes["continueOnError"]), postMessage)); }