Пример #1
0
        public static Commands CreateFromXML(XmlElement commandsElement)
        {
            if (commandsElement.Name != "commands")
            {
                throw new ArgumentException("argument must be a commands element", "commandsElement");
            }

            IDictionary <string, string> deviceMap = new SortedDictionary <string, string>();
            XmlElement deviceMapElement            = commandsElement["deviceMap"];

            if (deviceMapElement != null)
            {
                foreach (XmlNode node in deviceMapElement)
                {
                    if (node is XmlElement entryElement)
                    {
                        deviceMap[entryElement.Attributes["model"].Value] = entryElement.Attributes["name"].Value;
                    }
                }
            }

            XmlElement startActivitiesNode = commandsElement["startupActivities"];

            string[] startActivities = null;
            if (startActivitiesNode != null)
            {
                startActivities = TextParser.ParseActivities(startActivitiesNode.InnerText);
            }

            XmlElement exitActivitiesNode = commandsElement["exitActivities"];

            string[] exitActivities = null;
            if (exitActivitiesNode != null)
            {
                exitActivities = TextParser.ParseActivities(exitActivitiesNode.InnerText);
            }

            XmlAttribute compatibleProductModelsAttribute = commandsElement.Attributes["compatibleProductModels"];

            string[] compatibleProductModels = null;
            if (compatibleProductModelsAttribute != null)
            {
                compatibleProductModels = TextParser.ParseProductModels(compatibleProductModelsAttribute.Value);
            }

            return(new Commands(deviceMap, startActivities, exitActivities, Menu.CreateFromXML(commandsElement["menu"], null), compatibleProductModels));
        }
Пример #2
0
        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;
        }