/// <summary> /// Set taskanswer for a receive-task /// </summary> /// <param name="taskId">Id of the task</param> /// <param name="messageInstanceId">Id of the choosen message</param> /// <param name="username">username</param> public void submitReceiveTaskAnswer(int taskId, string messageInstanceId, string username) { IProcessStore processStore = StoreHandler.getProcessStore(connectionString); ITaskStore taskStore = StoreHandler.getTaskStore(connectionString); T_Task openTask = taskStore.getTaskById(taskId); //check if task isn't already answered if (openTask.Done == false && openTask.Type.Equals("R")) { P_ProcessSubject processSubject = processStore.getProcessSubjectForWFId(openTask.WFId); P_Process process = processStore.getProcess(processSubject.Process_Id); DynamicValue val = new DynamicValue(); val.Add("MessageId", new DynamicValue(messageInstanceId)); submitTaskAnswer(val, process, openTask); //set task as answered //taskStore.setTaskStatus(taskId, true); taskStore.setTaskStatus(taskId, username, "", messageInstanceId); //set the owner of the task recipient instance to the user who submitted the taskanswer processStore.setWorkflowInstanceOwner(openTask.WFId, username); } }
/// <summary> /// start a new instance of a processsubject with an existing processinstanceid /// </summary> /// <param name="processInstanceId">existing processinstanceid</param> /// <param name="subjectProcessId">id of the processsubject</param> /// <param name="username">owner of the new processsubject instance</param> /// <returns>id of the new workflow instance</returns> public string startNewSubjectProcess(string processInstanceId, int subjectProcessId, string username) { IProcessStore processStore = StoreHandler.getProcessStore(connectionString); Console.WriteLine("start2 " + subjectProcessId + " " + username); P_ProcessSubject subject = processStore.getProcessSubject(subjectProcessId); P_Process process = processStore.getProcess(subject.Process_Id); string adress = baseAddress + process.WFM_RootScope + process.WFM_ProcessScope; WorkflowManagementClient client = new WorkflowManagementClient(new Uri(adress), credentials); string guid = client.Workflows.Start(subject.WFM_WFName); processStore.addWorkflowInstance(subject.Id, processInstanceId, guid, username); Console.WriteLine(guid, ConsoleColor.Blue); return(guid); }
protected override void Execute(CodeActivityContext context) { IProcessStore processStore = StoreHandler.getProcessStore(context.GetValue(cfgSQLConnectionString)); P_WorkflowInstance senderInstance = processStore.getWorkflowInstance(context.GetValue(SenderId)); P_ProcessSubject senderProcessSubject = processStore.getProcessSubject(senderInstance.ProcessSubject_Id); P_Process process = processStore.getProcess(senderProcessSubject.Process_Id); P_ProcessSubject recipientProcessSubject = processStore.getProcessSubject(senderProcessSubject.Process_Id, context.GetValue(RecipientSubject)); //check if message is for internal subject if (recipientProcessSubject.WFM_WFName != null) { string recipientuser = context.GetValue(RecipientUsername); if (recipientuser != null) { if (recipientuser.Length == 0) { recipientuser = null; } } P_WorkflowInstance recipientInstance = processStore.getWorkflowInstance(recipientProcessSubject.Id, senderInstance.ProcessInstance_Id, recipientuser); if (recipientInstance != null) { //update recipient workflow id context.SetValue(RecipientId, recipientInstance.Id); } //message is for internal subject context.SetValue(IsMessageForExternalSubject, false); //update recipient processsubjectId context.SetValue(RecipientProcessSubjectId, recipientProcessSubject.Id); } else { //message is for external subject context.SetValue(IsMessageForExternalSubject, true); } context.SetValue(GlobalProcessName, process.GlobalProcessName); context.SetValue(ProcessInstanceId, senderInstance.ProcessInstance_Id); context.SetValue(SenderSubject, senderProcessSubject.Name); context.SetValue(SenderUsername, senderInstance.Owner); context.SetValue(Recipient_Role_Id, recipientProcessSubject.U_Role_Id); }
/// <summary> /// Set taskanswer for a send-state task /// </summary> /// <param name="taskId">Id of the task</param> /// <param name="recipientName">choosen recipient/s</param> /// <param name="editableParameters">edited parameters</param> public void submitSendTaskAnswer(int taskId, string recipientName, string editableParameters, string username) { IProcessStore processStore = StoreHandler.getProcessStore(connectionString); ITaskStore taskStore = StoreHandler.getTaskStore(connectionString); T_Task openTask = taskStore.getTaskById(taskId); //check if task isn't already answered if (openTask.Done == false && openTask.Type.Equals("S")) { P_ProcessSubject processSubject = processStore.getProcessSubjectForWFId(openTask.WFId); P_Process process = processStore.getProcess(processSubject.Process_Id); DynamicValue val = DynamicValue.Parse(editableParameters); val.Add("recipient", new DynamicValue(recipientName)); submitTaskAnswer(val, process, openTask); //set task as answered //taskStore.setTaskStatus(taskId, true); taskStore.setTaskStatus(taskId, username, editableParameters, recipientName); } }
protected override void Execute(CodeActivityContext context) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(context.GetValue(cfgWFMUsername), context.GetValue(cfgWFMPassword)); DynamicValue variables = context.GetValue(globalVariables); //set message data DynamicValue data = new DynamicValue(); foreach (string i in SbpmActivityHelper.convertCSVtoListofString(context.GetValue(parameters))) { if (variables.ContainsKey(i)) { DynamicValue value = new DynamicValue(); variables.TryGetValue(i, out value); data.Add(i, value); } } List <string> recipients = new List <string>(context.GetValue(recipient).Split(',')); List <M_Message> messages = new List <M_Message>(); if (recipients.Count == 1) { List <string> usernames = new List <string>(); IUserStore userStore = StoreHandler.getUserStore(context.GetValue(cfgSQLConnectionString)); string[] recipientArray = recipients[0].Split('|'); string recipientSubject = recipientArray[0]; IProcessStore processStore = StoreHandler.getProcessStore(context.GetValue(cfgSQLConnectionString)); P_ProcessSubject senderSubject = processStore.getProcessSubjectForWFId(context.GetValue(globalWFId)); P_WorkflowInstance senderinstance = processStore.getWorkflowInstance(context.GetValue(globalWFId)); P_ProcessSubject recipientSubjet = processStore.getProcessSubject(senderSubject.Process_Id, recipientSubject); if (recipientSubjet.MultiSubject && recipientArray.Length == 1)//If multisubject { P_WorkflowInstance recipientInstance = processStore.getWorkflowInstance(recipientSubjet.Id, senderinstance.ProcessInstance_Id, null); //Check if Recipientinstance already Exists if (recipientInstance != null) { //recipients are only existing processsubjectinstances usernames = processStore.getWorkflowInstanceOwnersForMultisubjects(recipientInstance.ProcessSubject_Id, recipientInstance.ProcessInstance_Id); } else { //recipients are all users who represent the processsubject // usernames = subjectStore.getUsernamesForSubjectName(recipientArray[0]); usernames = userStore.getUsernamesForRole(recipientSubjet.U_Role_Id); } foreach (string user in usernames) { M_Message m = new M_Message(context.GetValue(globalWFId), recipientSubject, user, context.GetValue(type), data.ToString()); messages.Add(m); } } else { //simple Subject string recipientUsername = ""; if (recipientArray.Length > 1) { recipientUsername = recipientArray[1]; } M_Message m = new M_Message(context.GetValue(globalWFId), recipientSubject, recipientUsername, context.GetValue(type), data.ToString()); messages.Add(m); } } else //multisubject { foreach (string rec in recipients) { string[] recipientArray = rec.Split('|'); string recipientSubject = recipientArray[0]; string recipientUsername = ""; if (recipientArray.Length > 1) { recipientUsername = recipientArray[1]; } M_Message m = new M_Message(context.GetValue(globalWFId), recipientSubject, recipientUsername, context.GetValue(type), data.ToString()); messages.Add(m); } } WorkflowManagementClient client = new WorkflowManagementClient(new Uri(context.GetValue(cfgProcessScopeAddress)), credentials); messages.ForEach(m => client.PublishNotification(m.toWorkflowNotification())); }
protected override void Execute(CodeActivityContext context) { string editableparameters = context.GetValue(EditableParameters); string log = ""; try { bool toMultiSubject = false; ITaskStore taskStore = StoreHandler.getTaskStore(context.GetValue(cfgSQLConnectionString)); IProcessStore processStore = StoreHandler.getProcessStore(context.GetValue(cfgSQLConnectionString)); P_WorkflowInstance creatorinstance = null; int timer = 1; do { try { creatorinstance = processStore.getWorkflowInstance(context.GetValue(WFId)); } catch (Exception e) { log = log + "[" + timer + ": " + e.Message + "]"; creatorinstance = null; System.Threading.Thread.Sleep(500 * timer); timer++; } } while (creatorinstance == null && timer < 20); log = log + "(Timer: " + timer + ")"; string taskProperties = context.GetValue(TaskProperties); string subjectname = taskProperties.Split('|')[0]; //check if the task is a send-task if (context.GetValue(Type).Equals("S")) { P_ProcessSubject creatorSubject = processStore.getProcessSubjectForWFId(context.GetValue(WFId)); P_ProcessSubject recipientSubjet = processStore.getProcessSubject(creatorSubject.Process_Id, subjectname); P_WorkflowInstance recipientInstance = processStore.getWorkflowInstance(recipientSubjet.Id, creatorinstance.ProcessInstance_Id, null); if (recipientSubjet.MultiSubject) { toMultiSubject = true; } //Check if Recipientinstance already Exists if (recipientInstance != null) { //Check if recipient is a multisubject if (recipientSubjet.MultiSubject) { //Multisubject List <string> users = processStore.getWorkflowInstanceOwnersForMultisubjects(recipientInstance.ProcessSubject_Id, recipientInstance.ProcessInstance_Id); users.ForEach(user => taskProperties = taskProperties + "," + subjectname + "|" + user); } else { //Normal Subject if (recipientInstance.Owner != null) { if (recipientInstance.Owner.Length > 0) { taskProperties = subjectname + "|" + recipientInstance.Owner; } } } } else { //If instance doesn't exist IUserStore userStore = StoreHandler.getUserStore(context.GetValue(cfgSQLConnectionString)); //List<string> username = subjectStore.getUsernamesForSubjectName(taskProperties.Split('|')[0]); List <string> username = userStore.getUsernamesForRole(recipientSubjet.U_Role_Id); username.ForEach(user => taskProperties = taskProperties + "," + subjectname + "|" + user); } } if (context.GetValue(Type).Equals("S") || context.GetValue(Type).Equals("F")) { if (editableparameters.Length > 0) { IDictionary <string, dynamic> ob = Newtonsoft.Json.JsonConvert.DeserializeObject <IDictionary <string, dynamic> >(editableparameters); foreach (KeyValuePair <string, dynamic> i in ob) { if (ob[i.Key].Type.Value.Equals("bobasic")) { dynamic boconf = ob[i.Key].Value; if (boconf.boi < 0) { int id = (int)boconf.bo.Value; int newid = InitializeBO.initializeBO(id, context.GetValue(cfgSQLConnectionString)); ob[i.Key].Value.boi = newid; } } } editableparameters = Newtonsoft.Json.JsonConvert.SerializeObject(ob); } } //store task T_Task newTask = new T_Task(context.GetValue(Type), context.GetValue(WFId), context.GetValue(Name), context.GetValue(Done), false, context.GetValue(IsEndState), context.GetValue(ReadableParameters), editableparameters, taskProperties, context.GetValue(InternalOrderId));//, creatorinstance.ProcessSubject_Id, creatorinstance.Id); newTask.ToMultiSubject = toMultiSubject; newTask.P_ProcessInstance_Id = creatorinstance.ProcessInstance_Id; newTask.P_ProcessSubject_Id = creatorinstance.ProcessSubject_Id; var createdTask = taskStore.addTask(newTask); context.SetValue(TaskId, createdTask.Id); }catch (Exception e) { string message = "[ cfgSQLConnectionString: " + context.GetValue(cfgSQLConnectionString); message = message + "| WFId: " + context.GetValue(WFId) + "][" + log + "]"; message = message + e.Message; throw new Exception(message); } }