/// <summary> /// 撤消任务 /// </summary> /// <param name="procInstID">流程实例ID,格式:1_2_3_4</param> /// <param name="activityName">实例结束结点</param> public static void CancelProcInstance(string procInstID) { Mang.WorkflowManagementServer svr = new Mang.WorkflowManagementServer(); try { svr.CreateConnection(); svr.Connection.Open(GetServerConnectionSetup()); string[] procInstIDs = procInstID.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); foreach (string id in procInstIDs) { svr.GotoActivity(Convert.ToInt32(id), "结束"); } } catch { throw; } finally { if (svr != null) { svr.Connection.Close(); } } }
/// <summary> /// GotoActivity /// </summary> /// <param name="procInstID"></param> /// <param name="activityName"></param> public static void GotoActivity(int procInstID, string activityName) { Mang.WorkflowManagementServer svr = new Mang.WorkflowManagementServer(); try { svr.CreateConnection(); svr.Connection.Open(GetServerConnectionSetup()); svr.GotoActivity(procInstID, activityName); } catch { throw; } finally { if (svr != null) { svr.Connection.Close(); } } }
/// <summary> /// Method to check K2 for process errors since the last scheduled internal. /// </summary> public void RetrieveNewErrors() { k2Mgnt.WorkflowManagementServer server = new k2Mgnt.WorkflowManagementServer(); server.Connection = server.CreateConnection(); server.Connection.Open(connectionString); // client connection to K2 server. k2Client.Connection k2Conn = new k2Client.Connection(); try { // Search for new process errors in the specified profile and update the error list. k2Mgnt.ErrorLogs els = server.GetErrorLogs(server.GetErrorProfile(_errorProfileName).ID); // Open client connection to K2 server. string host = Regex.Replace(connectionString, @"(.+)(Host\=)(.+)(;)(.+)", "$3"); k2Conn.Open(host); // check every error in the error log foreach (k2Mgnt.ErrorLog el in els) { Update(el, k2Conn); } if (ErrorsToBeReported.Count > 0) { // // Pull in the related tasks into the error collection. // k2Mgnt.WorklistItems worklistItems = server.GetWorklistItems( new DateTime(1900, 1, 1), DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty); foreach (SourceCode.Workflow.Management.WorklistItem worklistItem in worklistItems) { if (worklistItem.ProcessInstanceStatus == k2Mgnt.ProcessInstanceStatus.Error) { Update(worklistItem); } } } //Finally, prune the errors collection. Prune(k2Conn, server); } finally { if (server.Connection != null) { server.Connection.Close(); } if (k2Conn != null) { k2Conn.Close(); } } }
/// <summary> /// 连接K2管理服务器 /// </summary> /// <returns></returns> protected WorkflowManagementServer ConnectManagermentServer() { try { var wms = new SourceCode.Workflow.Management.WorkflowManagementServer(); wms.CreateConnection(); wms.Open(K2ManagermentConnStr); return wms; } catch (Exception ex) { throw new K2ManagermentServerConnectErrorException(K2ManagermentConnStr, ex); } }