public void LoadActions() { actions = DesignUtil.GetActions(_map); eventHandlers = DesignUtil.GetEventHandlers(_map); if (ProjectEnvironment.RunMode) //&& _map.ParanetMap == null) { //if an action is for executing a custom method then the actions inside the method //only holds actions ID's. We need associate actions objects to those action ID's //by going through all action branches foreach (IAction a in actions) { //ActionCustom ac = a as ActionCustom; //if (ac != null) //{ // ac.SetActions(actions); //} CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer; if (cmp != null) { cmp.MethodDef.SetActions(actions); } } //link events to actions foreach (EventAction ea in eventHandlers) { if (ea.Event.ObjectInstance != null) { SetEventLink(ea.Event); } } } }
public override bool CanActionBeLinked(TaskID act) { HandlerMethodID hid = act as HandlerMethodID; if (hid != null) { return(hid.ActionId == this.MethodId); } if (act.Action != null) { DataTypePointer dtp = act.Action.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } ClassPointer cpr = this.RootPointer.GetExternalExecuterClass(act.Action); if (cpr != null) { return(false); } CustomMethodPointer cmp = act.Action.ActionMethod as CustomMethodPointer; if (cmp != null) { if (cmp.MemberId == MethodId) { return(true); } } } return(false); }
public override bool CanActionBeLinked(TaskID act) { if (act.Action == null) { act.LoadActionInstance(this.RootPointer); } ActionAttachEvent aae = act.Action as ActionAttachEvent; if (aae != null) { return(aae.ExecuterMemberId == ActionExecuterId); } if (act.Action != null && act.Action.ActionMethod != null) { ClassPointer cpr = this.RootPointer.GetExternalExecuterClass(act.Action); if (cpr != null) { return(false); } DataTypePointer dtp = act.Action.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } CustomMethodPointer cp = act.Action.ActionMethod as CustomMethodPointer; if (cp != null) { if (cp.ClassId != act.ClassId) { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } else { SetterPointer sp = act.Action.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp == null || cpp.ClassId != act.ClassId) { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } else { if (act.Action.ExecuterMemberId == ActionExecuterId) { return(true); } } } } return(false); }
/// <summary> /// called from event action list, not from a custom method. /// called only between event actions /// </summary> /// <param name="objectKey"></param> /// <param name="eventName"></param> /// <param name="taskId"></param> /// <param name="executer"></param> public void BeforeExecuteEventAction(string objectKey, string eventName, int actionIndex, object executer) { if (_ComponentDebugger.Stopping) { return; } _ComponentDebugger.ClearBreakpointDisplay(); EventAction ea = _ComponentDebugger.RootClass.GetEventHandler(eventName, objectKey); if (ea != null) { int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; if (actionIndex > 0) { //check the action just finished is an custom method or not if (!ea.TaskIDList[actionIndex - 1].IsEmbedded) { IAction a = _ComponentDebugger.RootClass.GetActionInstance(ea.TaskIDList[actionIndex - 1].ActionId); if (a != null) { CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer; if (cmp != null) { MethodDesignerHolder h = _ComponentDebugger.GetViewer(threadId, cmp.MethodDef.MethodID); if (h != null) { h.ActionGroup.GroupFinished = true; _ComponentDebugger.UpdateViewersBackColor(); } } } } } EnumRunStatus status = _ComponentDebugger.GetRunStatus(threadId); if ((status != EnumRunStatus.Stop && status != EnumRunStatus.Run) || ea.TaskIDList[actionIndex].BreakAsEventAction) { _ComponentDebugger.SetSelectedObject(executer); _ComponentDebugger.SetAtBreak(threadId, true); _debugUI.ShowBreakPoint(_ComponentDebugger); _ComponentDebugger.ShowEventBreakPointInTreeView(objectKey, eventName, executer, actionIndex); waitForBreakPoint(threadId); } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { ActionClass act = context.Instance as ActionClass; if (act == null) { LimnorDesigner.PropertiesWrapper pw = context.Instance as LimnorDesigner.PropertiesWrapper; if (pw != null) { LimnorDesigner.Action.AB_SingleAction abs = pw.Owner as LimnorDesigner.Action.AB_SingleAction; if (abs != null) { act = abs.ActionData as ActionClass; } } } if (act != null && act.ScopeMethod != null) { MethodClass mc = act.ScopeMethod as MethodClass; if (mc != null && (mc.CurrentEditor != null || mc.CurrentSubEditor != null)) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { listAssignedTo list = new listAssignedTo(edSvc); edSvc.DropDownControl(list); if (list.SelectedAssignedTo == 0) { ComponentIconLocal cil = null; MethodClass actMethod = act.ActionMethod as MethodClass; if (actMethod == null) { CustomMethodPointer cmp = act.ActionMethod as CustomMethodPointer; if (cmp != null) { actMethod = cmp.MethodDef; } } if (act.ReturnValueType.IsLibType) { Type t = act.ReturnValueType.BaseClassType; if (t.IsArray) { ArrayPointer ap = new ArrayPointer(new TypePointer(t.GetElementType())); if (mc.CurrentSubEditor != null) { cil = mc.CurrentSubEditor.CreateLocalVariable(ap, new System.Drawing.Point(0, 0), actMethod, false); } else { cil = mc.CurrentEditor.CreateLocalVariable(ap, new System.Drawing.Point(0, 0), actMethod, false); } } } if (cil == null) { if (mc.CurrentSubEditor != null) { cil = mc.CurrentSubEditor.CreateLocalVariable(act.ReturnValueType, new System.Drawing.Point(0, 0), actMethod, false); } else { cil = mc.CurrentEditor.CreateLocalVariable(act.ReturnValueType, new System.Drawing.Point(0, 0), actMethod, false); } } cil.LocalPointer.Owner = mc; if (cil.LocalPointer.BaseClassType.IsGenericParameter) { if (cil.LocalPointer.ClassType.ConcreteType == null) { DataTypePointer dp = act.GetConcreteType(cil.LocalPointer.BaseClassType); if (dp != null) { cil.LocalPointer.ClassType.SetConcreteType(dp); } } } else if (cil.LocalPointer.BaseClassType.IsGenericType) { MethodPointer mp = act.ActionMethod as MethodPointer; if (mp != null) { if (mp.ReturnTypeConcrete != null) { cil.LocalPointer.SetDataType(mp.ReturnTypeConcrete); } else { DataTypePointer dp = mp.GetConcreteType(cil.LocalPointer.BaseClassType); if (dp != null) { cil.LocalPointer.SetDataType(dp); } } } } value = cil.LocalPointer; } else if (list.SelectedAssignedTo == 1) { LValueSelector pe = new LValueSelector(); value = pe.EditValue(context, provider, value); } } } } } return(value); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { IMethod m = value as IMethod; IActionMethodPointer im = null; MethodPointer method = value as MethodPointer; if (m == null) { IMethodPointerHolder mh = context.Instance as IMethodPointerHolder; if (mh != null) { im = mh.GetMethodPointer(); if (im != null) { m = im.MethodPointed; } } } MethodClass scopeMethod = null; Type t = edSvc.GetType(); PropertyInfo pif0 = t.GetProperty("OwnerGrid"); if (pif0 != null) { object g = pif0.GetValue(edSvc, null); MathPropertyGrid pg = g as MathPropertyGrid; if (pg != null) { scopeMethod = pg.ScopeMethod as MethodClass; } } if (scopeMethod == null) { IAction ia = context.Instance as IAction; if (ia != null) { scopeMethod = ia.ScopeMethod as MethodClass; } } FrmObjectExplorer dlg = DesignUtil.CreateSelectMethodDialog(scopeMethod, m); if (edSvc.ShowDialog(dlg) == DialogResult.OK) { IAction act = null; if (method != null) { act = method.Action; } if (act == null) { if (im != null) { act = im.Action; } } IPropertyEx p = dlg.SelectedObject as IPropertyEx; if (p != null) { value = p.CreateSetterMethodPointer(act); } else { MethodPointer mp = dlg.SelectedObject as MethodPointer; if (mp != null) { mp.Action = act; value = mp; } else { CustomMethodPointer cmp = dlg.SelectedObject as CustomMethodPointer; if (cmp != null) { cmp.Action = act; value = cmp; } } } } } } return(value); }
/// <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); } } } } } } } } } }
/// <summary> /// finish execute an action /// </summary> /// <param name="objectKey"></param> /// <param name="methodWholeId"></param> /// <param name="branchId"></param> /// <param name="executer"></param> public void AfterExecuteAction(string objectKey, UInt64 methodWholeId, UInt32 branchId, object executer) { if (_ComponentDebugger.Stopping) { return; } int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId; _ComponentDebugger.DecrementStackLevel(threadId); //check if it is at a break point MethodClass mc = _ComponentDebugger.GetMethod(methodWholeId); if (mc != null) { IActionGroup g = mc; ActionBranch branch = mc.GetBranchByIdInGroup(branchId, ref g); if (branch != null) { IActionGroup g0 = branch as IActionGroup; if (g0 != null) { //finished calling a group of actions MethodDesignerHolder h = _ComponentDebugger.GetViewer(threadId, g0.GroupId); if (h != null) { h.ActionGroup.GroupFinished = true; _ComponentDebugger.UpdateViewersBackColor(); } } else { ISingleAction sa = branch as ISingleAction; if (sa != null) { CustomMethodPointer ac = sa.ActionData.ActionMethod as CustomMethodPointer; if (ac != null) { //finished calling a custom action MethodDesignerHolder h = _ComponentDebugger.GetViewer(threadId, ac.MethodDef.MethodID); if (h != null) { h.ActionGroup.GroupFinished = true; _ComponentDebugger.UpdateViewersBackColor(); } } } } EnumRunStatus status = _ComponentDebugger.GetRunStatus(threadId); bool b = (status == EnumRunStatus.Pause || status == EnumRunStatus.StepInto); if (!b) { if (status == EnumRunStatus.StepOver && _ComponentDebugger.ReachStepOver(threadId)) { b = true; } if (!b) { if (status == EnumRunStatus.StepOut && _ComponentDebugger.ReachStepOut(threadId)) { b = true; } } } if (b || branch.BreakAfterExecute) { _ComponentDebugger.SetSelectedObject(executer); _ComponentDebugger.SetAtBreak(threadId, true); _debugUI.ShowBreakPoint(_ComponentDebugger); branch.AtBreak = EnumActionBreakStatus.After; _ComponentDebugger.ShowBreakPointInMethod(threadId, mc, g, branch); waitForBreakPoint(threadId); branch.AtBreak = EnumActionBreakStatus.None; _ComponentDebugger.ShowBreakPointInMethod(threadId, mc, g, branch); } else { branch.AtBreak = EnumActionBreakStatus.None; _ComponentDebugger.ClearBreakPointInMethod(threadId, mc, g, branch); } } } }
/// <summary> /// check whether the action is executed by the owner of this icon /// </summary> /// <param name="act"></param> /// <param name="root"></param> /// <returns></returns> public virtual bool IsActionExecuter(IAction act, ClassPointer root) { FireEventMethod fe = act.ActionMethod as FireEventMethod; if (fe != null) { } else if (act.ActionMethod != null) { DataTypePointer dtp = act.ActionMethod.Owner as DataTypePointer; if (dtp != null) { return(false); } ClassPointer cpa = root.GetExternalExecuterClass(act); if (cpa != null) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } return(false); } CustomMethodPointer cmp = act.ActionMethod as CustomMethodPointer; if (cmp != null) { //for the same class, ComponentIconMethod is used if (act.ExecuterClassId != this.ClassPointer.ClassId) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } } return(false); } else { SetterPointer sp = act.ActionMethod as SetterPointer; if (sp != null) { CustomPropertyPointer cpp = sp.SetProperty as CustomPropertyPointer; if (cpp != null) { //for the same class ComponentIconProperty is used if (act.ExecuterClassId != this.ClassPointer.ClassId) { MemberComponentIdCustom idc = this.ClassPointer as MemberComponentIdCustom; if (idc != null) { return(act.ExecuterClassId == idc.DefinitionClassId); } } return(false); } } return(act.ExecuterMemberId == this.ClassPointer.MemberId); } } else { ActionAttachEvent aae = act as ActionAttachEvent; if (aae != null) { if (aae.ClassId == this.ClassId && aae.ExecuterMemberId == this.ClassPointer.MemberId) { return(true); } } } return(false); }
public void OnActionChanged(uint classId, IAction act, bool isNewAction) { if (_panes.Loader.ClassID == classId) { if (isNewAction) { if (_eventPath.SelectedEvent == null && _eventPath.SelectedLinkLine == null) { ComponentIconEvent cie = _eventPath.GetSelectedComponentIcon(); if (cie != null) { if (cie.IsForComponent) { if (cie.ClassPointer.MemberId == act.ExecuterMemberId) { listBoxActions.Items.Add(act); } } else { ComponentIconMethod cim = cie as ComponentIconMethod; if (cim != null) { CustomMethodPointer cmp = act.ActionMethod as CustomMethodPointer; if (cmp != null) { if (cmp.MemberId == cim.MethodId) { listBoxActions.Items.Add(act); } } } else { ComponentIconProperty cip = cie as ComponentIconProperty; if (cip != null) { if (cip.Property.IsActionOwner(act)) { listBoxActions.Items.Add(act); } } } } } } } else { for (int i = 0; i < listBoxActions.Items.Count; i++) { IAction a = listBoxActions.Items[i] as IAction; if (a != null) { if (a.ActionId == act.ActionId) { if (string.CompareOrdinal(a.ActionName, act.ActionName) != 0) { } } } } //if(_eventPath. } _eventPath.OnActionChanged(classId, act, isNewAction); } }
/// <summary> /// icon selected by mouse, called from EventPath /// </summary> /// <param name="ci"></param> public void OnComponentIconSelection(ComponentIcon ci) { if (!_loading) { listBoxActions.Items.Clear(); ClassPointer root = _panes.Loader.GetRootId(); List <EventAction> eas = root.EventHandlers; if (eas != null) { ComponentIconEventhandle h = ci as ComponentIconEventhandle; if (h != null) { foreach (EventAction ea in eas) { if (ea.TaskIDList != null) { bool b = false; foreach (TaskID tid in ea.TaskIDList) { HandlerMethodID hid = tid as HandlerMethodID; if (hid != null) { if (hid.ActionId == h.MethodId) { listBoxActions.Items.Add(tid); b = true; break; } } } if (b) { break; } } } } else { Dictionary <UInt32, IAction> acts = root.GetActions(); if (acts != null) { ComponentIconMethod cim = ci as ComponentIconMethod; if (cim != null) { foreach (IAction a in acts.Values) { if (a != null && a.IsPublic) { CustomMethodPointer cmp = a.ActionMethod as CustomMethodPointer; if (cmp != null) { if (cmp.MemberId == cim.MethodId) { listBoxActions.Items.Add(a); } } } } } else { ComponentIconProperty cip = ci as ComponentIconProperty; if (cip != null) { foreach (IAction a in acts.Values) { if (a != null && a.IsPublic) { if (cip.Property.IsActionOwner(a)) { listBoxActions.Items.Add(a); } } } } else { ComponentIconClass cic = ci as ComponentIconClass; if (cic != null) { foreach (IAction a in acts.Values) { if (a != null && a.IsPublic) { if (cic.IsActionExecuter(a, root)) { listBoxActions.Items.Add(a); } } } } else { ComponentIconClassType cict = ci as ComponentIconClassType; if (cict != null) { foreach (IAction a in acts.Values) { if (a != null && a.IsPublic) { if (cict.IsActionExecuter(a, root)) { listBoxActions.Items.Add(a); } } } } else { ComponentIconEvent cie = ci as ComponentIconEvent; if (cie != null && cie.IsForComponent) { foreach (IAction a in acts.Values) { if (a != null && a.IsPublic) { if (cie.IsActionExecuter(a, root)) { listBoxActions.Items.Add(a); } } } } } } } } } } } } }
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); }