Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        internal ConditionType GetCondition(string id)
        {
            ConditionType ct;
            ConditionInfo info = (ConditionInfo)conditionTypes [id];

            if (info != null)
            {
                if (info.CondType is Type)
                {
                    // The condition was registered as a type, create an instance now
                    ct            = (ConditionType)Activator.CreateInstance((Type)info.CondType);
                    ct.Id         = id;
                    ct.Changed   += new EventHandler(OnConditionChanged);
                    info.CondType = ct;
                }
                else
                {
                    ct = info.CondType as ConditionType;
                }

                if (ct != null)
                {
                    return(ct);
                }
            }

            if (parentContext != null)
            {
                return(parentContext.GetCondition(id));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        ConditionInfo CreateConditionInfo(string id)
        {
            ConditionInfo info = conditionTypes [id] as ConditionInfo;

            if (info == null)
            {
                info = new ConditionInfo();
                conditionTypes [id] = info;
            }
            return(info);
        }
Ejemplo n.º 5
0
        public void RegisterCondition(string id, Type type)
        {
            // Allows delayed creation of condition types
            ConditionInfo info = CreateConditionInfo(id);
            ConditionType ot   = info.CondType as ConditionType;

            if (ot != null)
            {
                ot.Changed -= new EventHandler(OnConditionChanged);
            }
            info.CondType = type;
        }
Ejemplo n.º 6
0
        public void RegisterCondition(string id, ConditionType type)
        {
            type.Id = id;
            ConditionInfo info = CreateConditionInfo(id);
            ConditionType ot   = info.CondType as ConditionType;

            if (ot != null)
            {
                ot.Changed -= new EventHandler(OnConditionChanged);
            }
            info.CondType = type;
            type.Changed += new EventHandler(OnConditionChanged);
        }
Ejemplo n.º 7
0
        internal void NotifyConditionChanged(ConditionType cond)
        {
            try {
                fireEvents = true;

                ConditionInfo info = (ConditionInfo)conditionTypes [cond.Id];
                if (info != null && info.BoundConditions != null)
                {
                    Hashtable parentsToNotify = new Hashtable();
                    foreach (BaseCondition c in info.BoundConditions)
                    {
                        ArrayList nodeList = (ArrayList)conditionsToNodes [c];
                        if (nodeList != null)
                        {
                            foreach (TreeNode node in nodeList)
                            {
                                parentsToNotify [node.Parent] = null;
                            }
                        }
                    }
                    foreach (TreeNode node in parentsToNotify.Keys)
                    {
                        if (node.NotifyChildrenChanged())
                        {
                            NotifyExtensionsChanged(new ExtensionEventArgs(node.GetPath()));
                        }
                    }
                }
            }
            finally {
                fireEvents = false;
            }

            // Notify child contexts
            lock (conditionTypes) {
                if (childContexts != null)
                {
                    foreach (WeakReference wref in childContexts)
                    {
                        ExtensionContext ctx = wref.Target as ExtensionContext;
                        if (ctx != null)
                        {
                            ctx.NotifyConditionChanged(cond);
                        }
                    }
                }
            }
        }
		ConditionInfo CreateConditionInfo (string id)
		{
			ConditionInfo info = conditionTypes [id] as ConditionInfo;
			if (info == null) {
				info = new ConditionInfo ();
				conditionTypes [id] = info;
			}
			return info;
		}