public EventPortIn ValidateActionExecuter(EventAction ea, ClassPointer root)
        {
            EventPortIn missing = null;

            if (_inPortList == null)
            {
                _inPortList = new List <EventPortIn>();
            }
            foreach (TaskID tid in ea.TaskIDList)
            {
                if (this.IsActionExecuter(tid, root))
                {
                    bool bFound = false;
                    foreach (EventPortIn pi in _inPortList)
                    {
                        if (pi.Event.IsSameObjectRef(ea.Event))
                        {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        EventPortIn pi = new EventPortIn(this);
                        pi.Event = ea.Event;
                        _inPortList.Add(pi);
                        double x, y;
                        ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                        pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                        pi.SetLoaded();
                        pi.SaveLocation();
                        //
                        missing = pi;
                    }
                    break;
                }
            }
            return(missing);
        }
Example #2
0
        /// <summary>
        /// link: from this action to the event
        /// it does not have in-ports
        /// it has one out-port linking to the event
        /// </summary>
        /// <param name="eventData"></param>
        public override void Initialize(EventPathData eventData)
        {
            List <EventPortIn> inports = this.DestinationPorts;
            List <IEvent>      events  = new List <IEvent>();
            ClassPointer       root    = eventData.Owner.RootPointer;

            if (_firer != null)
            {
                List <EventAction> eas = root.EventHandlers;
                foreach (EventAction ea in eas)
                {
                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                    {
                        //this event handling is not empty
                        //check to see if there is an event-firing action using this firer
                        //if there is one then this event should be linked to this firer
                        //that is, this ea causes the firer to fire another event
                        foreach (TaskID tid in ea.TaskIDList)
                        {
                            if (tid.Action == null)
                            {
                                tid.LoadActionInstance(root);
                            }
                            if (tid.Action != null)
                            {
                                FireEventMethod fe = tid.Action.ActionMethod as FireEventMethod;
                                if (fe != null)
                                {
                                    if (fe.EventId == _firer.EventId && fe.MemberId == _firer.MemberId)
                                    {
                                        events.Add(ea.Event);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            List <EventPortIn> invalid = new List <EventPortIn>();

            foreach (EventPortIn epi in inports)
            {
                bool found = false;
                foreach (IEvent e in events)
                {
                    if (e.IsSameObjectRef(epi.Event))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    invalid.Add(epi);
                }
            }
            if (invalid.Count > 0)
            {
                foreach (EventPortIn epi in invalid)
                {
                    inports.Remove(epi);
                }
            }
            foreach (IEvent e in events)
            {
                bool found = false;
                foreach (EventPortIn epi in inports)
                {
                    if (e.IsSameObjectRef(epi.Event))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    EventPortIn epi = new EventPortIn(this);
                    epi.Event = e;
                    epi.SetLoaded();
                    inports.Add(epi);
                }
            }
        }
        /// <summary>
        /// this control is already added to Parent.Controls.
        /// 1. remove invalid inports
        /// 2. add missed EventPortIn
        /// </summary>
        /// <param name="viewer"></param>
        public override void Initialize(EventPathData eventData)
        {
            ClassPointer       root = this.ClassPointer.RootPointer;
            List <EventAction> ehs  = root.EventHandlers;

            if (ehs != null && ehs.Count > 0)
            {
                if (DestinationPorts == null)
                {
                    DestinationPorts = new List <EventPortIn>();
                }
                else
                {
                    //remove invalid inport
                    List <EventPortIn> invalidInports = new List <EventPortIn>();
                    foreach (EventPortIn pi in DestinationPorts)
                    {
                        bool bFound = false;
                        foreach (EventAction ea in ehs)
                        {
                            if (pi.Event.IsSameObjectRef(ea.Event))
                            {
                                if (pi.Event.IsSameObjectRef(ea.Event))
                                {
                                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                                    {
                                        foreach (TaskID tid in ea.TaskIDList)
                                        {
                                            if (tid.IsEmbedded)
                                            {
                                                HandlerMethodID hid = tid as HandlerMethodID;
                                                if (hid != null)
                                                {
                                                    if (hid.ActionId == this.MethodId)
                                                    {
                                                        bFound = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                IAction a = root.GetActionInstance(tid.ActionId);                                                //only public actions in map
                                                if (a != null)
                                                {
                                                    CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer;
                                                    if (cmp != null)
                                                    {
                                                        if (cmp.MemberId == this.MethodId)
                                                        {
                                                            bFound = true;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (bFound)
                                {
                                    break;
                                }
                            }
                        }
                        if (!bFound)
                        {
                            invalidInports.Add(pi);
                        }
                    }
                    if (invalidInports.Count > 0)
                    {
                        foreach (EventPortIn pi in invalidInports)
                        {
                            DestinationPorts.Remove(pi);
                        }
                    }
                }
                //add missed EventPortIn
                foreach (EventAction ea in ehs)
                {
                    if (ea.TaskIDList != null && ea.TaskIDList.Count > 0)
                    {
                        foreach (TaskID tid in ea.TaskIDList)
                        {
                            HandlerMethodID hid = tid as HandlerMethodID;
                            if (hid != null)
                            {
                                if (hid.ActionId == this.MethodId)
                                {
                                    bool bFound = false;
                                    foreach (EventPortIn pi in DestinationPorts)
                                    {
                                        if (pi.Event.IsSameObjectRef(ea.Event))
                                        {
                                            bFound = true;
                                            break;
                                        }
                                    }
                                    if (!bFound)
                                    {
                                        EventPortIn pi = new EventPortIn(this);

                                        pi.Event = ea.Event;
                                        double x, y;
                                        ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                                        pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                                        pi.SetLoaded();
                                        pi.SaveLocation();
                                        DestinationPorts.Add(pi);
                                    }
                                }
                            }
                            else
                            {
                                //it is a root scope action
                                IAction a = root.GetActionInstance(tid.ActionId);
                                if (a == null)
                                {
                                    MathNode.LogError(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                    "Action [{0}] not found", tid));
                                }
                                else
                                {
                                    CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer;
                                    if (cmp != null)
                                    {
                                        if (cmp.MemberId == this.MethodId)
                                        {
                                            bool bFound = false;
                                            foreach (EventPortIn pi in DestinationPorts)
                                            {
                                                if (pi.Event.IsSameObjectRef(ea.Event))
                                                {
                                                    bFound = true;
                                                    break;
                                                }
                                            }
                                            if (!bFound)
                                            {
                                                EventPortIn pi = new EventPortIn(this);
                                                pi.Event = ea.Event;
                                                double x, y;
                                                ComponentIconEvent.CreateRandomPoint(Width + ComponentIconEvent.PortSize, out x, out y);
                                                pi.Location = new Point((int)(Center.X + x), (int)(Center.Y + y));
                                                pi.SetLoaded();
                                                pi.SaveLocation();
                                                DestinationPorts.Add(pi);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }