Пример #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 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));
        }