/// <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); }
/// <summary> /// this control is already added to Parent.Controls /// 1. remove invalid inports /// 2. remove invalid EventIcon /// 3. add missed EventIcon /// 4. add missed EventPortIn /// 4. add EventIcon objects to Parent.Controls /// 5. initialize EventIcon /// </summary> /// <param name="viewer"></param> public virtual void Initialize(EventPathData eventData) { bool isRoot = this.IsRootClass; //validate events ClassPointer root = RootClassPointer; Dictionary <string, EventClass> events = root.CustomEvents; List <EventAction> ehs = root.EventHandlers; if (ehs != null && ehs.Count > 0) { if (_inPortList == null) { _inPortList = new List <EventPortIn>(); } else { //remove invalid inport List <EventPortIn> invalidInports = new List <EventPortIn>(); foreach (EventPortIn pi in _inPortList) { bool bFound = false; foreach (EventAction ea in ehs) { if (pi.Event.IsSameObjectRef(ea.Event)) { if (ea.TaskIDList != null && ea.TaskIDList.Count > 0) { foreach (TaskID tid in ea.TaskIDList) { if (this.IsActionExecuter(tid, root)) { bFound = true; break; } } } if (bFound) { break; } } } if (!bFound) { invalidInports.Add(pi); } } if (invalidInports.Count > 0) { foreach (EventPortIn pi in invalidInports) { _inPortList.Remove(pi); } } } //remove invalid EventIcon objects if (_events != null) { List <EventIcon> invalid = new List <EventIcon>(); foreach (EventIcon ei in _events) { bool bFound = false; if (ei.Event != null) { EventClass eic = ei.CustomEvent; if (eic != null) { if (isRoot) { if (this.ClassId == eic.ClassId) { foreach (EventClass ec in events.Values) { if (ec.IsSameObjectRef(eic)) { bFound = true; break; } } } } } if (!bFound) { foreach (EventAction ea in ehs) { if (ei.Event.IsSameObjectRef(ea.Event)) { bFound = true; break; } } } } if (!bFound) { invalid.Add(ei); } } foreach (EventIcon ei in invalid) { _events.Remove(ei); } //remove duplicated ports foreach (EventIcon ei in _events) { ei.ValidateSourcePorts(); } } //add missed EventIcon //add missed EventPortIn Dictionary <string, List <EventAction> > eaGroup = EventPathData.CreateHandlerGroup(ehs); foreach (EventAction ea in ehs) { IClass ic = EventPathData.GetEventFirerRef(ea.Event.Holder); if (ic != null) { if (ea.TaskIDList != null && ea.TaskIDList.Count > 0) { if (ic.IsSameObjectRef(this.ClassPointer)) { List <EventAction> eas; if (eaGroup.TryGetValue(ea.Event.ObjectKey, out eas)) { ValidateEventFirer(eas, eventData); } } ValidateActionExecuter(ea, root); } } } } if (isRoot) { foreach (EventClass ec in events.Values) { bool bFound = false; if (_events != null) { foreach (EventIcon ei in _events) { if (ec.IsSameObjectRef(ei.CustomEvent)) { ei.SetMoveUnLink(true); bFound = true; break; } } } if (!bFound) { if (_events == null) { _events = new List <EventIcon>(); } EventIcon ei = new EventIcon(this); ei.Event = new CustomEventPointer(ec, root); ei.SetMoveUnLink(true); _events.Add(ei); } } } //add EventIcon objects to Parent.Controls //initialize EventIcon if (_events != null) { Parent.Controls.AddRange(_events.ToArray()); foreach (EventIcon ei in _events) { ei.AdjustPosition(); ei.Initialize(); } } else { _events = new List <EventIcon>(); } }