Exemplo n.º 1
0
        void LoadFromXml(XmlElement templateElement, string xmlFileName)
        {
            // required for warning messages for unknown elements
            templateElement.SetAttribute("fileName", xmlFileName);

            originator   = templateElement.GetAttribute("originator");
            created      = templateElement.GetAttribute("created");
            lastmodified = templateElement.GetAttribute("lastModified");

            string newProjectDialogVisibleAttr = templateElement.GetAttribute("newprojectdialogvisible");

            if (string.Equals(newProjectDialogVisibleAttr, "false", StringComparison.OrdinalIgnoreCase))
            {
                newProjectDialogVisible = false;
            }

            XmlElement config = templateElement["TemplateConfiguration"];

            name     = config["Name"].InnerText;
            category = config["Category"].InnerText;

            if (config["LanguageName"] != null)
            {
                languagename = config["LanguageName"].InnerText;
                WarnObsoleteNode(config["LanguageName"], "use language attribute on the project node instead");
            }

            if (config["Subcategory"] != null)
            {
                subcategory = config["Subcategory"].InnerText;
            }

            if (config["Description"] != null)
            {
                description = config["Description"].InnerText;
            }

            if (config["Icon"] != null)
            {
                icon = config["Icon"].InnerText;
            }

            if (config["SupportedTargetFrameworks"] != null)
            {
                supportedTargetFrameworks =
                    config["SupportedTargetFrameworks"].InnerText.Split(';')
                    .Select <string, TargetFramework>(TargetFramework.GetByName).ToArray();
            }

            string hintPath = Path.GetDirectoryName(xmlFileName);

            if (templateElement["Solution"] != null)
            {
                solutionDescriptor = SolutionDescriptor.CreateSolutionDescriptor(templateElement["Solution"], hintPath);
            }
            else if (templateElement["Combine"] != null)
            {
                solutionDescriptor = SolutionDescriptor.CreateSolutionDescriptor(templateElement["Combine"], hintPath);
                WarnObsoleteNode(templateElement["Combine"], "Use <Solution> instead!");
            }

            if (templateElement["Project"] != null)
            {
                projectDescriptor = new ProjectDescriptor(templateElement["Project"], hintPath);
            }

            if (solutionDescriptor == null && projectDescriptor == null ||
                solutionDescriptor != null && projectDescriptor != null)
            {
                throw new TemplateLoadException("Template must contain either Project or Solution node!");
            }

            // Read Actions;
            if (templateElement["Actions"] != null)
            {
                foreach (XmlElement el in templateElement["Actions"])
                {
                    Action <ProjectCreateInformation> action = ReadAction(el);
                    if (action != null)
                    {
                        openActions.Add(action);
                    }
                }
            }
        }