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); }
public static bool GoToActitvy(int wfId, string activityName) { WorkflowManagementServer svr = new WorkflowManagementServer(K2ServerName, uint.Parse(K2ServerPort)); svr.Open(); return(svr.GotoActivity(wfId, activityName)); }
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 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; } } }
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 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 UserDeleteZone() { string FQN = base.GetStringProperty(Constants.SOProperties.WorkingHoursConfiguration.FQN, true); WorkflowManagementServer mngServer = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); mngServer.UserDeleteZone(FQN); } }
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 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); } } }
/// <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 = 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 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 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 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 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); } } }
/// <summary> /// 设置流程实例最新版本,重试流程错误 /// </summary> /// <param name="procInstID"></param> public static void SetProcessInstanceVersionRetry(int procInstID) { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.Open(GetK2ManagementServerConnectionString()); SqlHelper sqlHelper = new SqlHelper(K2ConnectionString); var dt = sqlHelper.ExecuteDataTable(string.Format("EXEC Utility.GetProcInstNewVersionByProcInstID {0}", procInstID)); int Ver = Convert.ToInt32(dt.Rows[0]["Ver"]); int ErrorID = Convert.ToInt32(dt.Rows[0]["ErrorID"]); if (ErrorID != 0) { wms.SetProcessInstanceVersion(procInstID, Ver); wms.RetryError(procInstID, ErrorID, MngUserID); } }
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); } } }
/// <summary> /// 结束流程 /// </summary> /// <param name="wfId"></param> /// <returns></returns> public static bool StopWorkflow(int wfId) { WorkflowManagementServer svr = new WorkflowManagementServer(K2ServerName, uint.Parse(K2ServerPort)); try { svr.Open(); bool flag = svr.StopProcessInstances(wfId); return(flag); } catch (Exception ex) { return(false); } finally { svr.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 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 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); } } }
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); } }
public static void SetProcessInstanceVersion() { WorkflowManagementServer wms = new WorkflowManagementServer(); wms.Open(GetK2ManagementServerConnectionString()); // wms.StopProcessInstances SqlHelper sqlHelper = new SqlHelper(K2ConnectionString); var dt = sqlHelper.ExecuteDataTable("SELECT ID FROM Server.ProcInst WHERE ProcID IN (1202,1217,1195,1176)"); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { wms.StopProcessInstances(Convert.ToInt32(dr["ID"])); wms.SetProcessInstanceVersion(Convert.ToInt32(dr["ID"]), 68); wms.StartProcessInstances(Convert.ToInt32(dr["ID"])); } } }
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); } }
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); } } }
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); } } }
//sample that demonstrates opening a connection to the K2 server using the management API public void OpenManagementConnection() { WorkflowManagementServer K2Mgmt = new WorkflowManagementServer(); //construct a connection string with the hosting client API SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder builder = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder(); builder.Integrated = true; //use the current user's security credentials builder.IsPrimaryLogin = true; builder.Authenticate = true; builder.EncryptedPassword = false; builder.Host = "localhost"; builder.Port = 5555; //you must use port 5555 when connecting with the management API builder.SecurityLabelName = "K2"; //this sample uses the Active Directory security provider //open the connection using the constructed connection string K2Mgmt.Open(builder.ToString()); //do something in the management connection //close the connection when you are done K2Mgmt.Connection.Close(); }
private void GetUserStatus() { 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 = new WorkflowManagementServer(); using (mngServer.CreateConnection()) { mngServer.Open(BaseAPIConnectionString); UserStatuses status = mngServer.GetUserStatus(userFQN); DataRow dr = results.NewRow(); dr[Constants.SOProperties.OutOfOffice.UserFQN] = userFQN; dr[Constants.SOProperties.OutOfOffice.UserStatus] = status.ToString(); results.Rows.Add(dr); } }
/// <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(); }
/// <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 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 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 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; } } }
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 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); } } }
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; }
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 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 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 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 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); } }
// 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); } } }
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 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); } }
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 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 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 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); } }