public void ProcessListItems(SPList list, SPQuery query, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (itemsProcessor == null)
            {
                throw new ArgumentNullException("itemsProcessor");
            }

            if (!list.HasExternalDataSource && (list.ItemCount == 0))
            {
                return;
            }

            if (list.HasExternalDataSource && (query.RowLimit == 0))
            {
                query.RowLimit = 0x7fffffff;
            }
            else if ((query.RowLimit == 0) || (query.RowLimit == 0x7fffffff))
            {
                query.RowLimit = (uint)(string.IsNullOrEmpty(query.ViewFields) ? 200 : 0x7d0);
            }

            if (!list.HasExternalDataSource && StrictQuerySemantics)
            {
                query.QueryThrottleMode = SPQueryThrottleOption.Strict;
            }

            do
            {
                SPListItemCollection items = list.GetItems(query);

                try
                {
                    itemsProcessor(items);
                }
                catch (System.Exception exception)
                {
                    if ((errorCallout == null) || errorCallout(items, exception))
                    {
                        throw;
                    }
                }

                query.ListItemCollectionPosition = items.ListItemCollectionPosition;
            } while (!ShouldCancel(IterationGranularity.Item) && query.ListItemCollectionPosition != null);
        }
        public void ProcessListItems(SPList list, string strQuery, uint rowLimit, bool fRecursive, SPFolder folder, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            if (itemsProcessor == null)
            {
                throw new ArgumentNullException("itemsProcessor");
            }

            var query = new SPQuery();

            if (!string.IsNullOrEmpty(strQuery))
            {
                query.Query = strQuery;
            }

            query.RowLimit          = rowLimit;
            query.QueryThrottleMode = SPQueryThrottleOption.Override;

            if (folder != null)
            {
                query.Folder = folder;
            }

            if (fRecursive)
            {
                query.ViewAttributes = "Scope=\"RecursiveAll\"";
            }

            ProcessListItems(list, query, itemsProcessor, errorCallout);
        }
 public void ProcessListItems(SPList list, string strQuery, uint rowLimit, bool fRecursive, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
 {
     ProcessListItems(list, strQuery, rowLimit, fRecursive, null, itemsProcessor, errorCallout);
 }
 public void ProcessListItems(SPList list, string strQuery, bool fRecursive, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
 {
     ProcessListItems(list, strQuery, 0, fRecursive, itemsProcessor, errorCallout);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Process ListItems batch by batch
        /// </summary>
        /// <param name="listName">ListName</param>
        /// <param name="camlQuery">CamlQuery</param>
        /// <param name="itemsProcessor">itemprocessor delegate</param>
        /// <param name="errorCallout">error delegate</param>
        public void ProcessListItems(string listName, CamlQuery camlQuery, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
        {
            List      list  = _context.Web.Lists.GetByTitle(listName);
            CamlQuery query = camlQuery;

            ListItemCollectionPosition position = null;

            query.ListItemCollectionPosition = position;

            while (true)
            {
                ListItemCollection listItems = list.GetItems(query);
                _context.Load(listItems, items => items.ListItemCollectionPosition);
                _context.ExecuteQuery();
                try
                {
                    itemsProcessor(listItems);
                }
                catch (System.Exception ex)
                {
                    if (errorCallout == null || errorCallout(listItems, ex))
                    {
                        throw;
                    }
                }

                if (listItems.ListItemCollectionPosition == null)
                {
                    return;
                }
                else
                {
                    /*if query contains lookup column filter last batch returns null
                     * by removing the lookup column in paginginfo query will return next records
                     */
                    string        pagingInfo         = listItems.ListItemCollectionPosition.PagingInfo;
                    string[]      parameters         = pagingInfo.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                    List <string> requiredParameters = new List <string>();
                    foreach (string str in parameters)
                    {
                        if (str.Contains("Paged=") || str.Contains("p_ID="))
                        {
                            requiredParameters.Add(str);
                        }
                    }

                    pagingInfo = string.Join("&", requiredParameters.ToArray());
                    listItems.ListItemCollectionPosition.PagingInfo = pagingInfo;
                    query.ListItemCollectionPosition = listItems.ListItemCollectionPosition;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Process ListItems batch by batch
        /// </summary>
        /// <param name="listName">ListName</param>
        /// <param name="camlQuery">CamlQuery</param>
        /// <param name="itemsProcessor">itemprocessor delegate</param>
        /// <param name="errorCallout">error delegate</param>
        public void ProcessListItems(string listName, CamlQuery camlQuery, ItemsProcessor itemsProcessor, ItemsProcessorErrorCallout errorCallout)
        {
            List list = _context.Web.Lists.GetByTitle(listName);
            CamlQuery query = camlQuery;

            ListItemCollectionPosition position = null;
            query.ListItemCollectionPosition = position;

            while (true)
            {
                ListItemCollection listItems = list.GetItems(query);
                _context.Load(listItems, items => items.ListItemCollectionPosition);
                _context.ExecuteQuery();
                try
                {
                    itemsProcessor(listItems);
                }
                catch (System.Exception ex)
                {
                    if (errorCallout == null || errorCallout(listItems, ex))
                    {
                        throw;
                    }
                }

                if (listItems.ListItemCollectionPosition == null)
                {
                    return;
                }
                else
                {
                    /*if query contains lookup column filter last batch returns null 
                     by removing the lookup column in paginginfo query will return next records
                     */
                    string pagingInfo = listItems.ListItemCollectionPosition.PagingInfo;
                    string[] parameters = pagingInfo.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                    List<string> requiredParameters = new List<string>();
                    foreach (string str in parameters)
                    {
                        if (str.Contains("Paged=") || str.Contains("p_ID="))
                            requiredParameters.Add(str);
                    }

                    pagingInfo = string.Join("&", requiredParameters.ToArray());
                    listItems.ListItemCollectionPosition.PagingInfo = pagingInfo;
                    query.ListItemCollectionPosition = listItems.ListItemCollectionPosition;
                }

            }

        }