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); } } }
// 11. Implementation of IACMyConfigCache for resetting the local cache (_MyConfiguration) public void ClearMyConfiguration() { using (ACMonitor.Lock(_20015_LockValue)) { _MyConfiguration = null; } HasRules.ValueT = 0; }
static PWOrder() { // 2. Register a ACMethod-Template for this Workflow-Class ACMethod method = new ACMethod(ACStateConst.SMStarting); Dictionary <string, string> paramTranslation = new Dictionary <string, string>(); method.ParameterValueList.Add(new ACValue("SkipIfNoLines", typeof(bool), false, Global.ParamOption.Required)); paramTranslation.Add("SkipIfNoLines", "en{'Skip if no lines'}de{'Überspringe wenn keine Positionen'}"); var wrapper = new ACMethodWrapper(method, "en{'Configuration'}de{'Konfiguration'}", typeof(PWOrder), paramTranslation, null); ACMethod.RegisterVirtualMethod(typeof(PWOrder), ACStateConst.SMStarting, wrapper); // 3. Register static Method-Invocation-Handler for Client/Proxy-Side RegisterExecuteHandler(typeof(PWOrder), HandleExecuteACMethod_PWOrder); }
// 4. Override the Start-Method public override ACMethodEventArgs Start(ACMethod acMethod) { // 5. Read the data context: InOrder inOrder = GetInOrder(acMethod); if (inOrder == null) { return(CreateNewMethodEventArgs(acMethod, Global.ACMethodResultState.Failed)); } using (ACMonitor.Lock(_20015_LockValue)) { _CurrentInOrder = inOrder; } // 6. Call base-Start() to start the Workflow return(base.Start(acMethod)); }
protected InOrder GetInOrder(ACMethod acMethod) { if (acMethod == null) { return(null); } Guid inOrderID = (Guid)acMethod[InOrder.ClassName]; if (inOrderID == Guid.Empty) { return(null); } using (MyCompanyDB dbApp = new MyCompanyDB()) { return(dbApp.InOrder.Where(c => c.InOrderID == inOrderID) .SetMergeOption(System.Data.Objects.MergeOption.NoTracking) .FirstOrDefault()); } }
static PAFOrder() { // 2. Register a ACMethod-Template for this Function ACMethod method = new ACMethod("WriteOrder"); Dictionary <string, string> paramTranslation = new Dictionary <string, string>(); method.ParameterValueList.Add(new ACValue("Path", typeof(string), null, Global.ParamOption.Optional)); paramTranslation.Add("Path", "en{'Path'}de{'Path'}"); method.ParameterValueList.Add(new ACValue("FileName", typeof(string), null, Global.ParamOption.Optional)); paramTranslation.Add("FileName", "en{'FileName'}de{'FileName'}"); method.ParameterValueList.Add(new ACValue("Content", typeof(string), 0, Global.ParamOption.Required)); paramTranslation.Add("Content", "en{'Content'}de{'Content'}"); Dictionary <string, string> resultTranslation = new Dictionary <string, string>(); method.ResultValueList.Add(new ACValue("Duration", typeof(double), 0.0, Global.ParamOption.Required)); resultTranslation.Add("Duration", "en{'Duration[ms]'}de{'Duration[ms]'}"); var wrapper = new ACMethodWrapper(method, "en{'Write order'}de{'Auftrag schreiben'}", typeof(PWOrder), paramTranslation, resultTranslation); ACMethod.RegisterVirtualMethod(typeof(PAFOrder), ACStateConst.TMStart, wrapper); // 3. Register static Method-Invocation-Handler for Client/Proxy-Side RegisterExecuteHandler(typeof(PAFOrder), HandleExecuteACMethod_PAFOrder); }
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; } }
public override ACMethodEventArgs Start(ACMethod acMethod) { return(base.Start(acMethod)); }