public void StartExampleWorkflow() { if (!IsEnabledStartExampleWorkflow()) { return; } ACComponent appRoot = ACUrlCommand("\\AppExample") as ACComponent; if (appRoot == null) { return; } if (appRoot.ConnectionState == ACObjectConnectionState.DisConnected) { return; } string methodName; // 1. Find Workflow-Method ACClassMethod acClassMethod = appRoot.GetACClassMethod("ExampleWorkflow", out methodName); if (acClassMethod == null) { return; } // 2. Create a new Instance of the virtual Method (ACMethod) ACMethod acMethod = appRoot.NewACMethod(methodName); if (acMethod == null) { return; } ACValue paramProgram = acMethod.ParameterValueList.GetACValue(ACProgram.ClassName); ACValue paramInOrder = acMethod.ParameterValueList.GetACValue(InOrder.ClassName); if (paramProgram == null || paramInOrder == null) { return; } using (Database iPlusDB = new Database()) { // 3. Switch database context acClassMethod = acClassMethod.FromIPlusContext <ACClassMethod>(iPlusDB); // 4. Create a new ACProgram-Instance and set the ProgramACClassMethod and WorkflowTypeACClass-Properties. string secondaryKey = Root.NoManager.GetNewNo(iPlusDB, typeof(ACProgram), ACProgram.NoColumnName, ACProgram.FormatNewNo, this); ACProgram program = ACProgram.NewACObject(iPlusDB, null, secondaryKey); program.ProgramACClassMethod = acClassMethod; program.WorkflowTypeACClass = acClassMethod.WorkflowTypeACClass; // 5. Save the ACProgram-Instance to the dabase first: iPlusDB.ACProgram.AddObject(program); if (iPlusDB.ACSaveChanges() == null) { // 6. If ACProgram was sucessfully added to the database, start the workflow: paramProgram.Value = program.ACProgramID; paramInOrder.Value = CurrentInOrder.InOrderID; appRoot.ExecuteMethod(acClassMethod.ACIdentifier, acMethod); } } }
public override void SMStarting() { string csv = GetOrderDataCSV(); if (String.IsNullOrEmpty(csv) || (CountLines <= 0 && SkipIfNoLines)) { if (CurrentACState == ACStateEnum.SMStarting) { CurrentACState = ACStateEnum.SMCompleted; } return; } if (ParentPWGroup != null && this.ContentACClassWF != null) { // 5. RefPAACClassMethod is a reference to the virtual "WriteOrder"-Method ACClassMethod refPAACClassMethod = null; using (ACMonitor.Lock(this.ContextLockForACClassWF)) { refPAACClassMethod = this.ContentACClassWF.RefPAACClassMethod; } if (refPAACClassMethod != null) { PAProcessModule module = ParentPWGroup.AccessedProcessModule; if (module == null) { Msg msg = new Msg("AccessedProcessModule is null", this, eMsgLevel.Error, PWClassName, "SMStarting", 1010); if (IsAlarmActive(ProcessAlarm, msg.Message) == null) { Messages.LogError(this.GetACUrl(), "SMStarting(10)", msg.Message); } OnNewAlarmOccurred(ProcessAlarm, msg, true); SubscribeToProjectWorkCycle(); return; } // 6. With TypeACSignature() you get ACMethod for "WriteOrder" ACMethod paramMethod = refPAACClassMethod.TypeACSignature(); if (!(bool)ExecuteMethod("GetConfigForACMethod", paramMethod, true)) { return; } // 7. Set all necessary parameters paramMethod.ParameterValueList["Content"] = csv; RecalcTimeInfo(); if (CreateNewProgramLog(paramMethod) <= CreateNewProgramLogResult.ErrorNoProgramFound) { return; } _ExecutingACMethod = paramMethod; // 8. Start asynchronous task on PAFOrder. if (!module.TaskInvocationPoint.AddTask(paramMethod, this)) { SubscribeToProjectWorkCycle(); return; } else { UnSubscribeToProjectWorkCycle(); } UpdateCurrentACMethod(); } } // 9. Switch to State SMRunning // (If module.AddTask was exceuted syncronously then state is maybe already Runnning.) if (IsACStateMethodConsistent(ACStateEnum.SMStarting) < ACStateCompare.WrongACStateMethod) { CurrentACState = ACStateEnum.SMRunning; } }
protected override bool HandleExecuteACMethod(out object result, AsyncMethodInvocationMode invocationMode, string acMethodName, ACClassMethod acClassMethod, params object[] acParameter) { result = null; switch (acMethodName) { case "Save": Save(); return(true); case "IsEnabledSave": result = IsEnabledSave(); return(true); case "UndoSave": UndoSave(); return(true); case "IsEnabledUndoSave": result = IsEnabledUndoSave(); return(true); case "Load": Load(acParameter.Count() == 1 ? (Boolean)acParameter[0] : false); return(true); case "IsEnabledLoad": result = IsEnabledLoad(); return(true); case "New": New(); return(true); case "IsEnabledNew": result = IsEnabledNew(); return(true); case "Delete": Delete(); return(true); case "IsEnabledDelete": result = IsEnabledDelete(); return(true); case "Search": Search(); return(true); } return(base.HandleExecuteACMethod(out result, invocationMode, acMethodName, acClassMethod, acParameter)); }