Пример #1
0
        static void SetupPlugIn(XmlReader reader, PlugIn plugIn)
        {
            plugIn.Properties = Properties.ReadFromAttributes(reader);

            plugIn.Runtimes = new List <Runtime>();

            plugIn.Paths = new Dictionary <string, ExtensionPath>();

            plugIn.Manifest = new PlugInManifest();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case PlugInConst.Runtime:
                        Runtime.ReadRuntime(reader, plugIn);
                        break;

                    case PlugInConst.Path:
                        ExtensionPath.ReadPath(reader, plugIn);
                        break;

                    case PlugInConst.Manifest:
                        plugIn.Manifest.ReadManifest(reader, plugIn);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Пример #2
0
        private static Runtime Read(PlugIn plugIn, XmlReader reader)
        {
            if (reader.AttributeCount != 1)
            {
                throw new Exception(PlugInConst.RuntimeImport + " node requires only one attribute.");
            }

            Runtime runtime = new Runtime(reader.GetAttribute(0), plugIn.PlugInDir);

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        string     nodeName   = reader.LocalName;
                        Properties properties = Properties.ReadFromAttributes(reader);

                        switch (nodeName)
                        {
                        case PlugInConst.RuntimeImportDoozer:
                            if (reader.HasAttributes == false)
                            {
                                throw new Exception("Doozer node must be have attributes!");
                            }
                            runtime.DefinedDoozers.Add(new LazyDoozer(plugIn, properties));
                            break;

                        default:
                            throw new Exception("Unknown node in Import section:" + nodeName);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.LocalName == PlugInConst.RuntimeImport)
                        {
                            runtime.DefinedDoozers = (runtime.DefinedDoozers as List <LazyDoozer>).AsReadOnly();
                            return(runtime);
                        }
                        break;
                    }
                }
            }

            runtime.DefinedDoozers = (runtime.DefinedDoozers as List <LazyDoozer>).AsReadOnly();

            return(runtime);
        }
Пример #3
0
        public void ReadManifest(XmlReader reader, PlugIn plugIn)
        {
            if (reader.AttributeCount != 0)
            {
                throw new Exception(PlugInConst.Manifest + " node cannot have attributes.");
            }
            if (reader.IsEmptyElement)
            {
                throw new Exception(PlugInConst.Manifest + " node cannot be empty.");
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    string     nodeName   = reader.LocalName;
                    Properties properties = Properties.ReadFromAttributes(reader);
                    switch (nodeName)
                    {
                    case PlugInConst.ManifestIdentity:
                        AddIdentity(properties["name"], properties["version"], plugIn.PlugInDir);
                        break;

                    case PlugInConst.ManifestDependency:
                        Dependencies.Add(PlugInReference.Create(properties, plugIn.PlugInDir));
                        break;

                    case PlugInConst.ManifestConflict:
                        Conflicts.Add(PlugInReference.Create(properties, plugIn.PlugInDir));
                        break;

                    default:
                        throw new Exception("Unknown node in " + PlugInConst.Manifest + " section:" + nodeName + " plugIn:" + plugIn.PlugInFile);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.LocalName == PlugInConst.Manifest)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Пример #4
0
        public static void ReadPath(System.Xml.XmlReader reader, Core.PlugIn plugIn)
        {
            if (reader.AttributeCount != 1)
            {
                throw new Exception(PlugInConst.Path + " node requires only one attribute.");
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            string name = reader.GetAttribute(0);

            ExtensionPath path = new ExtensionPath(name, plugIn);

            plugIn.Paths.Add(path.Name, path);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element:
                    string elementName = reader.LocalName;

                    Codon newCodon = new Codon(path.PlugIn, elementName, Properties.ReadFromAttributes(reader));

                    path.Codons.Add(newCodon);

                    if (!reader.IsEmptyElement)
                    {
                        ReadPath(reader, plugIn);
                    }

                    break;

                case System.Xml.XmlNodeType.EndElement:
                    if (reader.LocalName == PlugInConst.Path)
                    {
                        return;
                    }
                    break;

                default:
                    break;
                }
            }
        }