private void ListSharedUsers() { string userFQN = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN); ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { // None for userstatus means the users is not configured, throw an exception if (mngServer.GetUserStatus(userFQN) == UserStatuses.None) { throw new ApplicationException(Resources.OutOfOfficeNotConfiguredForUser); } WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, 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] = userFQN; dr[Constants.SOProperties.OutOfOffice.DestinationUser] = dest.Name.ToString(); results.Rows.Add(dr); } } } } }
private static DateTime CalculateEscalationDatePrivate(string zoneName, DateTime startDate, int seconds) { WorkflowManagementServer mngServer = null; try { mngServer = new WorkflowManagementServer("localhost", 5555); //fairly safe to do this as inline function runs on K2 Server. mngServer.Open(); //http://www.k2underground.com/forums/p/8275/31827.aspx mngServer.ZoneLoad(zoneName); return mngServer.ZoneCalculateEvent(zoneName, startDate, new TimeSpan(0, 0, 0, seconds)); } catch (Exception ex) { //more detailed error in the k2server logs throw new Exception(string.Format("Error: {0}{1}", ex.Message, ex.StackTrace), ex); } finally { if (mngServer != null) { if (mngServer.Connection != null) { mngServer.Connection.Dispose(); } mngServer = null; } } }
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); }
private void ListUsers() { ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { 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 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); }
public static bool GoToActitvy(int wfId, string activityName) { WorkflowManagementServer svr = new WorkflowManagementServer(K2ServerName, uint.Parse(K2ServerPort)); svr.Open(); return(svr.GotoActivity(wfId, activityName)); }
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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Resources.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 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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { if (!mngServer.ZoneExists(ZoneName)) { throw new ApplicationException(Resources.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"); } }
private void UserCalculateEvent() { string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, 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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { TimeSpan Duration = new TimeSpan(DurationHours, DurationMinutes, DurationSeconds); DateTime dt; if (!DateTime.TryParse(Start, out dt)) { throw new ApplicationException(Resources.DateNotValid); } AvailabilityZone zone = mngServer.ZoneLoad(mngServer.UserGetZone(FQN)); if (zone.AvailabilityHoursList == null || zone.AvailabilityHoursList.Count == 0) { throw new ApplicationException(Resources.WorkingHoursNotSet); } DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.FinishDateTime] = mngServer.UserCalculateEvent(FQN, dt, Duration); results.Rows.Add(dRow); } }
private static DateTime CalculateEscalationDatePrivate(string zoneName, DateTime startDate, int seconds) { WorkflowManagementServer mngServer = null; try { mngServer = new WorkflowManagementServer("localhost", 5555); //fairly safe to do this as inline function runs on K2 Server. mngServer.Open(); //http://www.k2underground.com/forums/p/8275/31827.aspx mngServer.ZoneLoad(zoneName); return(mngServer.ZoneCalculateEvent(zoneName, startDate, new TimeSpan(0, 0, 0, seconds))); } catch (Exception ex) { //more detailed error in the k2server logs throw new Exception(string.Format("Error: {0}{1}", ex.Message, ex.StackTrace), ex); } finally { if (mngServer != null) { if (mngServer.Connection != null) { mngServer.Connection.Dispose(); } mngServer = null; } } }
public static Dictionary <string, int> GetProcActivites(int procID) { Dictionary <string, int> list = new Dictionary <string, int>(); WorkflowManagementServer svr = new WorkflowManagementServer(K2ServerName, uint.Parse(K2ServerPort)); try { svr.Open(); Activities activities = svr.GetProcInstActivities(procID); foreach (Activity activity in activities) { list.Add(activity.Name, activity.ID); } } catch (Exception ex) { } finally { svr.Connection.Close(); } return(list); }
private WorkflowManagementServer GetWorkflowManagementServer(string connectionString) { //Create instance of the workfow management class WorkflowManagementServer workflowManagementServer = new WorkflowManagementServer(); ConnectWorkflowManagementServer(workflowManagementServer, connectionString); return(workflowManagementServer); }
/// <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(); }
private void UserDeleteZone() { string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, true); WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { mngServer.UserDeleteZone(FQN); } }
public void Dispose() { if (_workflowManagementServer != null) { if (_workflowManagementServer.Connection.IsConnected) { _workflowManagementServer.Connection.Close(); _workflowManagementServer.Connection.Dispose(); } _workflowManagementServer = null; } }
private void ConnectWorkflowManagementServer(WorkflowManagementServer workflowManagementServer, string connectionString) { if (workflowManagementServer.Connection == null) { workflowManagementServer.CreateConnection(); } if (!workflowManagementServer.Connection.IsConnected) { workflowManagementServer.Connection.Open(connectionString); } }
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 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); } }
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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { mngServer.ReleaseWorklistItem(worklistItemId); } }
/// <summary> /// 获取流程的全称 /// </summary> /// <returns></returns> public static string GetWorkflowName(string WorkflowTypeName) { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.Open(GetK2ManagementServerConnectionString()); ProcessSets processSets = wms.GetProcSets(); foreach (ProcessSet procSet in processSets) { if (procSet.StringTable == StringTableType && procSet.Name == WorkflowTypeName) { return(procSet.FullName); } } return(""); }
public static string GetK2ProcessFolder() { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.Open(GetK2ManagementServerConnectionString()); ProcessSets processSets = wms.GetProcSets(); foreach (ProcessSet procSet in processSets) { if (procSet.StringTable == StringTableType) { return(procSet.Folder); } } return(""); }
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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { 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 = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { string defaultZone = mngServer.ZoneGetDefault(); DataRow dRow = results.NewRow(); dRow[Constants.SOProperties.WorkingHoursConfiguration.ZoneName] = defaultZone; results.Rows.Add(dRow); } }
private void ConnectionFactory() { if (_server == null || !_server.Connection.IsConnected) { _server = new WorkflowManagementServer(); try { var setting = ConfigurationManager.ConnectionStrings["HostServer"]; _server.Open(setting.ConnectionString); } catch (SmartException e) { Console.WriteLine(e.Message); throw e; } } }
private void ListZones() { base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable(); DataTable results = base.ServiceBroker.ServicePackage.ResultTable; WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>(); using (mngServer.Connection) { 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 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 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 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); } } }
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); } }
new string[] { "ProcessInstanceId", "ProcessSetId", "ProcessId", "ExecutingProcessId", "FullName", "Name", "Folio", "Originator", "Status", "ExpectedDuraction", "StartDate", "FinishDate", "Priority" })] // , "IsDefaultVersion", "VersionDate", "VersionDescription", "VersionLabel", "VersionNumber" public List<LIM.ProcessInstance> GetRunningProcessInstanceByVersion() { List<LIM.ProcessInstance> results = new List<ProcessInstance>(); WorkflowManagementServer svr = new WorkflowManagementServer("localhost", 5555); try { svr.Open(); ProcessInstances instances = null; SourceCode.Workflow.Management.Criteria.ProcessInstanceCriteriaFilter filter = new SourceCode.Workflow.Management.Criteria.ProcessInstanceCriteriaFilter(); filter.AddRegularFilter(ProcessInstanceFields.ProcID, SourceCode.Workflow.Management.Criteria.Comparison.Equals, this.ProcessId); instances = svr.GetProcessInstancesAll(filter); for (int i = 0; i < instances.Count; i++) { LIM.ProcessInstance pi = new ProcessInstance(); pi.ExecutingProcessId = instances[i].ExecutingProcID; pi.ExpectedDuration = instances[i].ExpectedDuration; pi.FinishDate = instances[i].FinishDate; pi.Folio = instances[i].Folio; pi.FullName = instances[i].ProcSetFullName; //pi.IsDefaultVersion = instances[i].Process.DefaultVersion; //pi.Name = instances[i].Process.FullName; pi.Originator = instances[i].Originator; pi.Priority = instances[i].Priority; pi.ProcessId = instances[i].ProcID; pi.ProcessInstanceId = instances[i].ID; pi.ProcessSetId = instances[i].ProcSetID; pi.StartDate = instances[i].StartDate; pi.Status = instances[i].Status; //pi.VersionDescription = instances[i].Process.VersionDesc; //pi.VersionDate = instances[i].Process.VersionDate; //pi.VersionLabel = instances[i].Process.VersionLabel; //pi.VersionNumber = instances[i].Process.VersionNumber; results.Add(pi); } } catch (Exception ex) { //this.ResultStatus = "Exception"; //this.ResultMessage = ex.GetBaseException().Message; //return this; } finally { try { svr.Connection.Close(); svr.Connection.Dispose(); } catch { } svr = null; } return results; }
public LIM.ProcessInstance GotoActivities() { List<LIM.ProcessInstance> results = new List<ProcessInstance>(); WorkflowManagementServer svr = new WorkflowManagementServer("localhost", 5555); try { svr.Open(); svr.GotoActivity(this.ProcessInstanceId, this.ActivityName, this.SecondActivityName); } catch (Exception ex) { //forcedStop = false; this.ResultStatus = "Exception"; this.ResultMessage = ex.GetBaseException().Message; return this; } finally { try { svr.Connection.Close(); svr.Connection.Dispose(); } catch { } svr = null; } this.ResultStatus = "Success"; return this; }
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 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 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 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 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 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); } }
// 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 static TimeSpan WorkingHoursDateDiff(string zoneName, DateTime startDate, DateTime endDate) { TimeSpan workedHours = new TimeSpan(0); WorkflowManagementServer mngServer = new WorkflowManagementServer("localhost", 5555); //safe to do this as inline function runs on K2 Server. mngServer.Open(); //let K2 catch errors here. AvailabilityZone zone = new AvailabilityZone(); if (string.IsNullOrEmpty(zoneName)) //use default working hours if not specified. { try { zoneName = mngServer.ZoneGetDefault(); } catch (Exception ex) { throw new Exception("Couldn't get default working hours because: " + ex.Message, ex); } } try { zone = mngServer.ZoneLoad(zoneName); } catch (Exception ex) { throw new Exception("Couldn't get working hours named: '" + zoneName + "' Because: " + ex.Message, ex); } DateTime currentZoneDate = startDate.Date; bool carryOn = true; while (carryOn) { List<AvailabilityHours> singleDayListOfHours = zone.AvailabilityHoursList.Where(x => x.WorkDay == currentZoneDate.DayOfWeek).ToList(); foreach (AvailabilityHours hours in singleDayListOfHours) { //quickly filter out exception dates :) if (zone.AvailabilityDateList.Count(x => x.IsNonWorkDate == true && x.WorkDate.Date == currentZoneDate.Date) > 0) continue; DateTime endOfSection = new DateTime(currentZoneDate.Year, currentZoneDate.Month, currentZoneDate.Day); DateTime startOfSection = new DateTime(currentZoneDate.Year, currentZoneDate.Month, currentZoneDate.Day); startOfSection = startOfSection.Add(hours.TimeOfDay); endOfSection = startOfSection.Add(hours.Duration); if ((startDate >= startOfSection && startDate <= endOfSection) && (endDate <= endOfSection && endDate >= startOfSection)) //starts inside, ends inside { workedHours += endDate - startDate; } if (startDate < startOfSection && endDate > endOfSection) // starts outside, ends outside { workedHours += endOfSection - startOfSection; } if (startDate < startOfSection && (endDate <= endOfSection && endDate >= startOfSection)) //starts outside, ends inside { workedHours += endDate - startOfSection; } if ((startDate >= startOfSection && startDate <= endOfSection) && endDate > endOfSection) //starts inside, ends outside { workedHours += endOfSection - startDate; } } //special dates require more work - basically duplicate the logic above but decrement worked hours for every special day foreach (AvailabilityDate specialDate in zone.AvailabilityDateList.Where(x => x.WorkDate.Date == currentZoneDate.Date && x.IsNonWorkDate == false)) { DateTime specialDateStart = specialDate.WorkDate; DateTime specialDateEnd = specialDate.WorkDate + specialDate.Duration; if ((startDate >= specialDateStart && startDate <= specialDateEnd) && (endDate <= specialDateEnd && endDate >= specialDateStart)) //starts inside, ends inside { workedHours -= endDate - startDate; } if (startDate < specialDateStart && endDate > specialDateEnd) // starts outside, ends outside { workedHours -= specialDateEnd - specialDateStart; } if (startDate < specialDateStart && (endDate <= specialDateEnd && endDate >= specialDateStart)) //starts outside, ends inside { workedHours -= endDate - specialDateStart; } if ((startDate >= specialDateStart && startDate <= specialDateEnd) && endDate > specialDateEnd) //starts inside, ends outside { workedHours -= specialDateEnd - startDate; } } if (currentZoneDate > endDate) carryOn = false; currentZoneDate = currentZoneDate.AddDays(1); } mngServer.Connection.Close(); mngServer.Connection.Dispose(); return workedHours; }
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 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 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); } } } }
public void Dispose() { //Check the server connections and close if needed. if (_SmartObjectClient != null) { _SmartObjectClient.CloseConnection(); _SmartObjectClient = null; } //Check the server connections and close if needed. if (_WorkflowServer != null) { if (_WorkflowServer.Connection.IsConnected) _WorkflowServer.Connection.Close(); _WorkflowServer = null; } //Check the server connections and close if needed. if (_WorkflowClient != null) { if (_WorkflowClient.connection != null) _WorkflowClient.CloseConnection(); _WorkflowClient.Dispose(); _WorkflowClient = null; } }
/// <summary> /// Workflow Management Server /// </summary> /// <returns>Workflow Management Server</returns> public WorkflowManagementServer WorkflowServer() { if (_WorkflowServer == null) { _WorkflowServer = new WorkflowManagementServer(_K2Server, _WorkflowManagementServerPort); _WorkflowServer.Open(); return _WorkflowServer; } else { return _WorkflowServer; } }
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); } } }
/// <summary> /// Check that the local K2 Server has a valid set of working hours for this test. /// </summary> private void ValidateWorkingHours() { WorkflowManagementServer mngServer = new WorkflowManagementServer("localhost", 5555); mngServer.Open(); AvailabilityZone zone = mngServer.ZoneLoad(workingHoursZoneName); List<AvailabilityDate> specialDates = zone.AvailabilityDateList.Where(x => x.IsNonWorkDate == false).ToList(); if (specialDates.Count > 2) Assert.Fail("Too many special dates"); List<AvailabilityDate> exceptionDates = zone.AvailabilityDateList.Where(x => x.IsNonWorkDate == true).ToList(); if (exceptionDates.Count > 2) Assert.Fail("Too many exception dates"); if (specialDates.Where(x => x.WorkDate == new DateTime(2011, 06, 30, 09, 00, 00) && x.Duration == new TimeSpan(3, 0, 0)).ToList().Count != 1) Assert.Fail("Problem finding special date June 30th 2011 09:00 - 12:00"); if (specialDates.Where(x => x.WorkDate == new DateTime(2011, 03, 11, 09, 00, 00) && x.Duration == new TimeSpan(3, 0, 0)).ToList().Count != 1) Assert.Fail("Problem finding special date March 11th 2011 09:00 - 12:00"); if (exceptionDates.Where(x => x.WorkDate == new DateTime(2011, 12, 26)).ToList().Count != 1) Assert.Fail("Problem finding exception date December 26th 2011"); if (exceptionDates.Where(x => x.WorkDate == new DateTime(2012, 1, 2)).ToList().Count != 1) Assert.Fail("Problem finding exception date Jan 2nd 2012"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Monday && x.Duration == new TimeSpan(3, 0, 0) && x.TimeOfDay == new TimeSpan(9, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Monday 9am - 12pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Tuesday && x.Duration == new TimeSpan(3, 0, 0) && x.TimeOfDay == new TimeSpan(9, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Tuesday 9am - 12pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Wednesday && x.Duration == new TimeSpan(3, 0, 0) && x.TimeOfDay == new TimeSpan(9, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Wednesday 9am - 12pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Thursday && x.Duration == new TimeSpan(3, 0, 0) && x.TimeOfDay == new TimeSpan(9, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Thursday 9am - 12pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Friday && x.Duration == new TimeSpan(3, 0, 0) && x.TimeOfDay == new TimeSpan(9, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Friday 9am - 12pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Monday && x.Duration == new TimeSpan(4, 0, 0) && x.TimeOfDay == new TimeSpan(13, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Monday 1pm - 5pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Tuesday && x.Duration == new TimeSpan(4, 0, 0) && x.TimeOfDay == new TimeSpan(13, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Tuesday 1pm - 5pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Wednesday && x.Duration == new TimeSpan(4, 0, 0) && x.TimeOfDay == new TimeSpan(13, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Wednesday 1pm - 5pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Thursday && x.Duration == new TimeSpan(4, 0, 0) && x.TimeOfDay == new TimeSpan(13, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Thursday 1pm - 5pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Friday && x.Duration == new TimeSpan(4, 0, 0) && x.TimeOfDay == new TimeSpan(13, 0, 0)).ToList().Count != 1) Assert.Fail("Problem with Friday 1pm - 5pm working hours"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Saturday).ToList().Count > 0) Assert.Fail("Found working hours on Saturday where there should be none"); if (zone.AvailabilityHoursList.Where(x => x.WorkDay == DayOfWeek.Sunday).ToList().Count > 0) Assert.Fail("Found working hours on Sunday wherer there should be none"); mngServer.Connection.Close(); mngServer.Connection.Dispose(); }
private SourceCode.Workflow.Management.ErrorLog GetLastError() //////int ErrorCountBeforeTests, out int LastErrorNumBeforeTests ) { WorkflowManagementServer ManagementServer = null; try { ManagementServer = new WorkflowManagementServer(); ManagementServer.Open(ConfigHelper.GetConnectionString("ManagementServerCS")); ErrorProfile profile = ManagementServer.GetErrorProfile("All"); ErrorLogCriteriaFilter elcf = new ErrorLogCriteriaFilter(); elcf.ORDER_BY(ErrorLogFields.ErrorLogID, CriteriaSortOrder.Ascending); ErrorLogs logs = ManagementServer.GetErrorLogs(profile.ID); if (logs.Count > 0) { return logs[logs.Count - 1]; } else { return null; } } finally { if (ManagementServer != null && ManagementServer.Connection != null) { ManagementServer.Connection.Dispose(); ManagementServer = null; } } }
new string[] { "ProcessInstanceId", "NewVersion", "ActivityName", "ResultStatus", "ResultMessage" })] // , "IsDefaultVersion", "VersionDate", "VersionDescription", "VersionLabel", "VersionNumber" public LIM.ProcessInstance MigrateProcessInstance() { List<LIM.ProcessInstance> results = new List<ProcessInstance>(); WorkflowManagementServer svr = new WorkflowManagementServer("localhost", 5555); try { svr.Open(); svr.StopProcessInstances(this.ProcessInstanceId); svr.SetProcessInstanceVersion(this.ProcessInstanceId, this.NewVersion); if (!string.IsNullOrWhiteSpace(this.ActivityName)) { svr.GotoActivity(this.ProcessInstanceId, ActivityName); } else { svr.StartProcessInstances(this.ProcessInstanceId); } } catch (Exception ex) { this.ResultStatus = "Exception"; this.ResultMessage = ex.GetBaseException().Message; return this; } finally { try { svr.Connection.Close(); svr.Connection.Dispose(); } catch { } svr = null; } this.ResultStatus = "Success"; return this; }
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); } } }
new string[] { "ProcessInstanceId", "ProcessSetId", "ProcessId", "ExecutingProcessId", "FullName", "Folio", "Originator", "Status", "ExpectedDuraction", "StartDate", "FinishDate", "Priority", "ResultStatus", "ResultMessage" })] // , "IsDefaultVersion", "VersionDate", "VersionDescription", "VersionLabel", "VersionNumber" public LIM.ProcessInstance GetProcessInstance() { WorkflowManagementServer svr = new WorkflowManagementServer("localhost", 5555); try { svr.Open(); ProcessInstances instances = null; SourceCode.Workflow.Management.Criteria.ProcessInstanceCriteriaFilter filter = new SourceCode.Workflow.Management.Criteria.ProcessInstanceCriteriaFilter(); filter.AddRegularFilter(ProcessInstanceFields.ProcInstID, SourceCode.Workflow.Management.Criteria.Comparison.Equals, this.ProcessInstanceId); instances = svr.GetProcessInstancesAll(filter); if (instances != null & instances.Count > 0) { this.ExecutingProcessId = instances[0].ExecutingProcID; this.ExpectedDuration = instances[0].ExpectedDuration; this.FinishDate = instances[0].FinishDate; this.Folio = instances[0].Folio; this.FullName = instances[0].ProcSetFullName; //this.IsDefaultVersion = instances[0].Process.DefaultVersion; //this.Name = instances[0].Process.FullName; this.Originator = instances[0].Originator; this.Priority = instances[0].Priority; this.ProcessId = instances[0].ProcID; this.ProcessInstanceId = instances[0].ID; this.ProcessSetId = instances[0].ProcSetID; this.StartDate = instances[0].StartDate; this.Status = instances[0].Status; //this.VersionDescription = instances[0].Process.VersionDesc; //this.VersionDate = instances[0].Process.VersionDate; //this.VersionLabel = instances[0].Process.VersionLabel; //this.VersionNumber = instances[0].Process.VersionNumber; } } catch (Exception ex) { this.ResultStatus = "Exception"; this.ResultMessage = ex.GetBaseException().Message; return this; } finally { try { svr.Connection.Close(); svr.Connection.Dispose(); } catch { } svr = null; } return this; }
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); } } } } } } }