コード例 #1
0
        /// <summary>
        /// remove invalid outports
        /// add missing outports
        /// </summary>
        /// <returns>missing outports added</returns>
        public List <EventPortOut> Initialize()
        {
            if (_inPortList != null && _inPortList.Count > 0)
            {
                foreach (EventPortIn epi in _inPortList)
                {
                    epi.RestoreLocation();
                }
            }
            List <EventPortOut> missing = new List <EventPortOut>();

            if (_data != null && _data.Owner != null && _data.Owner.Loader != null)
            {
                ClassPointer root = _data.Owner.Loader.GetRootId();
                Dictionary <string, List <EventAction> > eaGroup = EventPathData.CreateHandlerGroup(root.EventHandlers);
                bool hasAction = false;
                if (eaGroup.TryGetValue(_event.ObjectKey, out _eventActionList))
                {
                    foreach (EventAction ea in _eventActionList)
                    {
                        if (ea.TaskIDList.Count > 0)
                        {
                            hasAction = true;
                            break;
                        }
                    }
                }
                else
                {
                    _eventActionList = new List <EventAction>();
                }
                if (!hasAction)
                {
                    _outPortList.Clear();
                }
                else
                {
                    foreach (EventAction ea in _eventActionList)
                    {
                        for (int i = 0; i < ea.TaskIDList.Count; i++)
                        {
                            if (ea.TaskIDList[i].Action == null)
                            {
                                ea.TaskIDList[i].LoadActionInstance(root);
                            }
                        }
                    }
                    //remove invalid out ports===============================
                    if (_outPortList == null)
                    {
                        _outPortList = new List <EventPortOut>();
                    }
                    else
                    {
                        if (_outPortList.Count > 0)
                        {
                            List <EventPortOut> invalidPorts = new List <EventPortOut>();
                            foreach (EventPortOut po in _outPortList)
                            {
                                bool bLinked = false;
                                //for all actions for this event, find one that is for this port
                                foreach (EventAction ea in _eventActionList)
                                {
                                    for (int i = 0; i < ea.TaskIDList.Count; i++)
                                    {
                                        bLinked = po.CanActionBeLinked(ea.TaskIDList[i]);
                                        if (bLinked)
                                        {
                                            break;
                                        }
                                    }
                                    if (bLinked)
                                    {
                                        break;
                                    }
                                }
                                if (!bLinked)
                                {
                                    invalidPorts.Add(po);
                                }
                            }
                            if (invalidPorts.Count > 0)
                            {
                                foreach (EventPortOut po in invalidPorts)
                                {
                                    _outPortList.Remove(po);
                                }
                            }
                        }
                    }
                    //===add missing ports=======================================
                    foreach (EventAction ea in _eventActionList)
                    {
                        if (ea.TaskIDList.Count > 0)
                        {
                            //
                            //add missing outports, generate EventPortOut instances to link to EventPortIn instances
                            //
                            for (int i = 0; i < ea.TaskIDList.Count; i++)
                            {
                                EventPortOut po      = null;
                                bool         bLinked = false;
                                foreach (EventPortOut eo in _outPortList)
                                {
                                    bLinked = eo.IsForTheAction(ea.TaskIDList[i]);
                                    if (bLinked)
                                    {
                                        break;
                                    }
                                    if (po == null)
                                    {
                                        if (eo.CanActionBeLinked(ea.TaskIDList[i]))
                                        {
                                            po = eo;
                                        }
                                    }
                                }
                                if (!bLinked)
                                {
                                    if (po != null)
                                    {
                                        po.AddAction(ea.TaskIDList[i]);
                                    }
                                    else
                                    {
                                        po = EventPortOut.CreateOutPort(ea.TaskIDList[i], this);
                                        if (po != null)
                                        {
                                            po.Event = _event;
                                            _outPortList.Add(po);
                                            missing.Add(po);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(missing);
        }
コード例 #2
0
        public static EventPortOut CreateOutPort(TaskID a, EventIcon owner)
        {
            EventPortOut        po  = null;
            CustomMethodPointer cmp = null;
            HandlerMethodID     hid = a as HandlerMethodID;

            if (hid != null)
            {
                EventPortOutExecuteMethod em = new EventPortOutExecuteMethod(owner);
                em.SetMethod(hid.HandlerMethod);
                po = em;
            }
            else
            {
                if (a.Action == null)
                {
                }
                else
                {
                    IEventMapSource eir  = owner as IEventMapSource;
                    ClassPointer    root = eir.RootPointer;
                    ClassPointer    cpre = root.GetExternalExecuterClass(a.Action);
                    if (a.Action.IsStatic && cpre != null)
                    {
                        EventPortOutClassTypeAction pct = new EventPortOutClassTypeAction(owner);
                        pct.SetOwnerClassPointer(cpre);
                        po = pct;
                    }
                    else if (a.Action.ActionMethod != null)
                    {
                        DataTypePointer dtp = a.Action.ActionMethod.Owner as DataTypePointer;
                        if (dtp != null)
                        {
                            EventPortOutTypeAction pot = new EventPortOutTypeAction(owner);
                            pot.SetOwnerType(dtp.BaseClassType);
                            po = pot;
                        }
                        else
                        {
                            cmp = a.Action.ActionMethod as CustomMethodPointer;
                            if (cmp != null && cmp.Holder.DefinitionClassId == a.ClassId)
                            {
                                EventPortOutExecuteMethod em = new EventPortOutExecuteMethod(owner);
                                MethodClass mc = cmp.MethodPointed as MethodClass;
                                if (mc != null)
                                {
                                    em.SetMethod(mc);
                                }
                                po = em;
                            }
                            else
                            {
                                po = null;
                                SetterPointer sp = a.Action.ActionMethod as SetterPointer;
                                if (sp != null)
                                {
                                    CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer;
                                    if (cpp != null)
                                    {
                                        EventPortOutSetProperty posp = new EventPortOutSetProperty(owner);
                                        posp.SetProperty(cpp.Property);
                                        posp.PropertyId = cpp.MemberId;
                                        po = posp;
                                    }
                                }
                                if (po == null)
                                {
                                    EventPortOutExecuter pe = new EventPortOutExecuter(owner);
                                    pe.ActionExecuterId = a.Action.ExecuterMemberId;
                                    po = pe;
                                }
                            }
                        }
                    }
                    else
                    {
                        ActionAttachEvent aae = a.Action as ActionAttachEvent;
                        if (aae != null)
                        {
                            EventPortOutExecuter pe = new EventPortOutExecuter(owner);
                            pe.ActionExecuterId = a.Action.ExecuterMemberId;
                            po = pe;
                        }
                    }
                }
            }
            if (po != null)
            {
                po.AddAction(a);
                ActiveDrawing ei = owner as ActiveDrawing;
                double        x, y;
                ComponentIconEvent.CreateRandomPoint(ei.Width + ComponentIconEvent.PortSize, out x, out y);
                po.Location = new Point((int)(ei.Center.X + x), (int)(ei.Center.Y + y));
                po.SetLoaded();
                po.SaveLocation();
            }
            return(po);
        }