public async Task <IResultList <IContentEntity> > QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, ODataUriParser odataQuery, bool latest = false)
        {
            try
            {
                IMongoCollection <MongoContentEntity> sourceCollection;

                if (latest)
                {
                    sourceCollection = LatestCollection;
                }
                else
                {
                    sourceCollection = Collection;
                }

                var propertyCalculator = FindExtensions.CreatePropertyCalculator(schema.SchemaDef);

                var filter = FindExtensions.BuildQuery(odataQuery, schema.Id, status, propertyCalculator);

                var contentCount = sourceCollection.Find(filter).CountAsync();
                var contentItems =
                    sourceCollection.Find(filter)
                    .ContentTake(odataQuery)
                    .ContentSkip(odataQuery)
                    .ContentSort(odataQuery, propertyCalculator)
                    .ToListAsync();

                await Task.WhenAll(contentItems, contentCount);

                foreach (var entity in contentItems.Result)
                {
                    entity.ParseData(schema.SchemaDef);
                }

                return(ResultList.Create <IContentEntity>(contentItems.Result, contentCount.Result));
            }
            catch (NotSupportedException)
            {
                throw new ValidationException("This odata operation is not supported.");
            }
            catch (NotImplementedException)
            {
                throw new ValidationException("This odata operation is not supported.");
            }
            catch (MongoQueryException ex)
            {
                if (ex.Message.Contains("17406"))
                {
                    throw new DomainException("Result set is too large to be retrieved. Use $top parameter to reduce the number of items.");
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
        private string F(string value)
        {
            var parser = edmModel.ParseQuery(value);

            var query =
                parser.BuildFilter <MongoContentEntity>(FindExtensions.CreatePropertyCalculator(schemaDef))
                .Filter.Render(serializer, registry).ToString();

            return(query);
        }
Esempio n. 3
0
        private string S(string value)
        {
            var parser = edmModel.ParseQuery(value);
            var cursor = A.Fake <IFindFluent <MongoContentEntity, MongoContentEntity> >();

            var i = string.Empty;

            A.CallTo(() => cursor.Sort(A <SortDefinition <MongoContentEntity> > .Ignored))
            .Invokes((SortDefinition <MongoContentEntity> sortDefinition) =>
            {
                i = sortDefinition.Render(serializer, registry).ToString();
            });

            cursor.ContentSort(parser, FindExtensions.CreatePropertyCalculator(schemaDef));

            return(i);
        }