/// <summary> /// Reconnection k2. /// </summary> private void ReConnection() { if (_connection != null) { _connection.Close(); } _connection = Connection(_model); }
private void StartProcessInstance(bool startGeneric) { string processName = ServiceBroker.Service.ServiceObjects[0].Methods[0].Name; if (!startGeneric) { processName = GetStringProperty(Constants.SOProperties.ProcessInstanceClient.ProcessName, true); } int processVersion = GetIntProperty(Constants.SOProperties.ProcessInstanceClient.ProcessVersion); ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = ServiceBroker.ServicePackage.ResultTable; using (CLIENT.Connection k2Con = new CLIENT.Connection()) { k2Con.Open(K2ClientConnectionSetup); CLIENT.ProcessInstance pi; if (processVersion > 0) { pi = k2Con.CreateProcessInstance(processName, processVersion); } else { pi = k2Con.CreateProcessInstance(processName); } string folio = GetStringProperty(Constants.SOProperties.ProcessInstanceClient.ProcessFolio); if (!string.IsNullOrEmpty(folio)) { pi.Folio = folio; } if (startGeneric) { MethodParameters mParams = ServiceBroker.Service.ServiceObjects[0].Methods[0].MethodParameters; foreach (CLIENT.DataField df in pi.DataFields) { df.Value = GetDataFieldValue(mParams[df.Name].Value, df.ValueType); } } k2Con.StartProcessInstance(pi, GetBoolProperty(Constants.SOProperties.ProcessInstanceClient.StartSync)); DataRow dr = results.NewRow(); dr[Constants.SOProperties.ProcessInstanceClient.ProcessInstanceId] = pi.ID; dr[Constants.SOProperties.ProcessInstanceClient.ProcessFolio] = pi.Folio; results.Rows.Add(dr); k2Con.Close(); } }
private void SetFolio() { ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0]; string folio = base.GetStringProperty(Constants.SOProperties.ProcessInstanceClient.ProcessFolio, false); int procId = base.GetIntProperty(Constants.SOProperties.ProcessInstanceClient.ProcessInstanceId, true); using (CLIENT.Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection()) { CLIENT.ProcessInstance pi = k2Con.OpenProcessInstance(procId); pi.Folio = folio; pi.Update(); k2Con.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(); } } }