Beispiel #1
0
        private Dictionary <string, object> CreateFieldDictionary(Content content, bool isCollectionItem)
        {
            var projector = Projector.Create(this.ODataRequest, isCollectionItem, content);

            return(projector.Project(content));
        }
Beispiel #2
0
        private List <Dictionary <string, object> > ProcessOperationQueryResponse(ChildrenDefinition qdef, ODataRequest req, out int count)
        {
            var cdef = new ChildrenDefinition
            {
                PathUsage            = qdef.PathUsage,
                ContentQuery         = qdef.ContentQuery,
                Top                  = req.Top > 0 ? req.Top : qdef.Top,
                Skip                 = req.Skip > 0 ? req.Skip : qdef.Skip,
                Sort                 = req.Sort != null && req.Sort.Any() ? req.Sort : qdef.Sort,
                CountAllPages        = req.HasInlineCount ? req.InlineCount == InlineCount.AllPages : qdef.CountAllPages,
                EnableAutofilters    = req.AutofiltersEnabled != FilterStatus.Default ? req.AutofiltersEnabled : qdef.EnableAutofilters,
                EnableLifespanFilter = req.LifespanFilterEnabled != FilterStatus.Default ? req.AutofiltersEnabled : qdef.EnableLifespanFilter,
                QueryExecutionMode   = req.QueryExecutionMode != QueryExecutionMode.Default ? req.QueryExecutionMode : qdef.QueryExecutionMode,
            };

            var snQuery = SnExpression.BuildQuery(req.Filter, typeof(Content), null, cdef);

            if (cdef.EnableAutofilters != FilterStatus.Default)
            {
                snQuery.EnableAutofilters = cdef.EnableAutofilters;
            }
            if (cdef.EnableLifespanFilter != FilterStatus.Default)
            {
                snQuery.EnableLifespanFilter = cdef.EnableLifespanFilter;
            }
            if (cdef.QueryExecutionMode != QueryExecutionMode.Default)
            {
                snQuery.QueryExecutionMode = cdef.QueryExecutionMode;
            }

            var result = snQuery.Execute(new SnQueryContext(null, User.Current.Id));

            // for optimization purposes this combined condition is examined separately
            if (req.InlineCount == InlineCount.AllPages && req.CountOnly)
            {
                count = result.TotalCount;
                return(null);
            }

            var ids = result.Hits.ToArray();

            count = req.InlineCount == InlineCount.AllPages ? result.TotalCount : ids.Length;
            if (req.CountOnly)
            {
                return(null);
            }

            var contents   = new List <Dictionary <string, object> >();
            var projector  = Projector.Create(req, true);
            var missingIds = new List <int>();

            foreach (var id in ids)
            {
                var content = Content.Load(id);
                if (content == null)
                {
                    // collect missing ids for logging purposes
                    missingIds.Add(id);
                    continue;
                }

                var fields = CreateFieldDictionary(content, projector);
                contents.Add(fields);
            }

            if (missingIds.Count > 0)
            {
                // subtract missing count from result count
                count = Math.Max(0, count - missingIds.Count);

                // index anomaly: there are ids in the index that could not be loaded from the database
                SnLog.WriteWarning("Missing ids found in the index that could not be loaded from the database. See id list below.",
                                   EventId.Indexing,
                                   properties: new Dictionary <string, object>
                {
                    { "MissingIds", string.Join(", ", missingIds.OrderBy(id => id)) }
                });
            }

            return(contents);
        }
Beispiel #3
0
 private Dictionary <string, object> CreateFieldDictionary(Content content, Projector projector)
 {
     return(projector.Project(content));
 }