Exemplo n.º 1
0
 BaseCondition ReadComplexCondition(ExtensionNodeDescription elem, BaseCondition parentCondition)
 {
     if (elem.NodeName == "Or" || elem.NodeName == "And" || elem.NodeName == "Not") {
         ArrayList conds = new ArrayList ();
         foreach (ExtensionNodeDescription celem in elem.ChildNodes) {
             conds.Add (ReadComplexCondition (celem, null));
         }
         if (elem.NodeName == "Or")
             return new OrCondition ((BaseCondition[]) conds.ToArray (typeof(BaseCondition)), parentCondition);
         else if (elem.NodeName == "And")
             return new AndCondition ((BaseCondition[]) conds.ToArray (typeof(BaseCondition)), parentCondition);
         else {
             if (conds.Count != 1) {
                 addinEngine.ReportError ("Invalid complex condition element '" + elem.NodeName + "'. 'Not' condition can only have one parameter.", null, null, false);
                 return new NullCondition ();
             }
             return new NotCondition ((BaseCondition) conds [0], parentCondition);
         }
     }
     if (elem.NodeName == "Condition") {
         return new Condition (AddinEngine, elem, parentCondition);
     }
     addinEngine.ReportError ("Invalid complex condition element '" + elem.NodeName + "'.", null, null, false);
     return new NullCondition ();
 }
Exemplo n.º 2
0
		internal BaseCondition (BaseCondition parent)
		{
			this.parent = parent;
		}
Exemplo n.º 3
0
        void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ModuleDescription module, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes)
        {
            foreach (ExtensionNodeDescription elem in extension) {

                if (inComplextCondition) {
                    parentCondition = ReadComplexCondition (elem, parentCondition);
                    inComplextCondition = false;
                    continue;
                }

                if (elem.NodeName == "ComplexCondition") {
                    LoadExtensionElement (tnode, addin, elem.ChildNodes, module, ref curPos, parentCondition, true, addedNodes);
                    continue;
                }

                if (elem.NodeName == "Condition") {
                    Condition cond = new Condition (AddinEngine, elem, parentCondition);
                    LoadExtensionElement (tnode, addin, elem.ChildNodes, module, ref curPos, cond, false, addedNodes);
                    continue;
                }

                var pnode = tnode;
                ExtensionPoint extensionPoint = null;
                while (pnode != null && (extensionPoint = pnode.ExtensionPoint) == null)
                    pnode = pnode.Parent;

                string after = elem.GetAttribute ("insertafter");
                if (after.Length == 0 && extensionPoint != null && curPos == -1)
                    after = extensionPoint.DefaultInsertAfter;
                if (after.Length > 0) {
                    int i = tnode.Children.IndexOfNode (after);
                    if (i != -1)
                        curPos = i+1;
                }
                string before = elem.GetAttribute ("insertbefore");
                if (before.Length == 0 && extensionPoint != null && curPos == -1)
                    before = extensionPoint.DefaultInsertBefore;
                if (before.Length > 0) {
                    int i = tnode.Children.IndexOfNode (before);
                    if (i != -1)
                        curPos = i;
                }

                // If node position is not explicitly set, add the node at the end
                if (curPos == -1)
                    curPos = tnode.Children.Count;

                // Find the type of the node in this extension
                ExtensionNodeType ntype = addinEngine.FindType (tnode.ExtensionNodeSet, elem.NodeName, addin);

                if (ntype == null) {
                    addinEngine.ReportError ("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath (), addin, null, false);
                    continue;
                }

                string id = elem.GetAttribute ("id");
                if (id.Length == 0)
                    id = AutoIdPrefix + (++internalId);

                TreeNode cnode = new TreeNode (addinEngine, id);

                ExtensionNode enode = ReadNode (cnode, addin, ntype, elem, module);
                if (enode == null)
                    continue;

                cnode.Condition = parentCondition;
                cnode.ExtensionNodeSet = ntype;
                tnode.InsertChildNode (curPos, cnode);
                addedNodes.Add (cnode);

                if (cnode.Condition != null)
                    Context.RegisterNodeCondition (cnode, cnode.Condition);

                // Load children
                if (elem.ChildNodes.Count > 0) {
                    int cp = 0;
                    LoadExtensionElement (cnode, addin, elem.ChildNodes, module, ref cp, parentCondition, false, addedNodes);
                }

                curPos++;
            }
            if (Context.FireEvents)
                tnode.NotifyChildrenChanged ();
        }
Exemplo n.º 4
0
		public NotCondition (BaseCondition baseCond, BaseCondition parent): base (parent)
		{
			this.baseCond = baseCond;
		}
Exemplo n.º 5
0
		internal Condition (AddinEngine addinEngine, ExtensionNodeDescription element, BaseCondition parent): base (parent)
		{
			this.addinEngine = addinEngine;
			typeId = element.GetAttribute ("id");
			addin = element.GetAttribute (SourceAddinAttribute);
			node = element;
		}
		internal Condition (ExtensionNodeDescription element, BaseCondition parent): base (parent)
		{
			typeId = element.GetAttribute ("id");
			node = element;
		}
Exemplo n.º 7
0
		public AndCondition (BaseCondition[] conditions, BaseCondition parent): base (parent)
		{
			this.conditions = conditions;
		}
		internal void UnregisterNodeCondition (TreeNode node, BaseCondition cond)
		{
			ArrayList list = (ArrayList) conditionsToNodes [cond];
			if (list == null)
				return;
			
			list.Remove (node);
			if (list.Count == 0) {
				conditionsToNodes.Remove (cond);
				ArrayList conditionTypeIds = new ArrayList ();
				cond.GetConditionTypes (conditionTypeIds);
				foreach (string cid in conditionTypes.Keys) {
					ConditionInfo info = conditionTypes [cid] as ConditionInfo;
					if (info != null && info.BoundConditions != null)
						info.BoundConditions.Remove (cond);
				}
			}
		}
		internal void RegisterNodeCondition (TreeNode node, BaseCondition cond)
		{
			ArrayList list = (ArrayList) conditionsToNodes [cond];
			if (list == null) {
				list = new ArrayList ();
				conditionsToNodes [cond] = list;
				ArrayList conditionTypeIds = new ArrayList ();
				cond.GetConditionTypes (conditionTypeIds);
				
				foreach (string cid in conditionTypeIds) {
				
					// Make sure the condition is properly created
					GetCondition (cid);
					
					ConditionInfo info = CreateConditionInfo (cid);
					if (info.BoundConditions == null)
						info.BoundConditions = new ArrayList ();
						
					info.BoundConditions.Add (cond);
				}
			}
			list.Add (node);
		}
		void LoadExtensionElement (TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes)
		{
			foreach (ExtensionNodeDescription elem in extension) {
					
				if (inComplextCondition) {
					parentCondition = ReadComplexCondition (elem, parentCondition);
					inComplextCondition = false;
					continue;
				}

				if (elem.NodeName == "ComplexCondition") {
					LoadExtensionElement (tnode, addin, elem.ChildNodes, ref curPos, parentCondition, true, addedNodes);
					continue;
				}
					
				if (elem.NodeName == "Condition") {
					Condition cond = new Condition (elem, parentCondition);
					LoadExtensionElement (tnode, addin, elem.ChildNodes, ref curPos, cond, false, addedNodes);
					continue;
				}
					
				string after = elem.GetAttribute ("insertafter");
				if (after.Length > 0) {
					int i = tnode.Children.IndexOfNode (after);
					if (i != -1)
						curPos = i+1;
				}
				string before = elem.GetAttribute ("insertbefore");
				if (before.Length > 0) {
					int i = tnode.Children.IndexOfNode (before);
					if (i != -1)
						curPos = i;
				}
				
				// Find the type of the node in this extension
				ExtensionNodeType ntype = AddinManager.SessionService.FindType (tnode.ExtensionNodeSet, elem.NodeName, addin);
				
				if (ntype == null) {
					AddinManager.ReportError ("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath (), addin, null, false);
					continue;
				}
				
				string id = elem.GetAttribute ("id");
				if (id.Length == 0)
					id = AutoIdPrefix + (++internalId);

				TreeNode cnode = new TreeNode (id);
				
				ExtensionNode enode = ReadNode (cnode, addin, ntype, elem);
				if (enode == null)
					continue;

				cnode.Condition = parentCondition;
				cnode.ExtensionNodeSet = ntype;
				tnode.InsertChildNode (curPos, cnode);
				addedNodes.Add (cnode);
				
				if (cnode.Condition != null)
					Context.RegisterNodeCondition (cnode, cnode.Condition);

				// Load children
				if (elem.ChildNodes.Count > 0) {
					int cp = 0;
					LoadExtensionElement (cnode, addin, elem.ChildNodes, ref cp, parentCondition, false, addedNodes);
				}
				
				curPos++;
			}
			if (Context.FireEvents)
				tnode.NotifyChildrenChanged ();
		}
		BaseCondition ReadComplexCondition (ExtensionNodeDescription elem, BaseCondition parentCondition)
		{
			if (elem.NodeName == "Or" || elem.NodeName == "And") {
				ArrayList conds = new ArrayList ();
				foreach (ExtensionNodeDescription celem in elem.ChildNodes) {
					conds.Add (ReadComplexCondition (celem, null));
				}
				if (elem.NodeName == "Or")
					return new OrCondition ((BaseCondition[]) conds.ToArray (typeof(BaseCondition)), parentCondition);
				else
					return new AndCondition ((BaseCondition[]) conds.ToArray (typeof(BaseCondition)), parentCondition);
			}
			if (elem.NodeName == "Condition") {
				return new Condition (elem, parentCondition);
			}
			AddinManager.ReportError ("Invalid complex condition element '" + elem.NodeName + "'.", null, null, false);
			return new NullCondition ();
		}
Exemplo n.º 12
0
        void LoadExtensionElement(TreeNode tnode, string addin, ExtensionNodeDescriptionCollection extension, ref int curPos, BaseCondition parentCondition, bool inComplextCondition, ArrayList addedNodes)
        {
            foreach (ExtensionNodeDescription elem in extension)
            {
                if (inComplextCondition)
                {
                    parentCondition     = ReadComplexCondition(elem, parentCondition);
                    inComplextCondition = false;
                    continue;
                }

                if (elem.NodeName == "ComplexCondition")
                {
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, ref curPos, parentCondition, true, addedNodes);
                    continue;
                }

                if (elem.NodeName == "Condition")
                {
                    Condition cond = new Condition(elem, parentCondition);
                    LoadExtensionElement(tnode, addin, elem.ChildNodes, ref curPos, cond, false, addedNodes);
                    continue;
                }

                string after = elem.GetAttribute("insertafter");
                if (after.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(after);
                    if (i != -1)
                    {
                        curPos = i + 1;
                    }
                }
                string before = elem.GetAttribute("insertbefore");
                if (before.Length > 0)
                {
                    int i = tnode.Children.IndexOfNode(before);
                    if (i != -1)
                    {
                        curPos = i;
                    }
                }

                // Find the type of the node in this extension
                ExtensionNodeType ntype = AddinManager.SessionService.FindType(tnode.ExtensionNodeSet, elem.NodeName, addin);

                if (ntype == null)
                {
                    AddinManager.ReportError("Node '" + elem.NodeName + "' not allowed in extension: " + tnode.GetPath(), addin, null, false);
                    continue;
                }

                string id = elem.GetAttribute("id");
                if (id.Length == 0)
                {
                    id = AutoIdPrefix + (++internalId);
                }

                TreeNode cnode = new TreeNode(id);

                ExtensionNode enode = ReadNode(cnode, addin, ntype, elem);
                if (enode == null)
                {
                    continue;
                }

                cnode.Condition        = parentCondition;
                cnode.ExtensionNodeSet = ntype;
                tnode.InsertChildNode(curPos, cnode);
                addedNodes.Add(cnode);

                if (cnode.Condition != null)
                {
                    Context.RegisterNodeCondition(cnode, cnode.Condition);
                }

                // Load children
                if (elem.ChildNodes.Count > 0)
                {
                    int cp = 0;
                    LoadExtensionElement(cnode, addin, elem.ChildNodes, ref cp, parentCondition, false, addedNodes);
                }

                curPos++;
            }
            if (Context.FireEvents)
            {
                tnode.NotifyChildrenChanged();
            }
        }