Beispiel #1
0
        public IEnumerable <TEntity> GetEntities(Caml.View spView)
        {
            var entities = Enumerable.Empty <TEntity>();

            if (_args == null || spView == null)
            {
                return(entities);
            }

            string pagingInfo = null;

            ProcessItems(spView, false, false, (items) =>
            {
                entities = entities.Concat(ToEntities(items));

                if (items.ListItemCollectionPosition != null)
                {
                    pagingInfo = items.ListItemCollectionPosition.PagingInfo;
                }
                else
                {
                    pagingInfo = null;
                }
                //_args.PrevPagingInfo = _args.PagingInfo;
                //_args.PagingInfo = pagingInfo;
            });
            _args.OnAfterEvent?.Invoke(pagingInfo);
            return(entities);
        }
Beispiel #2
0
        public async Task <IEnumerable <TEntity> > GetEntitiesAsync(Caml.View spView)
        {
            var entities = Enumerable.Empty <TEntity>();

            if (_args == null || spView == null)
            {
                return(entities);
            }
            await ProcessItemsAsync(spView, false, false, (items) => entities = entities.Concat(ToEntities(items)));

            return(entities);
        }
Beispiel #3
0
        public ListItemCollection GetItems(Caml.View spView, ListItemCollectionPosition position, bool countOnly, bool fieldValuesAsText)
        {
            if (_args == null || spView == null)
            {
                return(null);
            }

            string folderUrl = string.IsNullOrWhiteSpace(this._args.FolderUrl)
                ? null
                : new Uri(string.Concat(this._args.Context.SiteUrl.TrimEnd('/'), "/", string.IsNullOrEmpty(_args.ListUrl) ? "" : $"{_args.ListUrl.Trim('/')}/", (!string.IsNullOrEmpty(_args.ListUrl) ? this._args.FolderUrl.Replace(_args.ListUrl, "") : this._args.FolderUrl).TrimStart('/'))).LocalPath;
            var list = GetList();

            //if (list == null)
            //{
            //    Check.NotNull(list, nameof(List));
            //}
            //if (spView == null)
            //{
            //    Check.NotNull(spView, nameof(Caml.View));
            //}
            if (list != null && spView != null)
            {
                var items = list.GetItems(new CamlQuery()
                {
                    DatesInUtc = true, FolderServerRelativeUrl = folderUrl, ViewXml = spView.ToString(true), ListItemCollectionPosition = position
                });
                if (countOnly)
                {
                    items.Context.Load(items, item => item.ListItemCollectionPosition, item => item.Include(i => i.Id));
                    return(items);
                }
                else
                {
                    if (_args.IncludeItemPermissions)
                    {
                        items.Context.Load(items, item => item.Include(i => i.EffectiveBasePermissions));
                    }
                    if (/*fieldValuesAsText*/ false)
                    {
                        //BUG: NOT working!
                        items.Context.Load(items, item => item.ListItemCollectionPosition, item => item.Include(i => i.FieldValuesAsText));
                    }
                    else
                    {
                        items.Context.Load(items, item => item.ListItemCollectionPosition);
                    }
                    return(items);
                }
            }
            return(null);
        }
Beispiel #4
0
        public async Task <IEnumerable <TEntity> > GetEntitiesAsync(Type type, Caml.View spView)
        {
            CheckEntityType(type);
            ListItemCollectionPosition position = null;
            var entities = Enumerable.Empty <TEntity>();

            if (_args == null || spView == null)
            {
                return(entities);
            }

            var rowLimit  = spView.Limit;
            int itemCount = 0;

            do
            {
                if (_args.BatchSize > 0)
                {
                    if (rowLimit > 0)
                    {
                        spView.Limit = Math.Min(rowLimit - itemCount, _args.BatchSize);
                    }
                    else
                    {
                        spView.Limit = _args.BatchSize;
                    }
                    if (spView.Limit == 0)
                    {
                        break;
                    }
                }
                var items = GetItems(spView, position);
                if (items != null)
                {
                    await items.Context.ExecuteQueryAsync();

                    if (_args.BatchSize > 0)
                    {
                        position = items.ListItemCollectionPosition;
                    }
                    itemCount += items.Count;
                    entities   = entities.Concat(MapEntities(items, type));
                }
            }while (position != null);

            spView.Limit = rowLimit;
            return(entities);
        }
Beispiel #5
0
        public ListItemCollection GetItems(Caml.View spView, ListItemCollectionPosition position)
        {
            var list = GetList();

            if (list != null)
            {
                var items = list.GetItems(new CamlQuery()
                {
                    ViewXml = spView.ToString(true), ListItemCollectionPosition = position
                });
                items.Context.Load(items, item => item.Include(i => i.EffectiveBasePermissions));
                items.Context.Load(items, item => item.ListItemCollectionPosition);
                return(items);
            }
            return(null);
        }
Beispiel #6
0
        public async Task ProcessItemsAsync(Caml.View spView, bool countOnly, bool fieldValuesAsText, Action <ListItemCollection> action)
        {
            if (_args == null || spView == null)
            {
                return;
            }

            if (action != null)
            {
                var rowLimit  = spView.Limit;
                int itemCount = 0;
                ListItemCollectionPosition position = null;
                do
                {
                    if (_args.BatchSize > 0)
                    {
                        if (rowLimit > 0)
                        {
                            spView.Limit = Math.Min(rowLimit - itemCount, _args.BatchSize);
                        }
                        else
                        {
                            spView.Limit = _args.BatchSize;
                        }
                        if (spView.Limit == 0)
                        {
                            break;
                        }
                    }
                    var items = GetItems(spView, position, countOnly, fieldValuesAsText);
                    if (items != null)
                    {
                        await items.Context.ExecuteQueryAsync();

                        if (_args.BatchSize > 0)
                        {
                            position = items.ListItemCollectionPosition;
                        }
                        itemCount += items.Count;
                        action(items);
                    }
                }while (position != null);
                spView.Limit = rowLimit;
            }
        }
Beispiel #7
0
        public IEnumerable <ListItem> GetItems(Caml.View spView, bool fieldValuesAsText, out string pagingInfo)
        {
            var listItems = Enumerable.Empty <ListItem>();

            pagingInfo = null;
            if (_args == null || spView == null)
            {
                return(listItems);
            }

            ListItemCollectionPosition position = null;

            ProcessItems(spView, false, fieldValuesAsText, (items) =>
            {
                listItems = listItems.Concat(items.Cast <ListItem>());
                position  = items.ListItemCollectionPosition;
            });
            if (position != null)
            {
                pagingInfo = position.PagingInfo;
            }
            _args.OnAfterEvent?.Invoke(pagingInfo);
            return(listItems);
        }
Beispiel #8
0
 public PagedExpressionVisitor(SpQueryArgs <TContext> args, PagedExpression <TContext /*, TEntity*/> expression, Caml.View spView) : base(args, null)
 {
     _args       = args;
     _expression = expression;
     _spView     = spView;
 }
Beispiel #9
0
 internal SpGeneratorQueryModelVisitor([NotNull] SpQueryArgs <TContext> args, Caml.View spView)
 {
     _args   = args;
     _spView = spView;
 }
Beispiel #10
0
        public void ProcessItems(Caml.View spView, bool countOnly, bool fieldValuesAsText, Action <ListItemCollection> action)
        {
            if (_args == null || spView == null)
            {
                return;
            }

            if (action != null)
            {
                var rowLimit  = spView.Limit;
                int itemCount = 0;
                int batchSize = _args.BatchSize;
                if (countOnly)
                {
                    _args.BatchSize = Math.Max(1000, batchSize);
                }
                ListItemCollectionPosition position = _args.IsPaged && !string.IsNullOrEmpty(_args.PagingInfo)
                  ? new ListItemCollectionPosition()
                {
                    PagingInfo = _args.PagingInfo
                } : null;
                try
                {
                    Debug.WriteLine($"# Entity: {typeof(TEntity)}");
                    Debug.WriteLine($"# List: {_args}");
                    Debug.WriteLine($"# Folder Url: {_args.FolderUrl}");
                    Debug.WriteLine($"# Paging Info: {_args.PagingInfo}");
                    //Debug.WriteLine($"# Previous Paging Info: {_args.PrevPagingInfo}");
                    Debug.WriteLine("# SP Query:");
                    Debug.Write(spView);
                    Debug.WriteLine("");

                    do
                    {
                        if (_args.BatchSize > 0)
                        {
                            if (rowLimit > 0)
                            {
                                spView.Limit = Math.Min(rowLimit - itemCount, _args.BatchSize);
                            }
                            else
                            {
                                spView.Limit = _args.BatchSize;
                            }
                            if (spView.Limit == 0)
                            {
                                break;
                            }
                        }
                        var items = GetItems(spView, position, countOnly, fieldValuesAsText);
                        if (items != null)
                        {
                            items.Context.ExecuteQuery();
                            if (_args.BatchSize > 0)
                            {
                                position = items.ListItemCollectionPosition;
                            }
                            itemCount += items.Count;
                            action(items);
                        }
                    }while (position != null);
                }
                finally
                {
                    spView.Limit    = rowLimit;
                    _args.BatchSize = batchSize;
                }
            }
        }