Ejemplo n.º 1
0
		void DoSetUp(XmlReader reader, string endElement, Stack<ICondition> conditionStack)
		{
			List<Codon> innerCodons = new List<Codon>();
			while (reader.Read()) {
				switch (reader.NodeType) {
					case XmlNodeType.EndElement:
						if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition") {
							conditionStack.Pop();
						} else if (reader.LocalName == endElement) {
							if (innerCodons.Count > 0)
								this.codons.Add(innerCodons);
							return;
						}
						break;
					case XmlNodeType.Element:
						string elementName = reader.LocalName;
						if (elementName == "Condition") {
							conditionStack.Push(Condition.Read(reader));
						} else if (elementName == "ComplexCondition") {
							conditionStack.Push(Condition.ReadComplexCondition(reader));
						} else {
							Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
							innerCodons.Add(newCodon);
							if (!reader.IsEmptyElement) {
								ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id);
								subPath.DoSetUp(reader, elementName, conditionStack);
							}
						}
						break;
				}
			}
			if (innerCodons.Count > 0)
				this.codons.Add(innerCodons);
		}
Ejemplo n.º 2
0
        public static AddIn Load(IAddInTree addInTree, TextReader textReader, string hintPath = null, XmlNameTable nameTable = null)
        {
            if (nameTable == null)
            {
                nameTable = new NameTable();
            }
            try {
                AddIn addIn = new AddIn(addInTree);
                using (XmlTextReader reader = new XmlTextReader(textReader, nameTable)) {
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.LocalName)
                            {
                            case "AddIn":
                                addIn.properties = Properties.ReadFromAttributes(reader);
                                SetupAddIn(reader, addIn, hintPath);
                                break;

                            default:
                                throw new AddInLoadException("Unknown add-in file.");
                            }
                        }
                    }
                }
                return(addIn);
            } catch (XmlException ex) {
                throw new AddInLoadException(ex.Message, ex);
            }
        }
Ejemplo n.º 3
0
        public static AddIn Load(TextReader textReader, string hintPath)
        {
            AddIn addIn = new AddIn();

            using (XmlTextReader reader = new XmlTextReader(textReader))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.LocalName)
                        {
                        case "AddIn":
                            addIn.properties = Properties.ReadFromAttributes(reader);
                            SetupAddIn(reader, addIn, hintPath);
                            break;

                        default:
                            throw new AddInLoadException("Unknown add-in file.");
                        }
                    }
                }
            }
            return(addIn);
        }
Ejemplo n.º 4
0
        internal static Runtime Read(AddIn addIn, XmlReader reader, string hintPath, Stack <ICondition> conditionStack)
        {
            if (reader.AttributeCount != 1)
            {
                throw new AddInLoadException("Import node requires ONE attribute.");
            }
            Runtime runtime = new Runtime(reader.GetAttribute(0), hintPath);

            if (conditionStack.Count > 0)
            {
                runtime.conditions = conditionStack.ToArray();
            }
            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.EndElement:
                        if (reader.LocalName == "Import")
                        {
                            return(runtime);
                        }
                        break;

                    case XmlNodeType.Element:
                        string     nodeName   = reader.LocalName;
                        Properties properties = Properties.ReadFromAttributes(reader);
                        switch (nodeName)
                        {
                        case "Doozer":
                            if (!reader.IsEmptyElement)
                            {
                                throw new AddInLoadException("Doozer nodes must be empty!");
                            }
                            runtime.definedDoozers.Add(new LazyLoadDoozer(addIn, properties));
                            break;

                        case "ConditionEvaluator":
                            if (!reader.IsEmptyElement)
                            {
                                throw new AddInLoadException("ConditionEvaluator nodes must be empty!");
                            }
                            runtime.definedConditionEvaluators.Add(new LazyConditionEvaluator(addIn, properties));
                            break;

                        default:
                            throw new AddInLoadException("Unknown node in Import section:" + nodeName);
                        }
                        break;
                    }
                }
            }
            runtime.definedDoozers             = (runtime.definedDoozers as List <LazyLoadDoozer>).AsReadOnly();
            runtime.definedConditionEvaluators = (runtime.definedConditionEvaluators as List <LazyConditionEvaluator>).AsReadOnly();
            return(runtime);
        }
Ejemplo n.º 5
0
        public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
        {
            Stack <ICondition> stack = new Stack <ICondition>();

            while (reader.Read())
            {
                XmlNodeType nodeType = reader.NodeType;
                if (nodeType != XmlNodeType.Element)
                {
                    if (nodeType == XmlNodeType.EndElement)
                    {
                        if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                        {
                            stack.Pop();
                        }
                        else
                        {
                            if (reader.LocalName == endElement)
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    string localName = reader.LocalName;
                    if (localName == "Condition")
                    {
                        stack.Push(Condition.Read(reader));
                    }
                    else
                    {
                        if (localName == "ComplexCondition")
                        {
                            stack.Push(Condition.ReadComplexCondition(reader));
                        }
                        else
                        {
                            Codon codon = new Codon(extensionPath.AddIn, localName, Properties.ReadFromAttributes(reader), stack.ToArray());
                            extensionPath.codons.Add(codon);
                            if (!reader.IsEmptyElement)
                            {
                                ExtensionPath extensionPath2 = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + codon.Id);
                                ExtensionPath.SetUp(extensionPath2, reader, localName);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
        {
            Stack <ICondition> conditionStack = new Stack <ICondition>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                    {
                        conditionStack.Pop();
                    }
                    else if (reader.LocalName == endElement)
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    string elementName = reader.LocalName;
                    if (elementName == "Condition")
                    {
                        conditionStack.Push(Condition.Read(reader));
                    }
                    else if (elementName == "ComplexCondition")
                    {
                        conditionStack.Push(Condition.ReadComplexCondition(reader));
                    }
                    else
                    {
                        Codon newCodon = new Codon(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
                        extensionPath.codons.Add(newCodon);
                        if (!reader.IsEmptyElement)
                        {
                            ExtensionPath subPath = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + newCodon.Id);
                            //foreach (ICondition condition in extensionPath.conditionStack) {
                            //	subPath.conditionStack.Push(condition);
                            //}
                            SetUp(subPath, reader, elementName);
                            //foreach (ICondition condition in extensionPath.conditionStack) {
                            //	subPath.conditionStack.Pop();
                            //}
                        }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        internal static Runtime Read(AddIn addIn, XmlReader reader, string hintPath, Stack <ICondition> conditionStack)
        {
            int     arg_08_0 = reader.AttributeCount;
            Runtime runtime  = new Runtime(reader.GetAttribute(0), hintPath);

            if (conditionStack.Count > 0)
            {
                runtime.conditions = conditionStack.ToArray();
            }
            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    XmlNodeType nodeType = reader.NodeType;
                    if (nodeType != XmlNodeType.Element)
                    {
                        if (nodeType == XmlNodeType.EndElement && reader.LocalName == "Import")
                        {
                            return(runtime);
                        }
                    }
                    else
                    {
                        string     localName  = reader.LocalName;
                        Properties properties = Properties.ReadFromAttributes(reader);
                        string     a;
                        if ((a = localName) != null)
                        {
                            if (!(a == "Doozer"))
                            {
                                if (a == "ConditionEvaluator")
                                {
                                    bool arg_B3_0 = reader.IsEmptyElement;
                                    runtime.definedConditionEvaluators.Add(new LazyConditionEvaluator(addIn, properties));
                                }
                            }
                            else
                            {
                                bool arg_98_0 = reader.IsEmptyElement;
                                runtime.definedDoozers.Add(new LazyLoadDoozer(addIn, properties));
                            }
                        }
                    }
                }
            }
            runtime.definedDoozers             = (runtime.definedDoozers as System.Collections.Generic.List <LazyLoadDoozer>).AsReadOnly();
            runtime.definedConditionEvaluators = (runtime.definedConditionEvaluators as System.Collections.Generic.List <LazyConditionEvaluator>).AsReadOnly();
            return(runtime);
        }
Ejemplo n.º 8
0
        public void ReadManifestSection(XmlReader reader, string hintPath)
        {
            if (reader.AttributeCount != 0)
            {
                throw new AddInLoadException("Manifest node cannot have attributes.");
            }
            if (reader.IsEmptyElement)
            {
                throw new AddInLoadException("Manifest node cannot be empty.");
            }
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == "Manifest")
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    string     nodeName   = reader.LocalName;
                    Properties properties = Properties.ReadFromAttributes(reader);
                    switch (nodeName)
                    {
                    case "Identity":
                        AddIdentity(properties["name"], properties["version"], hintPath);
                        break;

                    case "Dependency":
                        dependencies.Add(AddInReference.Create(properties, hintPath));
                        break;

                    case "Conflict":
                        conflicts.Add(AddInReference.Create(properties, hintPath));
                        break;

                    default:
                        throw new AddInLoadException("Unknown node in Manifest section:" + nodeName);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 9
0
 public void ReadManifestSection(XmlReader reader, string hintPath)
 {
     if (reader.AttributeCount != 0)
     {
         throw new System.ArgumentException("Manifest node cannot have attributes.");
     }
     if (reader.IsEmptyElement)
     {
         throw new System.ArgumentException("Manifest node cannot be empty.");
     }
     while (reader.Read())
     {
         XmlNodeType nodeType = reader.NodeType;
         if (nodeType == XmlNodeType.Element)
         {
             string     localName  = reader.LocalName;
             Properties properties = Properties.ReadFromAttributes(reader);
             string     a;
             if ((a = localName) != null)
             {
                 if (a == "Identity")
                 {
                     this.AddIdentity(properties["name"], properties["version"], hintPath);
                     continue;
                 }
                 if (a == "Dependency")
                 {
                     this.dependencies.Add(AddInReference.Create(properties, hintPath));
                     continue;
                 }
                 if (a == "Conflict")
                 {
                     this.conflicts.Add(AddInReference.Create(properties, hintPath));
                     continue;
                 }
             }
             throw new System.ArgumentException("Unknown node in Manifest section:" + localName);
         }
         if (nodeType == XmlNodeType.EndElement && reader.LocalName == "Manifest")
         {
             return;
         }
     }
 }
Ejemplo n.º 10
0
        public static AddIn Load(System.IO.TextReader textReader, string hintPath)
        {
            AddIn addIn = new AddIn();

            using (XmlTextReader xmlTextReader = new XmlTextReader(textReader))
            {
                while (xmlTextReader.Read())
                {
                    if (xmlTextReader.IsStartElement())
                    {
                        string localName;
                        if ((localName = xmlTextReader.LocalName) == null || !(localName == "AddIn"))
                        {
                            throw new System.NotSupportedException("Unknown add-in file.");
                        }
                        addIn.properties = Properties.ReadFromAttributes(xmlTextReader);
                        AddIn.SetupAddIn(xmlTextReader, addIn, hintPath);
                    }
                }
            }
            return(addIn);
        }
Ejemplo n.º 11
0
        static void SetupAddIn(XmlReader reader, AddIn addIn, string hintPath)
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "StringResources":
                    case "BitmapResources":
                        if (reader.AttributeCount != 1)
                        {
                            throw new AddInLoadException("BitmapResources requires ONE attribute.");
                        }

                        string filename = StringParser.Parse(reader.GetAttribute("file"));

                        if (reader.LocalName == "BitmapResources")
                        {
                            addIn.BitmapResources.Add(filename);
                        }
                        else
                        {
                            addIn.StringResources.Add(filename);
                        }
                        break;

                    case "Runtime":
                        if (!reader.IsEmptyElement)
                        {
                            addIn.runtimes.AddRange(Runtime.ReadSection(reader, addIn, hintPath));
                        }
                        break;

                    case "Include":
                        if (reader.AttributeCount != 1)
                        {
                            throw new AddInLoadException("Include requires ONE attribute.");
                        }
                        if (!reader.IsEmptyElement)
                        {
                            throw new AddInLoadException("Include nodes must be empty!");
                        }
                        if (hintPath == null)
                        {
                            throw new AddInLoadException("Cannot use include nodes when hintPath was not specified (e.g. when AddInManager reads a .addin file)!");
                        }

                        string fileName = Path.Combine(hintPath, reader.GetAttribute(0));

                        XmlReaderSettings xrs = new XmlReaderSettings();
                        xrs.NameTable        = reader.NameTable;                          // share the name table
                        xrs.ConformanceLevel = ConformanceLevel.Fragment;
                        using (XmlReader includeReader = XmlTextReader.Create(fileName, xrs)) {
                            SetupAddIn(includeReader, addIn, Path.GetDirectoryName(fileName));
                        }
                        break;

                    case "Path":
//							if (reader.AttributeCount != 1) {
//								throw new AddInLoadException("Import node requires ONE attribute.");
//							}
//							string pathName = reader.GetAttribute(0);

                        Properties properties = Properties.ReadFromAttributes(reader);
                        string     pathName   = properties["name"];
                        if (string.IsNullOrEmpty(pathName))
                        {
                            pathName = properties["path"];
                        }

                        if (string.IsNullOrEmpty(pathName))
                        {
                            pathName = properties[properties.Keys[0]];
                        }

                        ExtensionPath extensionPath = addIn.GetExtensionPath(pathName);
                        if (!reader.IsEmptyElement)
                        {
                            ExtensionPath.SetUp(extensionPath, reader, "Path", properties);
                        }
                        break;

                    case "Manifest":
                        addIn.Manifest.ReadManifestSection(reader, hintPath);
                        break;

                    default:
                        throw new AddInLoadException("Unknown root path node:" + reader.LocalName);
                    }
                }
            }
        }