public ProjectTemplateImpl(XmlDocument doc, IReadOnlyFileSystem fileSystem)
        {
            var templateElement = doc.DocumentElement;

            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 = TemplateIconLoader.GetImage(config["Icon"].InnerText);
            }

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

                supportedTargetFrameworks = SD.ProjectService.TargetFrameworks.Where(fx => specifiedTargetFrameworks.Any(s => fx.IsBasedOn(s))).ToArray();
            }
            else
            {
                supportedTargetFrameworks = new TargetFramework[0];
            }

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

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

            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 <ProjectTemplateResult> action = ReadAction(el);
                    if (action != null)
                    {
                        openActions.Add(action);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public FileTemplateImpl(XmlDocument doc, IReadOnlyFileSystem fileSystem)
        {
            author = doc.DocumentElement.GetAttribute("author");

            XmlElement config = doc.DocumentElement["Config"];

            name         = config.GetAttribute("name");
            icon         = TemplateIconLoader.GetImage(config.GetAttribute("icon"));
            category     = config.GetAttribute("category");
            defaultName  = config.GetAttribute("defaultname");
            languagename = config.GetAttribute("language");

            if (config.HasAttribute("subcategory"))
            {
                subcategory = config.GetAttribute("subcategory");
            }

            string newFileDialogVisibleAttr = config.GetAttribute("newfiledialogvisible");

            if (newFileDialogVisibleAttr != null && newFileDialogVisibleAttr.Length != 0)
            {
                if (newFileDialogVisibleAttr.Equals("false", StringComparison.OrdinalIgnoreCase))
                {
                    newFileDialogVisible = false;
                }
            }

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

            if (config["Wizard"] != null)
            {
                wizardpath = config["Wizard"].Attributes["path"].InnerText;
            }

            if (doc.DocumentElement["Properties"] != null)
            {
                XmlNodeList propertyList = doc.DocumentElement["Properties"].SelectNodes("Property");
                foreach (XmlElement propertyElement in propertyList)
                {
                    properties.Add(new TemplateProperty(propertyElement));
                }
            }

            if (doc.DocumentElement["Types"] != null)
            {
                XmlNodeList typeList = doc.DocumentElement["Types"].SelectNodes("Type");
                foreach (XmlElement typeElement in typeList)
                {
                    customTypes.Add(new TemplateType(typeElement));
                }
            }

            if (doc.DocumentElement["References"] != null)
            {
                XmlNodeList references = doc.DocumentElement["References"].SelectNodes("Reference");
                foreach (XmlElement reference in references)
                {
                    if (!reference.HasAttribute("include"))
                    {
                        throw new InvalidDataException("Reference without 'include' attribute!");
                    }
                    ReferenceProjectItem item = new ReferenceProjectItem(null, reference.GetAttribute("include"));
                    item.SetMetadata("HintPath", reference.GetAttribute("hintPath"));
                    var requiredTargetFramework = reference.GetElementsByTagName("RequiredTargetFramework").OfType <XmlElement>().FirstOrDefault();
                    if (requiredTargetFramework != null)
                    {
                        item.SetMetadata("RequiredTargetFramework", requiredTargetFramework.Value);
                    }
                    requiredAssemblyReferences.Add(item);
                }
            }

            if (doc.DocumentElement["CreateActions"] != null)
            {
                foreach (XmlElement el in doc.DocumentElement["CreateActions"])
                {
                    Action <FileTemplateResult> action = ReadAction(el);
                    if (action != null)
                    {
                        createActions += action;
                    }
                }
            }

            if (doc.DocumentElement["Actions"] != null)
            {
                foreach (XmlElement el in doc.DocumentElement["Actions"])
                {
                    Action <FileTemplateResult> action = ReadAction(el);
                    if (action != null)
                    {
                        openActions += action;
                    }
                }
            }

            fileoptions = doc.DocumentElement["AdditionalOptions"];

            // load the files
            XmlNodeList nodes = doc.DocumentElement["Files"].ChildNodes;

            foreach (XmlNode filenode in nodes)
            {
                if (filenode is XmlElement)
                {
                    this.files.Add(new FileDescriptionTemplate((XmlElement)filenode, fileSystem));
                }
            }
        }