//sample that shows how to perform Live INstance Management
        //in this example, we want to migrate all active instances of a workflow to the latest version
        //Note: take due care when migrating active process instances since not all migration scenarios are supported
        public void LiveInstanceManagementSample()
        {
            //establish the connection
            WorkflowManagementServer K2Mgmt = new WorkflowManagementServer();

            K2Mgmt.CreateConnection();
            K2Mgmt.Connection.Open("connectionstring");

            //get the proc set ID of the workflow so that we can get the latest version of the proc set
            SourceCode.Workflow.Management.Criteria.ProcessCriteriaFilter filter = new SourceCode.Workflow.Management.Criteria.ProcessCriteriaFilter();
            Processes procs = null;

            filter.AddRegularFilter(ProcessFields.ProcessFullName, Comparison.Equals, "processFullName");
            procs = K2Mgmt.GetProcesses(filter);
            int procSetId = procs[0].ProcSetID;

            //now get the latest version of the procset
            int       latestVersion   = 0;
            int       latestVersionId = 0;
            Processes procVersions    = K2Mgmt.GetProcessVersions(procSetId);

            foreach (Process procVersion in procVersions)
            {
                if (procVersion.VersionNumber > latestVersion)
                {
                    latestVersion   = procVersion.VersionNumber;
                    latestVersionId = procVersion.ProcID;
                }
            }

            //now that we have the latest version of the workflow,
            //get the ID's of all the  process instances of the workflow
            ProcessInstances procInstances = K2Mgmt.GetProcessInstancesAll("processFullName", "", ""); //leaving parameters blank effectively ignores that parameter

            foreach (ProcessInstance procInst in procInstances)
            {
                //no need to migrate ones that are already on this version
                if (procInst.ExecutingProcID != latestVersionId)
                {
                    //must stop a non-stopped instance before attempting migration
                    if (procInst.Status != "Stopped")
                    {
                        K2Mgmt.StopProcessInstances(procInst.ID);
                    }
                    //now migrate the instance to the latest version
                    K2Mgmt.SetProcessInstanceVersion(procInst.ID, latestVersion);
                    //restart the process
                    K2Mgmt.StartProcessInstances(procInst.ID);
                }
            }

            //close the connection
            K2Mgmt.Connection.Close();
        }
Пример #2
0
        private void RetryProcess()
        {
            bool newVersion = base.GetBoolProperty(Constants.SOProperties.ErrorLog.TryNewVersion);
            int  procInstId = base.GetIntProperty(Constants.SOProperties.ErrorLog.ProcessInstanceId, true);

            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

            using (mngServer.CreateConnection())
            {
                mngServer.Open(BaseAPIConnectionString);

                ErrorProfile           all         = mngServer.GetErrorProfiles()[0];
                ErrorLogCriteriaFilter errorfilter = new ErrorLogCriteriaFilter();
                errorfilter.AddRegularFilter(ErrorLogFields.ProcInstID, Comparison.Equals, procInstId);
                ErrorLogs errors = mngServer.GetErrorLogs(all.ID, errorfilter);

                if (errors.Count != 1)
                {
                    throw new ApplicationException(string.Format("Could not retrieve process (with id: {0}). Got {1} results.", procInstId, errors.Count));
                }

                int errorId = errors[0].ID;

                if (newVersion)
                {
                    int newVersionNumber = 0;
                    ProcessInstanceCriteriaFilter procFilter = new ProcessInstanceCriteriaFilter();
                    procFilter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, procInstId);
                    ProcessInstances procs          = mngServer.GetProcessInstancesAll(procFilter);
                    Processes        procesVersions = mngServer.GetProcessVersions(procs[0].ProcSetID);
                    foreach (Process proc in procesVersions)
                    {
                        if (proc.VersionNumber > newVersionNumber)
                        {
                            newVersionNumber = proc.VersionNumber;
                        }
                    }
                    mngServer.SetProcessInstanceVersion(procInstId, newVersionNumber);
                }
                mngServer.RetryError(procInstId, errorId, string.Format("Process Retry using {0}", base.ServiceBroker.Service.ServiceObjects[0].Name));
            }
        }
Пример #3
0
        private void RetryProcess()
        {
            bool newVersion = base.GetBoolProperty(Constants.SOProperties.ErrorLog.TryNewVersion);
            int procInstId = base.GetIntProperty(Constants.SOProperties.ErrorLog.ProcessInstanceId, true);

            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();
            using (mngServer.CreateConnection())
            {
                mngServer.Open(BaseAPIConnectionString);

                ErrorProfile all = mngServer.GetErrorProfiles()[0];
                ErrorLogCriteriaFilter errorfilter = new ErrorLogCriteriaFilter();
                errorfilter.AddRegularFilter(ErrorLogFields.ProcInstID, Comparison.Equals, procInstId);
                ErrorLogs errors = mngServer.GetErrorLogs(all.ID, errorfilter);

                if (errors.Count != 1)
                {
                    throw new ApplicationException(string.Format("Could not retrieve process (with id: {0}). Got {1} results.", procInstId, errors.Count));
                }

                int errorId = errors[0].ID;

                if (newVersion)
                {
                    int newVersionNumber = 0;
                    ProcessInstanceCriteriaFilter procFilter = new ProcessInstanceCriteriaFilter();
                    procFilter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, procInstId);
                    ProcessInstances procs = mngServer.GetProcessInstancesAll(procFilter);
                    Processes procesVersions = mngServer.GetProcessVersions(procs[0].ProcSetID);
                    foreach (Process proc in procesVersions)
                    {
                        if (proc.VersionNumber > newVersionNumber)
                            newVersionNumber = proc.VersionNumber;
                    }
                    mngServer.SetProcessInstanceVersion(procInstId, newVersionNumber);
                }
                mngServer.RetryError(procInstId, errorId, string.Format("Process Retry using {0}", base.ServiceBroker.Service.ServiceObjects[0].Name));
            }
        }