private void GetWorklist()
        {
            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = this.ServiceBroker.K2Connection.GetConnection <WorkflowManagementServer>();

            using (mngServer.Connection)
            {
                WorklistCriteriaFilter filter  = new WorklistCriteriaFilter();
                WorklistItems          wlItems = mngServer.GetWorklistItems(filter);

                foreach (WorklistItem wlItem in wlItems)
                {
                    DataRow row = CreateWorklistItemRow(results, wlItem);
                    results.Rows.Add(row);
                }
            }
        }
示例#2
0
        public void WorklistItems()
        {
            // Gets all the worklist items for the authenticated user
            WorklistItems worklistItems = ManagementServer.GetWorklistItems("", "", "", "", "", "", "");

            foreach (WorklistItem worklistItem in worklistItems)
            {
                Console.WriteLine("WorklistItem: {0}", worklistItem.ID);
            }

            int procInstId     = 1;
            int actInstDestId  = 1;
            int worklistItemId = 1;

            //If ID = 0, it means that the items' state is "available" and it will redirect the available item.
            //If ID != 0, it means the items' state = "Open" and it will redirect it retaining it's "Open" state.
            bool redirect = ManagementServer.RedirectWorklistItem("K2:Domain\\User1", "K2:Domain\\User2", procInstId, actInstDestId, worklistItemId);

            //If item not in "Open" state, an exception will be thrown.
            bool released = ManagementServer.ReleaseWorklistItem(worklistItemId);
        }
        //sample that shows how to manage worklist items.
        //In this sample, we want to redirect all tasks from one user to another user
        public void ManageWorklistItems()
        {
            //establish the connection
            WorkflowManagementServer K2Mgmt = new WorkflowManagementServer();

            K2Mgmt.CreateConnection();
            K2Mgmt.Connection.Open("connectionstring");

            //build up a filter for the list of worklist items. Here, we want to return all the worklist items for a specific user
            WorklistCriteriaFilter wlCritFilter = new WorklistCriteriaFilter();

            wlCritFilter.AddRegularFilter(WorklistFields.Destination, Comparison.Like, "%user1%");
            WorklistItems wlItems = K2Mgmt.GetWorklistItems(wlCritFilter);

            foreach (WorklistItem wlItem in wlItems)
            {
                K2Mgmt.RedirectWorklistItem("user1", "user2", wlItem.ProcInstID, wlItem.ActInstDestID, wlItem.ID);
            }

            //close the connection
            K2Mgmt.Connection.Close();
        }
示例#4
0
    /// <summary>
    /// 获取下一个审批人(处理人/处理步骤/接收时间)
    /// </summary>
    /// <param name="formId"></param>
    /// <returns></returns>
    public static SourceCode.Workflow.Management.WorklistItems GetNextApprover(string formId)
    {
        WorkflowManagementServer wms = new WorkflowManagementServer();

        try
        {
            wms.Open(WorkflowHelper.GetConnString4Management());
            SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter wcf = new SourceCode.Workflow.Management.Criteria.WorklistCriteriaFilter();
            wcf.AddRegularFilter(WorklistFields.Folio, SourceCode.Workflow.Management.Criteria.Comparison.Like, formId);

            WorklistItems wlis = wms.GetWorklistItems(wcf);
            wms.Connection.Close();
            return(wlis);
        }
        catch
        {
            wms.Connection.Close();
            return(null);
        }
        finally
        {
        }
    }
 private void ActionWorklistItemsIfFound(WorklistItems items, Process p, Activity a, out bool breakFromLoop, out bool actioned, out bool IPCeventFound)
 {
     actioned = false;
     breakFromLoop = false;
     IPCeventFound = false;
     
      string currentUser = "******" + System.Security.Principal.WindowsIdentity.GetCurrent().Name;
     for (int x = 0; x < items.Count; x++)
     {
         //Loop through and see if there is an item for this activity assigned to the current user.
         if (string.Equals(currentUser, items[x].Destination, StringComparison.OrdinalIgnoreCase)
             && a.Name.Equals(items[x].ActivityName))
         {
             //if we are here then maybe we have an item in an IPC event, 
             //set the a.ProcInstID which will be called on the next round.
             // important to note that IPC retry counts should be set higher to
             //cope with this hack!
             a.ProcessInstanceID = items[x].ProcInstID;
             IPCeventFound = true;
             breakFromLoop = true; return;
         }
         if (!this.ProceedWithTest)
         {
             breakFromLoop = true; return;
         }
     }
     for (int x = 0; x < items.Count; x++)
     {
         //we have a matching activity, but it is not assigned to the current user.
         if (string.Equals(items[x].ActivityName, a.Name, StringComparison.OrdinalIgnoreCase))
         {
             try
             {
                 //If we are on the last loop, lets impersonate the destination user and action the item.
                 string impersonatedUser = string.Empty;
                 Dictionary<string, object> filter = new Dictionary<string, object>();
                 switch (items[x].Actioner.ActionerType)
                 {
                     case ActionerType.User:
                         impersonatedUser = items[x].Actioner.Name;
                         break;
                     case ActionerType.Groups:
                         filter.Add("Group_name", items[x].Actioner.Name);
                         filter.Add("LabelName", "K2:");
                         //get the first user in the group.
                         var group = k2helper.SmartObjectClient().SmartObjectGetList(filter, "UMUSer", "Get_Group_Users");
                         impersonatedUser = group.Rows[0]["Name"].ToString();
                         break;
                     case ActionerType.Role:
                         filter.Add("Role_Name", items[x].Actioner.Name);
                         //get the first user in the group.
                         var role = k2helper.SmartObjectClient().SmartObjectGetList(filter, "UMUSer", "Get_Role_Users");
                         impersonatedUser = role.Rows[0]["Name"].ToString();
                         break;
                 }
                 //now impersonate them and action the worklist item.
                 var wlitem = k2helper.WorkflowClient().GetWorkListItem(items[x].ProcInstID + "_ " + items[x].ActInstDestID, impersonatedUser);
                 
                 actioned = ActionActivity(p, a, wlitem, impersonatedUser, true);
                 if (!actioned)
                 {
                     breakFromLoop = true; return;
                 }
                 //wlitem.Actions[a.Action].Execute();
                 //k2helper.WorkflowServer().RedirectWorklistItem(items[x].Destination, currentUser, items[x].ProcInstID, items[x].ActInstDestID, items[x].ID);
             }
             catch (Exception ex)
             {
                 if (ex.IsFatal())
                 {
                     throw;
                 }
                 string err = "Error getting worklist item : " + ex.Message;
                 FailTest(err, TestResultStage.ActivityExecutionError, p, a);
                 breakFromLoop = true; return;
             }
             if (!this.ProceedWithTest)
             {
                 breakFromLoop = true; return;
             }
             Thread.Sleep(1000);
         }
     }//end for
 }