private void ListZoneUsers() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { List <string> userList = mngServer.ZoneListUsers(ZoneName); foreach (string user in userList) { DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.FQN] = user; dRow[Constants.SOProperties.WorkingHoursConfiguration.UserName] = Helper.DeleteLabel(user); results.Rows.Add(dRow); } } } }
private bool CheckConnection(bool display) { bool result = false; var workflowManagementServer = new WorkflowManagementServer(); try { if (string.IsNullOrEmpty(txtServerName.Text) || string.IsNullOrEmpty(txtServerPort.Text.ToString())) { this.DisplayError("Enter servername and port", "ServerName or Port empty"); return(result); } ConnectionBuilder = new SCConnectionStringBuilder(); ConnectionBuilder.Host = txtServerName.Text; ConnectionBuilder.Port = uint.Parse(txtServerPort.Text); ConnectionBuilder.IsPrimaryLogin = true; ConnectionBuilder.Integrated = chkIntegratedSecurity.Checked; if (!string.IsNullOrEmpty(txtUserName.Text)) { if (string.IsNullOrEmpty(txtServerName.Text) || string.IsNullOrEmpty(txtServerPort.Text.ToString())) { this.DisplayError("Enter servername and port", "ServerName or Port empty"); return(result); } ConnectionBuilder.UserID = txtUserName.Text; ConnectionBuilder.Password = txtUserPassword.Text; ConnectionBuilder.SecurityLabelName = txtLabel.Text; ConnectionBuilder.WindowsDomain = txtDomain.Text; } workflowManagementServer.CreateConnection(); workflowManagementServer.Connection.Open(ConnectionBuilder.ConnectionString); if (display) { this.DisplayInfo("Connection to '" + txtServerName.Text + "' succeeded", "Connection succeeded"); } btnOK.Enabled = true; result = true; } catch (Exception ex) { this.DisplayError("Connection Failed to '" + txtServerName.Text + ":" + txtServerPort.Text + "' Message: " + ex.Message, "Connection Failed"); btnOK.Enabled = false; result = false; } finally { this.Stop(); workflowManagementServer?.Connection?.Dispose(); } return(result); }
private void LoadZone() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { AvailabilityZone aZone = mngServer.ZoneLoad(ZoneName); DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = aZone.ZoneName; dRow[Constants.SOProperties.WorkingHoursConfiguration.DefaultZone] = aZone.DefaultZone; dRow[Constants.SOProperties.WorkingHoursConfiguration.GMTOffset] = aZone.ZoneGMTOffset; dRow[Constants.SOProperties.WorkingHoursConfiguration.Description] = aZone.ZoneDescription; results.Rows.Add(dRow); } } }
private void btnDuplicate_Click(object sender, EventArgs e) { try { Connection cnx = new Connection(); cnx.Open(ConfigurationManager.AppSettings["K2ServerName"]); SourceCode.Workflow.Client.ProcessInstance pi = cnx.CreateProcessInstance(txtProcessFullName.Text); pi.Folio = txtFolio.Text; foreach (DataGridViewRow item in dgvDatafields.Rows) { pi.DataFields[item.Cells[0].Value.ToString()].Value = item.Cells[1].Value.ToString(); } cnx.StartProcessInstance(pi); int newProcId = pi.ID; cnx.Close(); if (ddlActivities.SelectedIndex > 1) { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.CreateConnection(); wms.Connection.Open(ConfigurationManager.AppSettings["K2MgmCnxString"]); wms.GotoActivity(newProcId, ddlActivities.SelectedItem.ToString()); wms.Connection.Close(); } MessageBox.Show("L'instance à été dupliquée. (ID: " + newProcId.ToString() + ")", "PI Management"); } catch (Exception ex) { MessageBox.Show(ex.Message, "PI Manager eror"); } }
/// <summary> /// 跳转 /// </summary> /// <param name="procInstID"></param> /// <param name="activityName"></param> /// <returns></returns> bool GoToActitvy(int procInstID, string activityName) { WorkflowManagementServer svr = new WorkflowManagementServer(); svr.CreateConnection(); svr.Connection.Open(WorkflowHelper.GetConnString4Management()); bool flag = svr.GotoActivity(procInstID, activityName); svr.Connection.Close(); return(flag); }
//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(); }
protected override void BeginProcessing() { try { wfMan.CreateConnection(); wfMan.Connection.Open(ModuleHelper.BuildConnectionString()); } catch (Exception ex) { ErrorHelper.Write(ex); } }
private void UserDeleteZone() { string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, true); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); mngServer.UserDeleteZone(FQN); } }
private void ConnectWorkflowManagementServer(WorkflowManagementServer workflowManagementServer, string connectionString) { if (workflowManagementServer.Connection == null) { workflowManagementServer.CreateConnection(); } if (!workflowManagementServer.Connection.IsConnected) { workflowManagementServer.Connection.Open(connectionString); } }
public override List<ServiceObject> DescribeServiceObjects() { ServiceObject so = Helper.CreateServiceObject("ProcessInstanceClient", "Exposes functionality to start the workflow."); so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ProcessInstanceClient.ProcessFolio, SoType.Text, "The folio to use for the process.")); so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ProcessInstanceClient.ProcessName, SoType.Text, "The full name of the process.")); so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ProcessInstanceClient.StartSync, SoType.YesNo, "Start the process synchronously or not.")); so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ProcessInstanceClient.ProcessInstanceId, SoType.Number, "The process instance ID.")); so.Properties.Add(Helper.CreateProperty(Constants.SOProperties.ProcessInstanceClient.ProcessVersion, SoType.Number, "The version number to start. Leave empty for default.")); Method startProcessInstance = Helper.CreateMethod(Constants.Methods.ProcessInstanceClient.StartProcessInstance, "Start a new process instance", MethodType.Create); startProcessInstance.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessName); startProcessInstance.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessFolio); startProcessInstance.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessVersion); startProcessInstance.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.StartSync); startProcessInstance.Validation.RequiredProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessName); startProcessInstance.ReturnProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessInstanceId); startProcessInstance.ReturnProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessFolio); so.Methods.Add(startProcessInstance); //Adding a separate StartWF method for each workflow, exposing DataFields as Parameters WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); ProcessSets pSets = mngServer.GetProcSets(); foreach (ProcessSet pSet in pSets) { string displayName = Constants.Methods.ProcessInstanceClient.StartProcess + "_" + pSet.FullName; string description = "Starts " + pSet.FullName; Method m = new Method { Name = pSet.FullName, Type = MethodType.Create, MetaData = new MetaData(displayName, description) }; m.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessFolio); m.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.StartSync); m.InputProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessVersion); m.ReturnProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessInstanceId); m.ReturnProperties.Add(Constants.SOProperties.ProcessInstanceClient.ProcessFolio); foreach (ProcessDataField pDataField in mngServer.GetProcessDataFields(pSet.ProcID)) { m.MethodParameters.Add(Helper.CreateParameter(pDataField.Name, GetDataFieldType(pDataField.Type), false, pDataField.Name)); } so.Methods.Add(m); } } return new List<ServiceObject>() { so }; }
private void displayActivity() { ddlActivities.Items.Clear(); WorkflowManagementServer wms = new WorkflowManagementServer(); wms.CreateConnection(); wms.Connection.Open(ConfigurationManager.AppSettings["K2MgmCnxString"]); ddlActivities.Items.Add("Do nothing"); ddlActivities.Items.Add("---------------------"); foreach (Activity item in wms.GetProcInstActivities(int.Parse(txtProcInstanceId.Text))) { ddlActivities.Items.Add(item.Name); } wms.Connection.Close(); }
private void SaveZone() { string CurrentZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string NewZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.NewZoneName); Property DescriptionProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.Description]; Property GMTOffsetProperty = ServiceBroker.Service.ServiceObjects[0].Properties[Constants.SOProperties.WorkingHoursConfiguration.GMTOffset]; int GmtOffSet = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.GMTOffset); bool DefaultZone = base.GetBoolProperty(Constants.SOProperties.WorkingHoursConfiguration.DefaultZone); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!String.IsNullOrEmpty(NewZoneName) && !Helper.SpecialCharactersExist(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.SpecialCharactersAreNotAllowed); } else if (!String.IsNullOrEmpty(NewZoneName) && mngServer.ZoneExists(NewZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneExists + NewZoneName + "."); } else if (!mngServer.ZoneExists(CurrentZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + CurrentZoneName + "."); } else if (GmtOffSet > 13 || GmtOffSet < -13) { throw new ApplicationException(Constants.ErrorMessages.GMTOffSetValidationFailed); } else { AvailabilityZone aZone = mngServer.ZoneLoad(CurrentZoneName); aZone.ZoneName = String.IsNullOrEmpty(NewZoneName) ? CurrentZoneName : NewZoneName; if ((DescriptionProperty.Value != null) || (DescriptionProperty.IsClear)) { aZone.ZoneDescription = DescriptionProperty.Value == null ? String.Empty : DescriptionProperty.Value as string; } if ((GmtOffSet != 0) || (GMTOffsetProperty.IsClear)) { aZone.ZoneGMTOffset = GmtOffSet; } aZone.DefaultZone = DefaultZone; //even if the value is false, you cannot make a zone nonDefault without setting other zone to default mngServer.ZoneSave(CurrentZoneName, aZone); } } }
private void ReleaseWorklistItem() { int worklistItemId = base.GetIntProperty(Constants.SOProperties.ManagementWorklist.WorklistItemId, true); 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); mngServer.ReleaseWorklistItem(worklistItemId); } }
private void UserGetZone() { string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, true); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = mngServer.UserGetZone(FQN); results.Rows.Add(dRow); } }
private void GetDefaultZone() { base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); string defaultZone = mngServer.ZoneGetDefault(); DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = defaultZone; results.Rows.Add(dRow); } }
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)); } }
//sample that shows how to set workflow permissions //in this sample, we are giving a dummy user account rights to a dummy process public void SetWorkflowPermissions() { //establish the connection WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); K2Mgmt.CreateConnection(); K2Mgmt.Connection.Open("connectionstring"); //get the proc set ID of the workflow whose permissions we need to 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 that we have the proc set ID, we can apply permissions //build up a collection of permissions to apply to the workflow Permissions permissions = new Permissions(); //create a ProcSetPermission object - this object will be added to the Permissions collection ProcSetPermissions procPermissions = new ProcSetPermissions(); procPermissions.ProcSetID = procSetId; procPermissions.UserName = @"domain\username"; //could also be ProcPermissions.GroupName for a group procPermissions.Admin = true; procPermissions.Start = true; procPermissions.View = true; procPermissions.ViewPart = false; procPermissions.ServerEvent = false; //add the permission to the permissions collection permissions.Add(procPermissions); procPermissions = null; //now we can apply the updated set of permissions to the process K2Mgmt.UpdateProcPermissions(procSetId, permissions); //several other methods are also available, listed below. Check product documentation for more information //K2Mgmt.UpdateGroupPermissions(); //K2Mgmt.UpdateOrAddProcUserPermissions(); //K2Mgmt.UpdateProcGroupPermissions(); //K2Mgmt.UpdateProcUserPermissions(); //close the connection K2Mgmt.Connection.Close(); }
private void ListZones() { base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); List <string> zoneList = mngServer.ZoneListAll(); foreach (string zone in zoneList) { DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = zone; results.Rows.Add(dRow); } } }
private void SetDefaultZone() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { mngServer.ZoneSetDefault(ZoneName); } } }
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); } } }
private void ZoneCalculateEvent() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string Start = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.StartDateTime, true); int DurationHours = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.DurationHours); int DurationMinutes = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.DurationMinutes); int DurationSeconds = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.DurationSeconds); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { TimeSpan Duration = new TimeSpan(DurationHours, DurationMinutes, DurationSeconds); DateTime dt; if (!DateTime.TryParse(Start, out dt)) { throw new ApplicationException(Constants.ErrorMessages.DateNotValid); } AvailabilityZone zone = mngServer.ZoneLoad(ZoneName); if (zone.AvailabilityHoursList == null || zone.AvailabilityHoursList.Count == 0) { throw new ApplicationException(Constants.ErrorMessages.WorkingHoursNotSet); } DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.FinishDateTime] = mngServer.ZoneCalculateEvent(ZoneName, dt, Duration); results.Rows.Add(dRow); } } }
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); } }
private void SetStatus(UserStatuses status) { string userFQN = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); // None for userstatus means the users is not configured, throw an exception if (UserStatuses.None == mngServer.GetUserStatus(userFQN)) { throw new ApplicationException(Constants.ErrorMessages.OutOfOfficeNotConfiguredForUser); } bool result = mngServer.SetUserStatus(userFQN, status); if (!result) { throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF); } } }
//sample that shows how to list workflows in error state //in this sample, we just want to output all workflows that are in error state public void ListErrors() { //establish the connection WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); K2Mgmt.CreateConnection(); K2Mgmt.Connection.Open("connectionstring"); //first get the error profile ID., In this case, we will use the default "All" profile int errorProfileId = K2Mgmt.GetErrorProfile("All").ID; ErrorLogs K2Errors = K2Mgmt.GetErrorLogs(errorProfileId); //you can also construct a criteria filter to filter the error profile further. foreach (ErrorLog K2Error in K2Errors) { //Do something with the error log entry Console.WriteLine(K2Error.Description); } //close the connection K2Mgmt.Connection.Close(); }
//sample that shows how to repair error on a K2 server //in this sample, we want to attempt the "Retry" statement on all workflows currently in Error state //be careful doing this on a server with many errored process instances, since executing more than about 20 Retry statements in a very short interval can cause //the K2 server to slow down significantly public void RepairErrors() { //establish the connection WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); K2Mgmt.CreateConnection(); K2Mgmt.Connection.Open("connectionstring"); //first get the error profile ID., In this case, we will use the default "All" profile int errorProfileId = K2Mgmt.GetErrorProfile("All").ID; ErrorLogs K2Errors = K2Mgmt.GetErrorLogs(errorProfileId); //you can also construct a criteria filter to filter the error profile further. foreach (ErrorLog K2Error in K2Errors) { //Do something with the error log entry K2Mgmt.RetryError(K2Error.ProcInstID, K2Error.ID, @"domain\username"); } //close the connection K2Mgmt.Connection.Close(); }
private void RedirectWorklistItem() { string fromUser = base.GetStringProperty(Constants.SOProperties.ManagementWorklist.FromUser, false); string toUser = base.GetStringProperty(Constants.SOProperties.ManagementWorklist.ToUser, true); int procInstId = base.GetIntProperty(Constants.SOProperties.ManagementWorklist.ProcessInstanceId, true); int actInstId = base.GetIntProperty(Constants.SOProperties.ManagementWorklist.ActivityInstanceDestinationId, true); int worklistItemId = base.GetIntProperty(Constants.SOProperties.ManagementWorklist.WorklistItemId, true); 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); mngServer.RedirectWorklistItem(fromUser, toUser, procInstId, actInstId, worklistItemId); } }
//sample that shows how to manage worklist items. //In this sample, we want to redirect all tasks from one user to another user public void ManageWorklistItems() { //establish the connection WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); K2Mgmt.CreateConnection(); K2Mgmt.Connection.Open("connectionstring"); //build up a filter for the list of worklist items. Here, we want to return all the worklist items for a specific user WorklistCriteriaFilter wlCritFilter = new WorklistCriteriaFilter(); wlCritFilter.AddRegularFilter(WorklistFields.Destination, Comparison.Like, "%user1%"); WorklistItems wlItems = K2Mgmt.GetWorklistItems(wlCritFilter); foreach (WorklistItem wlItem in wlItems) { K2Mgmt.RedirectWorklistItem("user1", "user2", wlItem.ProcInstID, wlItem.ActInstDestID, wlItem.ID); } //close the connection K2Mgmt.Connection.Close(); }
//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(); }
private void GetErrors() { string profile = base.GetStringProperty(Constants.SOProperties.ErrorLog.Profile); if (string.IsNullOrEmpty(profile)) { profile = "All"; } base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); //TODO: catch exception on this? ErrorProfile prof = mngServer.GetErrorProfile(profile); ErrorLogs errors = mngServer.GetErrorLogs(prof.ID); foreach (ErrorLog e in errors) { DataRow r = results.NewRow(); r[Constants.SOProperties.ErrorLog.ProcessInstanceId] = e.ProcInstID; r[Constants.SOProperties.ErrorLog.ProcessName] = e.ProcessName; r[Constants.SOProperties.ErrorLog.Folio] = e.Folio; r[Constants.SOProperties.ErrorLog.ErrorDescription] = e.Description; r[Constants.SOProperties.ErrorLog.ErrorItem] = e.ErrorItemName; r[Constants.SOProperties.ErrorLog.ErrorDate] = e.ErrorDate; r[Constants.SOProperties.ErrorLog.ErrorId] = e.ID; r[Constants.SOProperties.ErrorLog.TypeDescription] = e.TypeDescription; r[Constants.SOProperties.ErrorLog.ExecutingProcId] = e.ExecutingProcID; r[Constants.SOProperties.ErrorLog.StackTrace] = e.StackTrace; results.Rows.Add(r); } } }
private void CreateZone() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string Description = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.Description); int GmtOffSet = base.GetIntProperty(Constants.SOProperties.WorkingHoursConfiguration.GMTOffset, true); bool DefaultZone = base.GetBoolProperty(Constants.SOProperties.WorkingHoursConfiguration.DefaultZone); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!Helper.SpecialCharactersExist(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.SpecialCharactersAreNotAllowed); } else if (mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneExists + ZoneName + "."); } else if (GmtOffSet > 13 || GmtOffSet < -13) { throw new ApplicationException(Constants.ErrorMessages.GMTOffSetValidationFailed); } else { AvailabilityZone aZone = new AvailabilityZone(); aZone.ZoneName = ZoneName; aZone.ID = Guid.NewGuid(); aZone.ZoneDescription = Description; aZone.ZoneGMTOffset = GmtOffSet; aZone.DefaultZone = DefaultZone; mngServer.ZoneCreateNew(aZone); } } }
//sample that shows how to use Out-of-Office in the workflow management API //in this example, we just want to output all users that are currently out-of-office public void ListOutOfOfficeUsers() { //establish the connection WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); K2Mgmt.CreateConnection(); K2Mgmt.Connection.Open("connectionstring"); SourceCode.Workflow.Management.OOF.Users OOFUsers = K2Mgmt.GetUsers(ShareType.OOF); foreach (SourceCode.Workflow.Management.OOF.User OOFUser in OOFUsers) { WorklistShares wlss = K2Mgmt.GetCurrentSharingSettings(OOFUser.FQN, ShareType.OOF); foreach (WorklistShare wls in wlss) { //do something with each "share" record Console.WriteLine("User Name: " + OOFUser.FQN); Console.WriteLine("Start Date: " + wls.StartDate.ToString()); Console.WriteLine("End Date: " + wls.EndDate.ToString()); } } //close the connection K2Mgmt.Connection.Close(); }
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); } } }
private void ListUsers() { 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); SourceCode.Workflow.Management.OOF.Users users = mngServer.GetUsers(ShareType.OOF); foreach (SourceCode.Workflow.Management.OOF.User user in users) { if (user.Status != UserStatuses.None) { WorklistShares wsColl = mngServer.GetCurrentSharingSettings(user.FQN, ShareType.OOF); foreach (WorklistShare ws in wsColl) { foreach (WorkType wt in ws.WorkTypes) { foreach (Destination dest in wt.Destinations) { DataRow dr = results.NewRow(); dr[Constants.SOProperties.OutOfOffice.UserFQN] = user.FQN; dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name; results.Rows.Add(dr); } } } } } } }
private void RedirectWorklistItem() { string fromUser = base.GetStringProperty(Constants.Properties.ManagementWorklist.FromUser, false); string toUser = base.GetStringProperty(Constants.Properties.ManagementWorklist.ToUser, true); int procInstId = base.GetIntProperty(Constants.Properties.ManagementWorklist.ProcessInstanceId, true); int actInstId = base.GetIntProperty(Constants.Properties.ManagementWorklist.ActivityInstanceDestinationId, true); int worklistItemId = base.GetIntProperty(Constants.Properties.ManagementWorklist.WorklistItemId, true); 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); mngServer.RedirectWorklistItem(fromUser, toUser, procInstId, actInstId, worklistItemId); } }
private void GetWorklist() { 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); WorklistCriteriaFilter filter = new WorklistCriteriaFilter(); WorklistItems wlItems = mngServer.GetWorklistItems(filter); foreach (WorklistItem wlItem in wlItems) { DataRow row = CreateWorklistItemRow(results, wlItem); results.Rows.Add(row); } } }
private void ListZones() { base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); List<string> zoneList = mngServer.ZoneListAll(); foreach (string zone in zoneList) { DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = zone; results.Rows.Add(dRow); } } }
private void btnDuplicate_Click(object sender, EventArgs e) { try { Connection cnx = new Connection(); cnx.Open(ConfigurationManager.AppSettings["K2ServerName"]); SourceCode.Workflow.Client.ProcessInstance pi = cnx.CreateProcessInstance(txtProcessFullName.Text); pi.Folio = txtFolio.Text; foreach (DataGridViewRow item in dgvDatafields.Rows) { pi.DataFields[item.Cells[0].Value.ToString()].Value = item.Cells[1].Value.ToString(); } cnx.StartProcessInstance(pi); int newProcId= pi.ID; cnx.Close(); if (ddlActivities.SelectedIndex > 1) { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.CreateConnection(); wms.Connection.Open(ConfigurationManager.AppSettings["K2MgmCnxString"]); wms.GotoActivity(newProcId, ddlActivities.SelectedItem.ToString()); wms.Connection.Close(); } MessageBox.Show("L'instance à été dupliquée. (ID: " + newProcId.ToString() + ")", "PI Management"); } catch (Exception ex) { MessageBox.Show(ex.Message, "PI Manager eror"); } }
// Example from page - http://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.6.9/default.htm#How_to_set_a_users_Out_of_Office_Status.html%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520Client%2520API%7CWorkflow%2520Client%2520API%2520Samples%7C_____10 private void AddOutOfOffice() { string userFQN = base.GetStringProperty(Constants.Properties.OutOfOffice.UserFQN); string destinationUser = base.GetStringProperty(Constants.Properties.OutOfOffice.DestinationUser); 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); WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF); // Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that if (wsColl.Count > 1) { throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations); } // If configuration exist already, add to it if (wsColl.Count == 1) { WorklistShare worklistshare = wsColl[0]; worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User)); bool result = mngServer.ShareWorkList(userFQN, worklistshare); DataRow dr = results.NewRow(); dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN; dr[Constants.Properties.OutOfOffice.DestinationUser] = destinationUser; dr[Constants.Properties.OutOfOffice.CallSuccess] = result; results.Rows.Add(dr); ; } // New user, create configuration for OOF else { // ALL Work that remains which does not form part of any "WorkTypeException" Filter WorklistCriteria worklistcriteria = new WorklistCriteria(); worklistcriteria.Platform = "ASP"; // Send ALL Work based on the above Filter to the following User Destinations worktypedestinations = new Destinations(); worktypedestinations.Add(new Destination(destinationUser, DestinationType.User)); // Link the filters and destinations to the Work WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations); WorklistShare worklistshare = new WorklistShare(); worklistshare.ShareType = ShareType.OOF; worklistshare.WorkTypes.Add(worktype); bool result = mngServer.ShareWorkList(userFQN, worklistshare); mngServer.SetUserStatus(userFQN, UserStatuses.Available); DataRow dr = results.NewRow(); dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN; dr[Constants.Properties.OutOfOffice.DestinationUser] = destinationUser; dr[Constants.Properties.OutOfOffice.CallSuccess] = result; results.Rows.Add(dr); } } }
private void ListZoneUsers() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { List<string> userList = mngServer.ZoneListUsers(ZoneName); foreach (string user in userList) { DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.FQN] = user; dRow[Constants.SOProperties.WorkingHoursConfiguration.UserName] = Helper.DeleteLabel(user); results.Rows.Add(dRow); } } } }
private void GetUserStatus() { string userFQN = base.GetStringProperty(Constants.Properties.OutOfOffice.UserFQN); 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); UserStatuses status = mngServer.GetUserStatus(userFQN); DataRow dr = results.NewRow(); dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN; dr[Constants.Properties.OutOfOffice.UserStatus] = status.ToString(); results.Rows.Add(dr); } }
private void ListSharedUsers() { string userFQN = base.GetStringProperty(Constants.Properties.OutOfOffice.UserFQN); 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); // None for userstatus means the users is not configured, throw an exception if (UserStatuses.None == mngServer.GetUserStatus(userFQN)) throw new ApplicationException(Constants.ErrorMessages.OutOfOfficeNotConfiguredForUser); WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF); foreach (WorklistShare ws in wsColl) { //throw new ApplicationException("collection count is: "+ wsColl.Count.ToString()); foreach (WorkType wt in ws.WorkTypes) { foreach (Destination dest in wt.Destinations) { DataRow dr = results.NewRow(); dr[Constants.Properties.OutOfOffice.DestinationUser] = dest.Name.ToString(); results.Rows.Add(dr); } } } } }
private void UserSetZone() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, true); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Constants.ErrorMessages.ZoneDoesNotExist + ZoneName + "."); } else { mngServer.UserSetZone(FQN, ZoneName); } } }
private void SetOutOfOffice() { string userFQN = base.GetStringProperty(Constants.Properties.OutOfOffice.UserFQN); 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); // None for userstatus means the users is not configured, throw an exception if (UserStatuses.None == mngServer.GetUserStatus(userFQN)) throw new ApplicationException(Constants.ErrorMessages.OutOfOfficeNotConfiguredForUser); bool result = mngServer.SetUserStatus(userFQN, UserStatuses.OOF); DataRow dr = results.NewRow(); dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN; dr[Constants.Properties.OutOfOffice.CallSuccess] = result; results.Rows.Add(dr); } }
private void ZoneExists() { string ZoneName = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.ZoneName, true); base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneExists] = mngServer.ZoneExists(ZoneName); results.Rows.Add(dRow); } }
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)); } }
private void GetErrors() { string profile = base.GetStringProperty(Constants.SOProperties.ErrorLog.Profile); if (string.IsNullOrEmpty(profile)) { profile = "All"; } base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); //TODO: catch exception on this? ErrorProfile prof = mngServer.GetErrorProfile(profile); ErrorLogs errors = mngServer.GetErrorLogs(prof.ID); foreach (ErrorLog e in errors) { DataRow r = results.NewRow(); r[Constants.SOProperties.ErrorLog.ProcessInstanceId] = e.ProcInstID; r[Constants.SOProperties.ErrorLog.ProcessName] = e.ProcessName; r[Constants.SOProperties.ErrorLog.Folio] = e.Folio; r[Constants.SOProperties.ErrorLog.ErrorDescription] = e.Description; r[Constants.SOProperties.ErrorLog.ErrorItem] = e.ErrorItemName; r[Constants.SOProperties.ErrorLog.ErrorDate] = e.ErrorDate; r[Constants.SOProperties.ErrorLog.ErrorId] = e.ID; results.Rows.Add(r); } } }
private void ReleaseWorklistItem() { int worklistItemId = base.GetIntProperty(Constants.Properties.ManagementWorklist.WorklistItemId, true); 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); mngServer.ReleaseWorklistItem(worklistItemId); } }