Esempio n. 1
0
        static Action <FileTemplateResult> ReadAction(XmlElement el)
        {
            switch (el.Name)
            {
            case "RunCommand":
                if (el.HasAttribute("path"))
                {
                    try {
                        ICommand command = (ICommand)SD.AddInTree.BuildItem(el.GetAttribute("path"), null);
                        return(command.Execute);
                    } catch (TreePathNotFoundException ex) {
                        MessageService.ShowWarning(ex.Message + " - in " + el.OwnerDocument.DocumentElement.GetAttribute("fileName"));
                        return(null);
                    }
                }
                else
                {
                    ProjectTemplateImpl.WarnAttributeMissing(el, "path");
                    return(null);
                }

            default:
                ProjectTemplateImpl.WarnObsoleteNode(el, "Unknown action element is ignored");
                return(null);
            }
        }
Esempio n. 2
0
        void LoadElement(XmlElement node, IReadOnlyFileSystem fileSystem)
        {
            switch (node.Name)
            {
            case "Options":
                ProjectTemplateImpl.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, fileSystem);
                break;

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

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

            case "Include":
                TemplateLoadException.AssertAttributeExists(node, "src");
                FileName includeFileName = FileName.Create(node.GetAttribute("src"));
                try {
                    XmlDocument doc = new XmlDocument();
                    using (var stream = fileSystem.OpenRead(includeFileName)) {
                        doc.Load(stream);
                    }
                    doc.DocumentElement.SetAttribute("fileName", includeFileName);
                    var fileSystemForInclude = new ReadOnlyChrootFileSystem(fileSystem, includeFileName.GetParentDirectory());
                    if (doc.DocumentElement.Name == "Include")
                    {
                        LoadElementChildren(doc.DocumentElement, fileSystemForInclude);
                    }
                    else
                    {
                        LoadElement(doc.DocumentElement, fileSystemForInclude);
                    }
                } catch (XmlException ex) {
                    throw new TemplateLoadException("Error loading include file " + includeFileName, ex);
                }
                break;

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