Ejemplo n.º 1
0
        public WorklistCriteria ToApi()
        {
            WorklistCriteria worklistCriteria = new WorklistCriteria();

            worklistCriteria.Count      = (int)this.Count;
            worklistCriteria.StartIndex = (int)this.StartIndex;
            if (worklistCriteria.Count == 0)
            {
                worklistCriteria.Count = -1;
            }
            worklistCriteria.ManagedUser = this.ManagedUser;
            worklistCriteria.NoData      = true;
            worklistCriteria.Platform    = this.Platform;
            foreach (CriteriaFilter current in this.Filters)
            {
                object obj = current.Value;
                obj = K2Convert.FromString(current.Value, (DataType)current.ValueType);
                if (obj is string && (current.Comparison == CriteriaComparison.Like || current.Comparison == CriteriaComparison.NotLike))
                {
                    obj = "*" + (string)obj + "*";
                }
                worklistCriteria.AddFilterField((WCLogical)current.Logical, (WCField)current.Field, current.SubField, (WCCompare)current.Comparison, obj);
            }
            foreach (CriteriaSort current2 in this.Sorts)
            {
                worklistCriteria.AddSortField((WCField)current2.Field, current2.SubField, (WCSortOrder)current2.SortOrder);
            }
            return(worklistCriteria);
        }
Ejemplo n.º 2
0
        public Worklist GetWorklistItems(String searchTerm, Int32 skip, Int32 take, Dictionary <WCField, WCSortOrder> sorts, String impersonateUser)
        {
            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                {
                    k2Connection.ImpersonateUser("K2:" + impersonateUser);
                }

                var workCriteria = new WorklistCriteria {
                    NoData = true, Platform = "ASP"
                };

                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);
                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //  (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat);                //  ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);     //  OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);  //  OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);             //  )
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.
                workCriteria.AddFilterField(WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);

                workCriteria.StartIndex = skip;
                workCriteria.Count      = take;

                foreach (KeyValuePair <WCField, WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);
                }

                Worklist k2Worklist = k2Connection.OpenWorklist(workCriteria);

                return(k2Worklist);
            }
        }
Ejemplo n.º 3
0
        public Worklist GetWorklistItems(String searchTerm, Int32 skip, Int32 take, Dictionary<WCField, WCSortOrder> sorts, String impersonateUser)
        {
            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                    k2Connection.ImpersonateUser("K2:" + impersonateUser);

                var workCriteria = new WorklistCriteria { NoData = true, Platform = "ASP" };                                                
                                
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);
                    //String searchTermFormat = String.Format("% / % / % / % / %{0}%", searchTerm);
                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //  (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat);                //  ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);     //  OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);  //  OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);             //  )
                    //workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, searchTermFormat);
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.
                workCriteria.AddFilterField(WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);                 

                workCriteria.StartIndex = skip;
                workCriteria.Count = take;                
                
                foreach (KeyValuePair<WCField,WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);                                        
                }

                Worklist k2Worklist = k2Connection.OpenWorklist(workCriteria);      

                return k2Worklist;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get worklist items by worklist filter criterias
        /// </summary>
        /// <returns>The collection of worklist items</returns>
        public WorklistItemCollection OpenWorklist()
        {
            WorklistItemCollection result;

            try {
                using (Connection workflowClient = this.GetWorkflowClient()) {
                    WorklistCriteria criteria = new WorklistCriteria();
                    criteria.Platform = "ASP";
                    criteria.NoData   = true;
                    criteria.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Me", WCCompare.Equal, WCWorklistItemOwner.Me);
                    criteria.AddFilterField(WCLogical.Or, WCField.WorklistItemOwner, "Other", WCCompare.Equal, WCWorklistItemOwner.Other);
                    criteria.AddSortField(WCField.EventStartDate, WCSortOrder.Descending);
                    result = OpenWorklist(criteria);
                }
            } catch (UnauthorizedAccessException) {
                throw;
            } catch (SmartException ex) {
                throw ex;
            }
            return(result);
        }
        //opening worklist sample
        public static void OpenWorklistSamples()
        {
            //you must open a K2 connection first. We will wrap the K2 connection into a using statement to ensure that it is closed
            using (Connection K2Conn = new Connection())
            {
                K2Conn.Open("[servername]");
                //retrieve the entire worklist for the current user
                Worklist K2WList = K2Conn.OpenWorklist();

                //or retrieve the worklist for a specific platform ("platform" not really used that often anymore). The default platform for worklist items is ASP
                Worklist K2WList1 = K2Conn.OpenWorklist("ASP");

                //or retrieve the worklist for a specific platform and a user managed by the current user.
                //This requires that the reporting structure is set up correctly in the underlying user provider (Active Directory or custom user manager)
                Worklist K2WList2 = K2Conn.OpenWorklist("ASP", @"[domain\username]");

                //you can also retrieve the worklist with a criteria filter. OpenWorklist can be an expensive operation, so use criteria to perform server-side filtering of the worklist
                //for large worklists you should always use criteria to reduce the size of the worklist that is returned to the client
                WorklistCriteria K2Crit = new WorklistCriteria();
                //you can set up various combinations of filters and sorts in the criteria object. Refer to the product documentation for more samples
                //here, we are filtering for all workflows for the project K2Learning where the priority equals 1. We want to sort the task list by workflow start date
                K2Crit.AddFilterField(WCField.ProcessFolder, WCCompare.Equal, "[FolderName]");
                K2Crit.AddFilterField(WCLogical.And, WCField.ProcessPriority, WCCompare.Equal, 1);
                K2Crit.AddSortField(WCField.ProcessStartDate, WCSortOrder.Descending);
                Worklist K2WList3 = K2Conn.OpenWorklist(K2Crit);

                int numberOfTasks = K2WList.TotalCount;

                //once you have retrieved the worklist, you can iterate over the worklist items in the worklist
                foreach (WorklistItem K2WLItem in K2WList)
                {
                    string serialNumber = K2WLItem.SerialNumber;
                    string status       = K2WLItem.Status.ToString();
                    //to access more information, drill down into the relevant object contained in the worklist item
                    string Folio = K2WLItem.ProcessInstance.Folio;
                }
            }
        }
Ejemplo n.º 6
0
        public List<WorkflowItem> GetWorkflowItems(String searchTerm, Int32 skip, Int32 take, Dictionary<WCField, WCSortOrder> sorts, String impersonateUser, out Int32 count, out Int32 totalCount, List<Tuple<String, String, String>> extraFilters)
        {
            Tuple<String, String, String> cobEF = null;
            Tuple<String, String, String> yearEF = null;
            Tuple<String, String, String> descEF = null;
            Tuple<String, String, String> insdEF = null;
            Tuple<String, String, String> bkrEF = null;
            Tuple<String, String, String> uwrEF = null;
            Tuple<String, String, String> actEF = null;             

            if (extraFilters != null)
            {
                cobEF = extraFilters.FirstOrDefault(f => f.Item1 == "COBId");
                yearEF = extraFilters.FirstOrDefault(f => f.Item1 == "AccountYear");
                descEF = extraFilters.FirstOrDefault(f => f.Item1 == "Description");
                insdEF = extraFilters.FirstOrDefault(f => f.Item1 == "InsuredName");
                bkrEF = extraFilters.FirstOrDefault(f => f.Item1 == "BrokerPseudonym");
                uwrEF = extraFilters.FirstOrDefault(f => f.Item1 == "UnderwriterCode");
                actEF = extraFilters.FirstOrDefault(f => f.Item1 == "Activity");
            }
            String cobExtraFilter = cobEF == null ? String.Empty : cobEF.Item3;
            Int32 yearParse;
            Int32? yearExtraFilter = null;
            if (Int32.TryParse(yearEF == null ? String.Empty : yearEF.Item3, out yearParse))
                yearExtraFilter = yearParse;

            String descExtraFilter = descEF == null ? String.Empty : descEF.Item3;
            String insdExtraFilter = insdEF == null ? String.Empty : insdEF.Item3;
            String bkrExtraFilter = bkrEF == null ? String.Empty : bkrEF.Item3;
            String uwrExtraFilter = uwrEF == null ? String.Empty : uwrEF.Item3;
            String actExtraFilter = actEF == null ? String.Empty : actEF.Item3;

            List<WorkflowItem> retArray = new List<WorkflowItem>();
            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                    k2Connection.ImpersonateUser(impersonateUser);

                var workCriteria = new WorklistCriteria { NoData = true, Platform = "ASP" };
                
                //String propertyFilter = String.Format("% / {0} / {1} / % / %{2}%", uwrExtraFilter, searchTerm);
                String propertyFilter = String.Format("% / {0} / {1}%{2} / % / {3}",
                    String.IsNullOrEmpty(uwrExtraFilter) ? "%" : uwrExtraFilter,
                    cobExtraFilter,
                    yearExtraFilter == null ? String.Empty : yearExtraFilter.ToString().Substring(2),
                    String.IsNullOrEmpty(insdExtraFilter) ? "%" : "%" + insdExtraFilter + "%");
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);

                    //if (extraFilters.Count > 0)
                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //  (

                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //      (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat);                //          ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessData, "BPC", WCCompare.Equal, searchTerm); //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);     //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);  //          OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);             //      )     

                    if (extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.None, WCCompare.Equal, null);                //      AND
                        workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);       //      (
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);              //          ...
                        workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);         //      )                        
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                        //  TODO: OR event name?
                        //workCriteria.AddFilterField(WCField.EventName, WCCompare.Equal, actExtraFilter);                     //     ...
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);                     //     ...

                    //if (extraFilters.Count > 0)
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);             //  )
                    //workCriteria.AddFilterField(WCField., WCField.None, WCCompare.Equal, null);
                }
                else
                {
                    if (extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);
                        
                    }
                    
                    if (!String.IsNullOrEmpty(actExtraFilter))
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal , actExtraFilter);                     //     ...
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.
                //  workCriteria.AddFilterField(WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);

                //workCriteria.AddSortField(WCField.ActivityStartDate, WCSortOrder.Descending);

                workCriteria.StartIndex = skip;
                workCriteria.Count = take;

                foreach (KeyValuePair<WCField, WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);
                }

                Worklist k2Worklist = k2Connection.OpenWorklist(workCriteria);

                foreach (WorklistItem item in k2Worklist)
                {
                    retArray.Add(new WorkflowItem(item));
                }

                count = k2Worklist.TotalCount;
                //  Total records before filter
                totalCount = k2Worklist.TotalCount; 

                return retArray;
            }
        }
Ejemplo n.º 7
0
        public List <WorkflowItem> GetWorkflowItems(String searchTerm, Int32 skip, Int32 take, Dictionary <WCField, WCSortOrder> sorts, String impersonateUser, out Int32 count, out Int32 totalCount, List <Tuple <String, String, String> > extraFilters)
        {
            Tuple <String, String, String> cobEF  = null;
            Tuple <String, String, String> yearEF = null;
            Tuple <String, String, String> insdEF = null;
            Tuple <String, String, String> uwrEF  = null;
            Tuple <String, String, String> actEF  = null;

            if (extraFilters != null)
            {
                cobEF  = extraFilters.FirstOrDefault(f => f.Item1 == "COBId");
                yearEF = extraFilters.FirstOrDefault(f => f.Item1 == "AccountYear");
                insdEF = extraFilters.FirstOrDefault(f => f.Item1 == "InsuredName");
                uwrEF  = extraFilters.FirstOrDefault(f => f.Item1 == "UnderwriterCode");
                actEF  = extraFilters.FirstOrDefault(f => f.Item1 == "Activity");
            }
            String cobExtraFilter = cobEF == null ? String.Empty : cobEF.Item3;
            Int32  yearParse;
            Int32? yearExtraFilter = null;

            if (Int32.TryParse(yearEF == null ? String.Empty : yearEF.Item3, out yearParse))
            {
                yearExtraFilter = yearParse;
            }

            String insdExtraFilter = insdEF == null ? String.Empty : insdEF.Item3;
            String uwrExtraFilter  = uwrEF == null ? String.Empty : uwrEF.Item3;
            String actExtraFilter  = actEF == null ? String.Empty : actEF.Item3;

            List <WorkflowItem> retArray = new List <WorkflowItem>();

            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                {
                    k2Connection.ImpersonateUser(impersonateUser);
                }

                var workCriteria = new WorklistCriteria {
                    NoData = true, Platform = "ASP"
                };

                String propertyFilter = String.Format("% / {0} / {1}%{2} / % / {3}",
                                                      String.IsNullOrEmpty(uwrExtraFilter) ? "%" : uwrExtraFilter,
                                                      cobExtraFilter,
                                                      yearExtraFilter == null ? String.Empty : yearExtraFilter.ToString().Substring(2),
                                                      String.IsNullOrEmpty(insdExtraFilter) ? "%" : "%" + insdExtraFilter + "%");
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);

                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //  (

                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);           //      (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat);                //          ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessData, "BPC", WCCompare.Equal, searchTerm); //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);     //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);  //          OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);             //      )

                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.None, WCCompare.Equal, null);                //      AND
                        workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);       //      (
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);              //          ...
                        workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);         //      )
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                    {
                        //  TODO: OR event name?
                        //workCriteria.AddFilterField(WCField.EventName, WCCompare.Equal, actExtraFilter);                     //     ...
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter); //     ...
                    }
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);                //  )
                }
                else
                {
                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);                     //     ...
                    }
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.

                workCriteria.StartIndex = skip;
                workCriteria.Count      = take;

                foreach (KeyValuePair <WCField, WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);
                }

                Worklist k2Worklist = k2Connection.OpenWorklist(workCriteria);

                foreach (WorklistItem item in k2Worklist)
                {
                    retArray.Add(new WorkflowItem(item));
                }

                count = k2Worklist.TotalCount;
                //  Total records before filter
                totalCount = k2Worklist.TotalCount;

                return(retArray);
            }
        }
Ejemplo n.º 8
0
        public async Task <GetUserWorkflowItemsDto> GetWorkflowItemsAsync(String searchTerm, Int32 skip, Int32 take,
                                                                          Dictionary <WCField, WCSortOrder> sorts,
                                                                          String impersonateUser,
                                                                          List <Tuple <String, String, String> >
                                                                          extraFilters)
        {
            Tuple <String, String, String> cobEF  = null;
            Tuple <String, String, String> yearEF = null;
            Tuple <String, String, String> insdEF = null;
            Tuple <String, String, String> uwrEF  = null;
            Tuple <String, String, String> actEF  = null;

            if (extraFilters != null)
            {
                cobEF  = extraFilters.FirstOrDefault(f => f.Item1 == "COBId");
                yearEF = extraFilters.FirstOrDefault(f => f.Item1 == "AccountYear");
                insdEF = extraFilters.FirstOrDefault(f => f.Item1 == "InsuredName");
                uwrEF  = extraFilters.FirstOrDefault(f => f.Item1 == "UnderwriterCode");
                actEF  = extraFilters.FirstOrDefault(f => f.Item1 == "Activity");
            }
            String cobExtraFilter = cobEF == null ? String.Empty : cobEF.Item3;
            Int32  yearParse;
            Int32? yearExtraFilter = null;

            if (Int32.TryParse(yearEF == null ? String.Empty : yearEF.Item3, out yearParse))
            {
                yearExtraFilter = yearParse;
            }

            String insdExtraFilter = insdEF == null ? String.Empty : insdEF.Item3;
            String uwrExtraFilter  = uwrEF == null ? String.Empty : uwrEF.Item3;
            String actExtraFilter  = actEF == null ? String.Empty : actEF.Item3;

            List <WorkflowItem> retArray = new List <WorkflowItem>();

            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                {
                    k2Connection.ImpersonateUser(impersonateUser);
                }

                var workCriteria = new WorklistCriteria {
                    NoData = true, Platform = "ASP"
                };

                String propertyFilter = String.Format("% / {0} / {1}%{2} / % / {3}",
                                                      String.IsNullOrEmpty(uwrExtraFilter) ? "%" : uwrExtraFilter,
                                                      cobExtraFilter,
                                                      yearExtraFilter == null
                                                          ? String.Empty
                                                          : yearExtraFilter.ToString().Substring(2),
                                                      String.IsNullOrEmpty(insdExtraFilter)
                                                          ? "%"
                                                          : "%" + insdExtraFilter + "%");
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);

                    //if (extraFilters.Count > 0)
                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null); //  (

                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null); //      (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat);      //          ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessData, "BPC", WCCompare.Equal, searchTerm);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);
                    //      )

                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.None, WCCompare.Equal, null); //      AND
                        workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);
                        //      (
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);
                        //          ...
                        workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);
                        //      )
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                    {
                        //  TODO: OR event name?
                        //workCriteria.AddFilterField(WCField.EventName, WCCompare.Equal, actExtraFilter);                     //     ...
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);
                    }
                    //     ...

                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null); //  )
                }
                else
                {
                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);
                    }
                    //     ...
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.
                //  workCriteria.AddFilterField(WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);

                workCriteria.StartIndex = skip;
                workCriteria.Count      = take;

                foreach (KeyValuePair <WCField, WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);
                }

                var dto  = new GetUserWorkflowItemsDto();
                var task = new Task <GetUserWorkflowItemsDto>
                           (
                    () =>
                {
                    var k2Worklist = k2Connection.OpenWorklist(workCriteria);

                    retArray.AddRange(from WorklistItem item in k2Worklist select new WorkflowItem(item));

                    dto.WorkflowItemsArray  = retArray.ToArray();
                    dto.TotalDisplayRecords = k2Worklist.TotalCount;
                    dto.TotalRecords        = k2Worklist.TotalCount;

                    return(dto);
                }
                           );

                // Start the task
                task.Start();

                // Get the result from the task - analogous to
                // calling task.Result (without the thread blocking)
                var result = await task;
                return(result);
            }
        }
Ejemplo n.º 9
0
        public List <Worklist> GetWorklist()
        {
            var procInsts = new List <Worklist>();
            var K2Crit    = new WorklistCriteria();

            K2Crit.NoData   = true;  //faster, does not return the data for each item
            K2Crit.Platform = "ASP"; //helps when multiple platform are used

            K2Crit.AddFilterField(
                WCLogical.Or, WCField.WorklistItemOwner, "Me",
                WCCompare.Equal, WCWorklistItemOwner.Me
                );

            K2Crit.AddFilterField(
                WCLogical.Or, WCField.WorklistItemOwner, "Other",
                WCCompare.Equal, WCWorklistItemOwner.Other
                );

            K2Crit.AddSortField(WCField.ActivityStartDate, WCSortOrder.Descending);

            try
            {
                var K2WList = _connection.OpenWorklist(K2Crit);
                foreach (WorklistItem item in K2WList)
                {
                    var procInst = new Worklist()
                    {
                        ProcInstId    = item.ProcessInstance.ID,
                        ActInstDestId = item.ActivityInstanceDestination.ID,
                        Serial        = item.SerialNumber,
                        Folio         = item.ProcessInstance.Folio,
                        WorkflowPath  = item.ProcessInstance.FullName,
                        OpenFormUrl   = item.Data,
                        Originator    = item.ProcessInstance.Originator.Name,
                        ManagedUser   = ManagedUser,
                        Priority      = item.ProcessInstance.Priority,
                        AllocatedUser = item.AllocatedUser,
                        OpenedBy      = (item.Status == WorklistStatus.Allocated) ? item.AllocatedUser : string.Empty,
                        Status        = (item.Status == WorklistStatus.Allocated) ? WorklistStatus.Open.ToString() : WorklistStatus.Available.ToString(),
                        ActivityName  = item.ActivityInstanceDestination.Name
                    };

                    foreach (Action action in item.Actions)
                    {
                        if (action.Batchable)
                        {
                            procInst.Actions.Add(action.Name);
                        }
                    }

                    var  existed = procInsts.SingleOrDefault(p => p.ProcInstId == procInst.ProcInstId);
                    bool skip    = false;
                    if (existed != null)
                    {
                        skip = (existed.AllocatedUser == ManagedUser);
                        // Removed duplicated item for OOF or Shared
                        if (!skip)
                        {
                            procInsts.Remove(existed);
                        }
                    }
                    if (!skip)
                    {
                        procInsts.Add(procInst);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(procInsts);
        }
        public async Task<GetUserWorkflowItemsDto> GetWorkflowItemsAsync(String searchTerm, Int32 skip, Int32 take,
                                                                         Dictionary<WCField, WCSortOrder> sorts,
                                                                         String impersonateUser,
                                                                         List<Tuple<String, String, String>>
                                                                             extraFilters)
        {
            Tuple<String, String, String> cobEF = null;
            Tuple<String, String, String> yearEF = null;
            Tuple<String, String, String> insdEF = null;
            Tuple<String, String, String> uwrEF = null;
            Tuple<String, String, String> actEF = null;

            if (extraFilters != null)
            {
                cobEF = extraFilters.FirstOrDefault(f => f.Item1 == "COBId");
                yearEF = extraFilters.FirstOrDefault(f => f.Item1 == "AccountYear");
                insdEF = extraFilters.FirstOrDefault(f => f.Item1 == "InsuredName");
                uwrEF = extraFilters.FirstOrDefault(f => f.Item1 == "UnderwriterCode");
                actEF = extraFilters.FirstOrDefault(f => f.Item1 == "Activity");
            }
            String cobExtraFilter = cobEF == null ? String.Empty : cobEF.Item3;
            Int32 yearParse;
            Int32? yearExtraFilter = null;
            if (Int32.TryParse(yearEF == null ? String.Empty : yearEF.Item3, out yearParse))
                yearExtraFilter = yearParse;

            String insdExtraFilter = insdEF == null ? String.Empty : insdEF.Item3;
            String uwrExtraFilter = uwrEF == null ? String.Empty : uwrEF.Item3;
            String actExtraFilter = actEF == null ? String.Empty : actEF.Item3;

            List<WorkflowItem> retArray = new List<WorkflowItem>();
            using (var k2Connection = new Connection())
            {
                ConnectionSetup k2Setup = new ConnectionSetup();
                k2Setup.ConnectionString = Properties.Settings.Default.WorkflowServerConnectionString;

                k2Connection.Open(k2Setup);

                if (!String.IsNullOrEmpty(impersonateUser))
                    k2Connection.ImpersonateUser(impersonateUser);

                var workCriteria = new WorklistCriteria { NoData = true, Platform = "ASP" };

                String propertyFilter = String.Format("% / {0} / {1}%{2} / % / {3}",
                                                      String.IsNullOrEmpty(uwrExtraFilter) ? "%" : uwrExtraFilter,
                                                      cobExtraFilter,
                                                      yearExtraFilter == null
                                                          ? String.Empty
                                                          : yearExtraFilter.ToString().Substring(2),
                                                      String.IsNullOrEmpty(insdExtraFilter)
                                                          ? "%"
                                                          : "%" + insdExtraFilter + "%");
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    String searchTermFormat = String.Format("%{0}%", searchTerm);

                    //if (extraFilters.Count > 0)
                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null); //  (

                    workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null); //      (
                    workCriteria.AddFilterField(WCField.ActivityName, WCCompare.Like, searchTermFormat); //          ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessData, "BPC", WCCompare.Equal, searchTerm);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.EventName, WCCompare.Like, searchTermFormat);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.Or, WCField.ProcessFolio, WCCompare.Like, searchTermFormat);
                    //          OR ...
                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);
                    //      )     

                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCLogical.And, WCField.None, WCCompare.Equal, null); //      AND
                        workCriteria.AddFilterField(WCLogical.StartBracket, WCField.None, WCCompare.Equal, null);
                        //      (
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);
                        //          ...
                        workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null);
                        //      )                        
                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                        //  TODO: OR event name?
                        //workCriteria.AddFilterField(WCField.EventName, WCCompare.Equal, actExtraFilter);                     //     ...
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);
                    //     ...

                    workCriteria.AddFilterField(WCLogical.EndBracket, WCField.None, WCCompare.Equal, null); //  )
                }
                else
                {
                    if (extraFilters != null && extraFilters.Count > 0)
                    {
                        workCriteria.AddFilterField(WCField.ProcessFolio, WCCompare.Like, propertyFilter);

                    }

                    if (!String.IsNullOrEmpty(actExtraFilter))
                        workCriteria.AddFilterField(WCLogical.And, WCField.ActivityName, WCCompare.Equal, actExtraFilter);
                    //     ...
                }

                //  No AND required - seems like bug - this bit gets put in a different bit of the query K2 creates.
                //  Hide allocated items like the SharePoint K2 worlist does by default.
                //  workCriteria.AddFilterField(WCField.WorklistItemStatus, WCCompare.NotEqual, WorklistStatus.Allocated);
                
                workCriteria.StartIndex = skip;
                workCriteria.Count = take;

                foreach (KeyValuePair<WCField, WCSortOrder> sort in sorts)
                {
                    workCriteria.AddSortField(sort.Key, sort.Value);
                }

                var dto = new GetUserWorkflowItemsDto();
                var task = new Task<GetUserWorkflowItemsDto>
                    (
                    () =>
                    {
                        var k2Worklist = k2Connection.OpenWorklist(workCriteria);

                        retArray.AddRange(from WorklistItem item in k2Worklist select new WorkflowItem(item));

                        dto.WorkflowItemsArray = retArray.ToArray();
                        dto.TotalDisplayRecords = k2Worklist.TotalCount;
                        dto.TotalRecords = k2Worklist.TotalCount;

                        return dto;
                    }
                    );

                // Start the task
                task.Start();

                // Get the result from the task - analogous to 
                // calling task.Result (without the thread blocking)
                var result = await task;
                return result;
            }
        }