示例#1
0
        /// <summary>
        /// Returns the total number of entities that correspond to the specified filter criteria.
        /// </summary>
        /// <param name="containerTitle"></param>
        /// <param name="path"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public virtual int CountEntities(string containerTitle, string path, EntityFilterCriteria criteria)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                return(0);
            }

            ContentIterator.EnsureContentTypeIndexed(list);

            var documentStoreEntityContentTypeId = list.ContentTypes.BestMatch(new SPContentTypeId(Constants.DocumentStoreEntityContentTypeId));

            var camlQuery = @"<Where>
    <Eq>
      <FieldRef Name=""ContentTypeId"" />
      <Value Type=""ContentTypeId"">" + documentStoreEntityContentTypeId + @"</Value>
    </Eq>
</Where>";

            var viewFields = SPDocumentStoreHelper.GetDocumentStoreEntityViewFieldsXml();

            var filteredListItems = new List <SPListItem>();

            var itemsIterator = new ContentIterator();

            itemsIterator.ProcessListItems(list, camlQuery + ContentIterator.ItemEnumerationOrderByPath + viewFields, ContentIterator.MaxItemsPerQueryWithViewFields, true, folder,
                                           spListItems =>
            {
                var listItems = FilterListItemEntities(spListItems.OfType <SPListItem>(),
                                                       criteria);
                // ReSharper disable AccessToModifiedClosure
                filteredListItems.AddRange(listItems);
                // ReSharper restore AccessToModifiedClosure
            },
                                           null);

            return(filteredListItems.Count);
        }
示例#2
0
        /// <summary>
        /// Lists all folders contained in the specified container.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public virtual IList <Folder> ListAllFolders(string containerTitle, string path)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                return(null);
            }

            ContentIterator.EnsureContentTypeIndexed(list);

            var folderContentTypeId = list.ContentTypes.BestMatch(SPBuiltInContentTypeId.Folder);

            var camlQuery = @"<Where>
    <Eq>
      <FieldRef Name=""ContentTypeId"" />
      <Value Type=""ContentTypeId"">" + folderContentTypeId + @"</Value>
    </Eq>
</Where>";

            var result        = new List <Folder>();
            var itemsIterator = new ContentIterator();

            itemsIterator.ProcessListItems(list, camlQuery + ContentIterator.ItemEnumerationOrderByPath, ContentIterator.MaxItemsPerQuery, false, folder,
                                           spListItems =>
            {
                // ReSharper disable ConvertToLambdaExpression
                result.AddRange(spListItems.OfType <SPListItem>()
                                .Select(
                                    spListItem =>
                                    SPDocumentStoreHelper.MapFolderFromSPFolder(
                                        spListItem.Folder)));
                // ReSharper restore ConvertToLambdaExpression
            },
                                           null);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Lists the entities.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="path">The path.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public virtual IList <Entity> ListEntities(string containerTitle, string path, EntityFilterCriteria criteria)
        {
            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, path) == false)
            {
                return(null);
            }

            ContentIterator.EnsureContentTypeIndexed(list);

            var documentStoreEntityContentTypeId = list.ContentTypes.BestMatch(new SPContentTypeId(Constants.DocumentStoreEntityContentTypeId));

            var camlQuery = @"<Where>
    <Eq>
      <FieldRef Name=""ContentTypeId"" />
      <Value Type=""ContentTypeId"">" + documentStoreEntityContentTypeId + @"</Value>
    </Eq>
</Where>";

            var viewFields = SPDocumentStoreHelper.GetDocumentStoreEntityViewFieldsXml();

            var filteredListItems = new List <SPListItem>();

            var itemsIterator = new ContentIterator();

            itemsIterator.ProcessListItems(list, camlQuery + ContentIterator.ItemEnumerationOrderByPath + viewFields, ContentIterator.MaxItemsPerQueryWithViewFields, true, folder,
                                           spListItems =>
            {
                var listItems = FilterListItemEntities(spListItems.OfType <SPListItem>(),
                                                       criteria);
                // ReSharper disable AccessToModifiedClosure
                filteredListItems.AddRange(listItems);
                // ReSharper restore AccessToModifiedClosure
            },
                                           null);

            var result = new List <Entity>();

            if (criteria == null || criteria.IncludeData)
            {
                result.AddRange(
                    filteredListItems
                    .Select(li =>
                {
                    // ReSharper disable AccessToDisposedClosure
                    var listItemFolder = li.Folder ?? web.GetFolder(SPUtility.GetUrlDirectory(li.Url));
                    // ReSharper restore AccessToDisposedClosure

                    return(SPDocumentStoreHelper.MapEntityFromDocumentSet(
                               DocumentSet.GetDocumentSet(listItemFolder), null));
                })
                    .Where(entity => entity != null)
                    );

                ProcessEntityList(containerTitle, path, criteria, folder, result);
            }
            else
            {
                if (criteria.Skip.HasValue)
                {
                    filteredListItems = filteredListItems.Skip((int)criteria.Skip.Value).ToList();
                }

                if (criteria.Top.HasValue)
                {
                    filteredListItems = filteredListItems.Take((int)criteria.Top.Value).ToList();
                }

                result.AddRange(
                    filteredListItems
                    .Select(
                        li =>
                        SPDocumentStoreHelper.MapEntityFromDocumentSet(DocumentSet.GetDocumentSet(li.Folder), null, null))
                    .Where(entity => entity != null)
                    );

                ProcessEntityList(containerTitle, path, criteria, folder, result);
            }

            return(result);
        }