Пример #1
0
        static Action <FileTemplateOptions> ReadAction(XmlElement el)
        {
            switch (el.Name)
            {
            case "RunCommand":
                if (el.HasAttribute("path"))
                {
                    try {
                        ICommand command = (ICommand)AddInTree.BuildItem(el.GetAttribute("path"), null);
                        return(fileCreateInformation => {
                            command.Owner = fileCreateInformation;
                            command.Run();
                        });
                    } catch (TreePathNotFoundException ex) {
                        MessageService.ShowWarning(ex.Message + " - in " + el.OwnerDocument.DocumentElement.GetAttribute("fileName"));
                        return(null);
                    }
                }
                else
                {
                    ProjectTemplate.WarnAttributeMissing(el, "path");
                    return(null);
                }

            default:
                ProjectTemplate.WarnObsoleteNode(el, "Unknown action element is ignored");
                return(null);
            }
        }
Пример #2
0
        void LoadElement(XmlElement node, string hintPath)
        {
            switch (node.Name)
            {
            case "Options":
                ProjectTemplate.WarnObsoleteNode(node, "Options are no longer supported, use properties instead.");
                break;

            case "CreateActions":
                LoadCreateActions(node);
                break;

            case "PreCreateActions":
                LoadPreCreateActions(node);
                break;

            case "ProjectItems":
                LoadProjectItems(node);
                break;

            case "Files":
                LoadFiles(node, hintPath);
                break;

            case "Imports":
                LoadImports(node);
                break;

            case "PropertyGroup":
                LoadPropertyGroup(node);
                break;

            case "Include":
                TemplateLoadException.AssertAttributeExists(node, "src");
                string includeFileName = Path.Combine(hintPath, node.GetAttribute("src"));
                try {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(includeFileName);
                    doc.DocumentElement.SetAttribute("fileName", includeFileName);
                    if (doc.DocumentElement.Name == "Include")
                    {
                        LoadElementChildren(doc.DocumentElement, Path.GetDirectoryName(includeFileName));
                    }
                    else
                    {
                        LoadElement(doc.DocumentElement, Path.GetDirectoryName(includeFileName));
                    }
                } catch (XmlException ex) {
                    throw new TemplateLoadException("Error loading include file " + includeFileName, ex);
                }
                break;

            default:
                throw new TemplateLoadException("Unknown node in <Project>: " + node.Name);
            }
        }