/// <summary> /// Launch new task /// </summary> /// <param name="eDesc"></param> private void LaunchTask(CEventDesc eventDesc) { FreeEndedTasks(); Task t = new Task(RunProgram); tasks.Add(eventDesc.Program, t); t.Start(); }
/// <summary> /// Launch task or single thread program /// </summary> /// <param name="eDesc"></param> public object LaunchProgram(CEventDesc eDesc, object program_vars) { bool queued = CProgram.CheckQueuedFlag(eDesc.Program); if ((logic == null) || (!queued)) { // Init program if (Program != null) { sprogram.Push(Program); } Program = new CProgram(sys, sys.Globals, eDesc.Program, program_vars); vm.Cancel_events = true; Program.ExecuteProcess += Program_ExecuteProcess; // Run program if not queued or logic is null if (!Program.hasErrors()) { // Init logic process executor if (logic != null) { slogic.Push(logic); } logic = new CLogic(sys, vm, eDesc); // Run program sync or async if (Program.Parallel_execution) { LaunchTask(eDesc); } else { RunProgram(); } logic = (slogic.Count > 0) ? (CLogic)slogic.Pop() : null; } program_vars = Program.vars; Program.ProgramClose(); vm.Cancel_events = false; Program = (sprogram.Count > 0) ? (CProgram)sprogram.Pop() : null; } else if ((logic != null) && (queued)) { // push program in queue sevent_desc.Push(eDesc); } return(program_vars); }
/// <summary> /// Direct program call /// </summary> /// <param name="eDesc"></param> /// <param name="Program"></param> public void CallProgram(CEventDesc eDesc, String Program) { CEventDesc desc = null; if (getFirstView_byGuid(eDesc.View_Guid) != null) { desc = new CEventDesc(eDesc.View_Guid, eDesc.View_Name, eDesc.Control_Name, "PROGRAM_CALL", Program); } else { desc = new CEventDesc(getMainView().guid, getMainView().Name, "", "PROGRAM_CALL", Program); } debug.add(string.Format("Call program event fired '{0}', program launched '{1}'. From view '{2}' => control '{3}'", desc.Event_Name, desc.Program, desc.View_Name, desc.Control_Name)); if (runProgram != null) { runProgram(desc); } }
CView.CtrlStruct fireCtrl_str; // Controls struct who fire the event #endregion #region initialize /// <summary> /// Load all information from UI to work with /// </summary> /// <param name="viewManager"></param> /// <param name="eventDesc"></param> public CLogic(CSystem csystem, CViewsManager views_manager, CEventDesc eventDesc) { sys = csystem; vm = views_manager; Globals = sys.Globals; errors = sys.ProgramErrors; debug = sys.ProgramDebug; event_desc = eventDesc; if (event_desc != null) { view = (event_desc.View_Guid != "") ? vm.getFirstView_byGuid(event_desc.View_Guid) : null; if (view != null) { mainCtrl = view.mainControl(); fireCtrl_str = view.getCtrlStruct(eventDesc.Control_Name); } fireCtrl = (Control)event_desc.fireCtrl; args = event_desc.args; } MainView = ((view != null) && (Globals.get_str(dGLOBALS.MAIN_VIEW) == view.Name)) ? view : vm.getFirstView(Globals.get_str(dGLOBALS.MAIN_VIEW)); }