Beispiel #1
0
        public void StopProcess(long sessionId)
        {
            var processInstance = GetProcessInstance(sessionId);

            processInstance.Kill();
            ProcessInstances.Remove(sessionId);
        }
Beispiel #2
0
    public static NameValueCollection GetDataFields(int wfId)
    {
        NameValueCollection dataFields = new NameValueCollection();

        WorkflowManagementServer svr = new WorkflowManagementServer(K2ServerName, uint.Parse(K2ServerPort));

        try
        {
            svr.Open();
            ProcessInstances ss = svr.GetProcessInstances(wfId);
            // ss[0].Process.DataFields

            //foreach (ProcessDataField item in dfs)
            //{
            //    dataFields.Add(item.Name, item.MetaData);
            //}
        }
        catch (Exception ex)
        {
        }
        finally
        {
            svr.Connection.Close();
        }
        return(dataFields);
    }
        //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();
        }
Beispiel #4
0
 private ProcessInstance GetProcessInstance(long sessionId)
 {
     if (ProcessInstances.ContainsKey(sessionId))
     {
         return(ProcessInstances[sessionId]);
     }
     else
     {
         throw new InvalidOperationException($"Brak procesu o Session Id: {sessionId}");
     }
 }
Beispiel #5
0
        private void RunGotoActivity(DataTable results = null)
        {
            int    processInstanceId = base.GetIntProperty(Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId);
            bool   ignoreProcessInstanceNotExists = base.GetBoolProperty(Constants.SOProperties.ProcessInstanceManagement.IgnoreProcessInstanceNotExists);
            string activityName       = base.GetStringProperty(Constants.SOProperties.ProcessInstanceManagement.ActivityName);
            string activitySystemName = String.Empty;
            bool   gotoActivityResult = false;

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                ProcessInstanceCriteriaFilter filter = new ProcessInstanceCriteriaFilter();
                filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, processInstanceId);
                ProcessInstances procInsts = mngServer.GetProcessInstancesAll(filter);
                if (!ignoreProcessInstanceNotExists & procInsts.Count == 0)
                {
                    throw new ApplicationException(String.Format(Resources.ProcessInstanceNotFound, processInstanceId));
                }

                if (procInsts.Count > 0)
                {
                    int procId = procInsts[0].ProcID;
                    processInstanceId = procInsts[0].ID;

                    Activities procActivities = mngServer.GetProcActivities(procId);

                    foreach (Activity act in procActivities)
                    {
                        if (act.DisplayName == activityName || act.Name == activityName)
                        {
                            activitySystemName = act.Name;
                        }
                    }

                    if (string.IsNullOrEmpty(activitySystemName))
                    {
                        throw new ApplicationException(String.Format(Resources.RequiredPropertyNotFound, activityName));
                    }

                    gotoActivityResult = mngServer.GotoActivity(processInstanceId, activitySystemName);
                }
            }
            if (results != null)
            {
                DataRow row = results.NewRow();
                row[Constants.SOProperties.ProcessInstanceManagement.ActivityName]       = activityName + " (" + activitySystemName + ")";
                row[Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId]  = processInstanceId;
                row[Constants.SOProperties.ProcessInstanceManagement.GoToActivityResult] = gotoActivityResult;
                results.Rows.Add(row);
            }
        }
Beispiel #6
0
        public void ProcessData()
        {
            // Get the specified process set
            ProcessSet procSet = ManagementServer.GetProcSet(1);

            //Load the processes in the process set
            procSet.Processes = ManagementServer.GetProcessVersions(procSet.ProcSetID);
            // Gets the Process of the procset based on the ProcID/Index
            Process process = procSet.Processes[1];
            //OR
            Processes processes = ManagementServer.GetProcesses(procSet.ProcSetID);

            // Gets all the Process Instances for this process
            ProcessInstances processInstances = ManagementServer.GetProcessInstances(process.ProcID);
        }
Beispiel #7
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));
            }
        }
Beispiel #8
0
        private void GotoActivity()
        {
            int    processInstanceId = base.GetIntProperty(Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId);
            string activityName      = base.GetStringProperty(Constants.SOProperties.ProcessInstanceManagement.ActivityName);

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                ProcessInstanceCriteriaFilter filter = new ProcessInstanceCriteriaFilter();
                filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, processInstanceId);
                ProcessInstances procInsts = mngServer.GetProcessInstancesAll(filter);
                if (procInsts.Count == 0)
                {
                    throw new ApplicationException(String.Format(Resources.ProcessInstanceNotFound, processInstanceId));
                }
                mngServer.GotoActivity(procInsts[0].ID, activityName);
            }
        }
Beispiel #9
0
        private void ListActivities()
        {
            int  processInstanceId    = base.GetIntProperty(Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId);
            bool includeStartActivity = base.GetBoolProperty(Constants.SOProperties.ProcessInstanceManagement.IncludeStartActivity);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

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

                ProcessInstanceCriteriaFilter filter = new ProcessInstanceCriteriaFilter();
                filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, processInstanceId);
                ProcessInstances procInsts = mngServer.GetProcessInstancesAll(filter);
                if (procInsts.Count == 0)
                {
                    throw new ApplicationException(String.Format("Sorry, process instance with id {0} not found.", processInstanceId));
                }

                foreach (Activity actvt in mngServer.GetProcActivities(procInsts[0].ProcID))
                {
                    if (actvt.IsStart && !includeStartActivity)
                    {
                        continue;
                    }
                    DataRow row = results.NewRow();
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityID]               = actvt.ID;
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityName]             = actvt.Name;
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityDescription]      = actvt.Description;
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityExpectedDuration] = actvt.ExpectedDuration;
                    row[Constants.SOProperties.ProcessInstanceManagement.IsStartActivity]          = actvt.IsStart;
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityMetaData]         = actvt.MetaData;
                    row[Constants.SOProperties.ProcessInstanceManagement.ActivityPriority]         = actvt.Priority;
                    results.Rows.Add(row);
                }
            }
        }
Beispiel #10
0
        private void GotoActivity()
        {
            int    processInstanceId = base.GetIntProperty(Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId);
            string activityName      = base.GetStringProperty(Constants.SOProperties.ProcessInstanceManagement.ActivityName);

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

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

                ProcessInstanceCriteriaFilter filter = new ProcessInstanceCriteriaFilter();
                filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, processInstanceId);
                ProcessInstances procInsts = mngServer.GetProcessInstancesAll(filter);
                if (procInsts.Count == 0)
                {
                    throw new ApplicationException(String.Format("Sorry, process instance with id {0} not found.", processInstanceId));
                }
                mngServer.GotoActivity(procInsts[0].ID, activityName);
            }
        }
        //sample that shows how to manage process instances
        //in this sample, we want to stop all instances of a particular workflow
        public void ManageProcessInstances()
        {
            //establish the connection
            WorkflowManagementServer K2Mgmt = new WorkflowManagementServer();

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

            //first, get the ID's of all the  process instances of the workflow
            ProcessInstances procInstances = K2Mgmt.GetProcessInstancesAll("workflowfullname", "", ""); //leaving parameters blank effectively ignores that parameter

            foreach (ProcessInstance procInst in procInstances)
            {
                if (procInst.Status == "Active")
                {
                    K2Mgmt.StopProcessInstances(procInst.ID);
                }
            }

            //close the connection
            K2Mgmt.Connection.Close();
        }
Beispiel #12
0
        private void GotoActivity()
        {
            int    processInstanceId  = base.GetIntProperty(Constants.SOProperties.ProcessInstanceManagement.ProcessInstanceId);
            string activityName       = base.GetStringProperty(Constants.SOProperties.ProcessInstanceManagement.ActivityName);
            string activitySystemName = String.Empty;

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                ProcessInstanceCriteriaFilter filter = new ProcessInstanceCriteriaFilter();
                filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, Comparison.Equals, processInstanceId);
                ProcessInstances procInsts = mngServer.GetProcessInstancesAll(filter);
                if (procInsts.Count == 0)
                {
                    throw new ApplicationException(String.Format(Resources.ProcessInstanceNotFound, processInstanceId));
                }

                int        procId         = procInsts[0].ProcID;
                Activities procActivities = mngServer.GetProcActivities(procId);

                foreach (Activity act in procActivities)
                {
                    if (act.DisplayName == activityName || act.Name == activityName)
                    {
                        activitySystemName = act.Name;
                    }
                }

                if (string.IsNullOrEmpty(activitySystemName))
                {
                    throw new ApplicationException(String.Format(Resources.RequiredPropertyNotFound, activityName));
                }

                mngServer.GotoActivity(procInsts[0].ID, activitySystemName);
            }
        }