Beispiel #1
0
        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);
                }
            }
        }