Ejemplo n.º 1
0
        public void addWorkflowInstance(int processSubjectId, string processInstanceId, string guid, string owner)
        {
            P_WorkflowInstance i = new P_WorkflowInstance(processInstanceId, guid, processSubjectId, owner);

            db.P_WorkflowInstances.Add(i);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            IProcessStore      processStore    = StoreHandler.getProcessStore(context.GetValue(cfgSQLConnectionString));
            ITaskStore         taskStore       = StoreHandler.getTaskStore(context.GetValue(cfgSQLConnectionString));
            P_WorkflowInstance creatorinstance = processStore.getWorkflowInstance(context.GetValue(WFId));

            processStore.updateWorkflowInstanceEndState(creatorinstance.Id, context.GetValue(IsEndState));

            if (processStore.hasProcessEnded(creatorinstance.ProcessInstance_Id))
            {
                processStore.markProcessInstanceAsEnded(creatorinstance.ProcessInstance_Id, creatorinstance.ProcessSubject_Id, creatorinstance.Owner);
                taskStore.setAllTasksForProcessInstanceAsDone(creatorinstance.ProcessInstance_Id);

                var           instances = processStore.getWFInstanceIdsForProcessInstance(creatorinstance.ProcessInstance_Id);
                CoreFunctions c         = new CoreFunctions(context.GetValue(cfgWFMBaseAddress), context.GetValue(cfgWFMUsername), context.GetValue(cfgWFMPassword), context.GetValue(cfgSQLConnectionString));
                foreach (var i in instances)
                {
                    try
                    {
                        c.terminateSubjectInstance(i);
                    }
                    catch (Exception e)
                    { }
                }
            }
        }
Ejemplo n.º 3
0
        public void createNotificationForTask(int TaskId, string cfgSQLConnectionString)
        {
            this.cfgSQLConnectionString = cfgSQLConnectionString;
            configStore  = StoreHandler.getConfigStore(cfgSQLConnectionString);
            baseURL      = configStore.getString(BaseURL);
            templatepath = configStore.getString(Email_NotificationTemplate);

            taskStore = StoreHandler.getTaskStore(cfgSQLConnectionString);
            T_Task task = taskStore.getTaskById(TaskId);

            helper       = new MailBodyHelper();
            processStore = StoreHandler.getProcessStore(cfgSQLConnectionString);
            instance     = processStore.getWorkflowInstance(task.WFId);
            mail         = new SmtpUtils(configStore);
            if (task.Type.Equals("F") || task.Type.Equals("S"))
            {
                if (configStore.getBool(Email_Notifications_Tasks))
                {
                    string content = helper.getStateBody(task, baseURL, templatepath);



                    List <string> recipients = new List <string>();

                    if (String.IsNullOrEmpty(instance.Owner))
                    {
                        var subject = processStore.getProcessSubjectForWFId(task.WFId);
                        userStore = StoreHandler.getUserStore(cfgSQLConnectionString);
                        recipients.AddRange(userStore.getUsernamesForRole(subject.U_Role_Id));
                    }
                    else
                    {
                        recipients.Add(instance.Owner);
                    }

                    foreach (string user in recipients)
                    {
                        mail.sendMail(user, "InFlow: " + task.Name + " #" + task.Id, content);
                    }
                }
            }
            if (task.Type.Equals("R"))
            {
                if (configStore.getBool(Email_Notifications_Messages))
                {
                    messageStore = StoreHandler.getMessageStore(cfgSQLConnectionString);
                    var messages = messageStore.getMessagesForReceiveStateTask(task.WFId, task.getTaskPropertiesAsListOfString());

                    foreach (var i in messages)
                    {
                        createReceiveNotification(i, task);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void createNotificationForMessage(int MessageId, string cfgSQLConnectionString)
        {
            this.cfgSQLConnectionString = cfgSQLConnectionString;
            configStore  = StoreHandler.getConfigStore(cfgSQLConnectionString);
            baseURL      = configStore.getString(BaseURL);
            templatepath = configStore.getString(Email_NotificationTemplate);

            if (configStore.getBool(Email_Notifications_Messages))
            {
                taskStore = StoreHandler.getTaskStore(cfgSQLConnectionString);
                T_Task task = taskStore.getReceiveTaskForMessageId(MessageId);
                if (task != null)
                {
                    messageStore = StoreHandler.getMessageStore(cfgSQLConnectionString);
                    mail         = new SmtpUtils(configStore);
                    processStore = StoreHandler.getProcessStore(cfgSQLConnectionString);
                    instance     = processStore.getWorkflowInstance(task.WFId);
                    M_Message message = messageStore.getMessageBymsgId(MessageId);
                    createReceiveNotification(message, task);
                }
            }
        }
Ejemplo n.º 6
0
        public List <T_Task> getTasksNotDoneByUsername(string name)
        {
            IProcessStore processStore = StoreHandler.getProcessStore(connectionString);
            IUserStore    userStore    = StoreHandler.getUserStore(connectionString);

            List <T_Task> temp  = new List <T_Task>();
            var           query = from t in db.T_Tasks
                                  where t.Done == false
                                  select t;

            foreach (var item in query)
            {
                P_WorkflowInstance i = processStore.getWorkflowInstance(item.WFId);
                //string subjectname = processStore.getProcessSubject(i.ProcessSubject_Id).Name;
                int roleId = processStore.getProcessSubject(i.ProcessSubject_Id).U_Role_Id;
                if (i.Owner.Length > 0)
                {
                    if (i.Owner.Equals(name))
                    {
                        temp.Add(item);
                    }
                }
                else
                {
                    foreach (string us in userStore.getUsernamesForRole(roleId))
                    {
                        if (us.Equals(name))
                        {
                            temp.Add(item);
                        }
                    }
                }
            }

            return(temp);
        }
Ejemplo n.º 7
0
        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()));
        }
Ejemplo n.º 8
0
        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);
            }
        }