protected override global::MongoDB.Driver.MongoCursor<global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var categoriesQuery = (CategoriesQuery)ContentQuery;
            MongoDBQueryTranslator translator = new MongoDBQueryTranslator();

            if (categoriesQuery.CategoryFolder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", categoriesQuery.CategoryFolder.FullName));
            }

            var subQuery = translator.Translate(categoriesQuery.InnerQuery);
            var contents = ((IEnumerable<TextContent>)subQuery.Execute());
            if (contents.Count() > 0)
            {
                var categoryQueryComplete = MongoDBHelper.EQIgnoreCase("CategoryFolder", categoriesQuery.CategoryFolder.FullName);

                var inCategories = QueryBuilder.Query.In("ContentUUID", contents.Select(it => BsonHelper.Create(it.UUID)).ToArray());

                var relation = categoriesQuery.Repository.GetCategoriesCollection().Find(QueryBuilder.Query.And(categoryQueryComplete, inCategories));

                visitor.SetQuery(QueryBuilder.Query.In("UUID", relation.Select(it => it["CategoryUUID"]).ToArray()));

                return categoriesQuery.CategoryFolder.GetSchema().GetCollection().Find(visitor.QueryComplete);
            }
            else
            {
                return null;
            }
        }
Exemple #2
0
        private QueryComplete VisitInner(IExpression expression)
        {
            MongoDBVisitor visitor = new MongoDBVisitor();

            visitor.Visite(expression);
            //combine the order expressions.
            this.OrderFields.AddRange(visitor.OrderFields);

            this.CategoryQueries = this.CategoryQueries.Concat(visitor.CategoryQueries);
            return(visitor.QueryComplete);
        }
        protected override global::MongoDB.Driver.MongoCursor<global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var textContentQuery = (TextContentQuery)ContentQuery;

            if (textContentQuery.Folder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", textContentQuery.Folder.FullName));
            }

            if (visitor.CategoryQueries != null && visitor.CategoryQueries.Count() > 0)
            {
                MongoDBQueryTranslator translator = new MongoDBQueryTranslator();

                IEnumerable<BsonDocument> categoryContents = null;

                foreach (var categoryQuery in visitor.CategoryQueries)
                {
                    var categories = ((IEnumerable<TextContent>)translator.Translate(categoryQuery).Execute()).ToArray();

                    if (categories.Count() > 0)
                    {
                        var categoryQueryComplete = MongoDBHelper.EQIgnoreCase("CategoryFolder", ((TextContentQueryBase)categoryQuery).Folder.FullName);
                        var inCategories = QueryBuilder.Query.In("CategoryUUID", categories.Select(it => BsonHelper.Create(it.UUID)).ToArray());
                        var relation = textContentQuery.Repository.GetCategoriesCollection().Find(QueryBuilder.Query.And(categoryQueryComplete, inCategories));

                        if (categoryContents == null)
                        {
                            categoryContents = relation;
                        }
                        else
                        {
                            //intersection of sets
                            categoryContents = categoryContents
                                .Where(it => relation.Any(r => r["ContentUUID"].AsString == it["ContentUUID"].AsString));
                        }
                    }

                }
                if (categoryContents != null && categoryContents.Count() != 0)
                {
                    visitor.SetQuery(QueryBuilder.Query.In("UUID", categoryContents.Select(it => it["ContentUUID"]).ToArray()));
                }
                else
                {
                    visitor.SetQuery(QueryBuilder.Query.Where(new BsonJavaScript("false")));
                }
            }

            return textContentQuery.Schema.GetCollection().Find(visitor.QueryComplete);
        }
Exemple #4
0
        protected override global::MongoDB.Driver.MongoCursor<global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var childrenQuery = (ChildrenQuery)this.ContentQuery;

            MongoDBQueryTranslator translator = new MongoDBQueryTranslator();

            var parents = ((IEnumerable<TextContent>)(translator.Translate(childrenQuery.ParentQuery)).Execute());

            if (childrenQuery.EmbeddedFolder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", childrenQuery.EmbeddedFolder.FullName));
            }
            if (parents.Count() > 0)
            {
                visitor.SetQuery(QueryBuilder.Query.In("ParentUUID", parents.Select(it => BsonHelper.Create(it.UUID)).ToArray()));

                return childrenQuery.ChildSchema.GetCollection().Find(visitor.MongoQuery);
            }

            return null;
        }
Exemple #5
0
        private IMongoQuery VisitInner(IExpression expression)
        {
            MongoDBVisitor visitor = new MongoDBVisitor();
            visitor.Visite(expression);
            //combine the order expressions.
            this.OrderFields.AddRange(visitor.OrderFields);

            this.CategoryQueries = this.CategoryQueries.Concat(visitor.CategoryQueries);
            return visitor.MongoQuery;
        }
Exemple #6
0
        public virtual object Execute()
        {
            var visitor = new MongoDBVisitor();

            visitor.Visite(ContentQuery.Expression);
            var mongoCursor = Query(visitor);

            if (mongoCursor == null)
            {
                return(DefaultValueExecute(visitor.CallType));
            }
            if (visitor.Skip != 0)
            {
                mongoCursor.Skip = visitor.Skip;
            }

            SortByBuilder sortBuilder = new SortByBuilder();

            foreach (var item in visitor.OrderFields)
            {
                if (item.Descending)
                {
                    sortBuilder.Descending(item.FieldName);
                }
                else
                {
                    sortBuilder.Ascending(item.FieldName);
                }
            }
            mongoCursor = mongoCursor.SetSortOrder(sortBuilder);

            object result = null;

            switch (visitor.CallType)
            {
            case Kooboo.CMS.Content.Query.Expressions.CallType.Count:
                result = Convert.ToInt32(mongoCursor.Count());
                break;

            case Kooboo.CMS.Content.Query.Expressions.CallType.First:
                result = mongoCursor.First().ToContent();
                break;

            case Kooboo.CMS.Content.Query.Expressions.CallType.Last:
                result = mongoCursor.Last().ToContent();
                break;

            case Kooboo.CMS.Content.Query.Expressions.CallType.LastOrDefault:
                result = mongoCursor.Last().ToContent();
                break;

            case Kooboo.CMS.Content.Query.Expressions.CallType.FirstOrDefault:
                result = mongoCursor.FirstOrDefault().ToContent();
                break;

            case Kooboo.CMS.Content.Query.Expressions.CallType.Unspecified:
            default:
                if (visitor.Take != 0)
                {
                    result = mongoCursor.Take(visitor.Take).Select(it => it.ToContent());
                }
                else
                {
                    result = mongoCursor.Select(it => it.ToContent());
                }
                break;
            }

            if (mongoCursor.Database.Server.State != MongoServerState.Disconnected)
            {
                mongoCursor.Database.Server.Disconnect();
            }
            return(result);
        }
Exemple #7
0
 protected abstract MongoCursor <BsonDocument> Query(MongoDBVisitor visitor);
Exemple #8
0
        protected override global::MongoDB.Driver.MongoCursor <global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var childrenQuery = (ChildrenQuery)this.ContentQuery;

            MongoDBQueryTranslator translator = new MongoDBQueryTranslator();

            var parents = ((IEnumerable <TextContent>)(translator.Translate(childrenQuery.ParentQuery)).Execute());

            if (childrenQuery.EmbeddedFolder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", childrenQuery.EmbeddedFolder.FullName));
            }
            if (parents.Count() > 0)
            {
                visitor.SetQuery(QueryBuilder.Query.In("ParentUUID", parents.Select(it => BsonHelper.Create(it.UUID)).ToArray()));

                return(childrenQuery.ChildSchema.GetCollection().Find(visitor.MongoQuery));
            }

            return(null);
        }
Exemple #9
0
        public virtual object Execute()
        {
            var visitor = new MongoDBVisitor();
            visitor.Visite(ContentQuery.Expression);
            var mongoCursor = Query(visitor);
            if (mongoCursor == null)
            {
                return DefaultValueExecute(visitor.CallType);
            }
            if (visitor.Skip != 0)
            {
                mongoCursor.Skip = visitor.Skip;
            }

            SortByBuilder sortBuilder = new SortByBuilder();
            
            foreach (var item in visitor.OrderFields)
            {
                if (item.Descending)
                {
                    sortBuilder.Descending(item.FieldName);
                }
                else
                {
                    sortBuilder.Ascending(item.FieldName);
                }
            }
            mongoCursor = mongoCursor.SetSortOrder(sortBuilder);

            object result = null;
            switch (visitor.CallType)
            {
                case Kooboo.CMS.Content.Query.Expressions.CallType.Count:
                    result = Convert.ToInt32(mongoCursor.Count());
                    break;
                case Kooboo.CMS.Content.Query.Expressions.CallType.First:
                    result = mongoCursor.First().ToContent();
                    break;
                case Kooboo.CMS.Content.Query.Expressions.CallType.Last:
                    result = mongoCursor.Last().ToContent();
                    break;
                case Kooboo.CMS.Content.Query.Expressions.CallType.LastOrDefault:
                    result = mongoCursor.Last().ToContent();
                    break;
                case Kooboo.CMS.Content.Query.Expressions.CallType.FirstOrDefault:
                    result = mongoCursor.FirstOrDefault().ToContent();
                    break;
                case Kooboo.CMS.Content.Query.Expressions.CallType.Unspecified:
                default:
                    if (visitor.Take != 0)
                    {
                        result = mongoCursor.Take(visitor.Take).Select(it => it.ToContent());
                    }
                    else
                        result = mongoCursor.Select(it => it.ToContent());
                    break;
            }

            //if (mongoCursor.Database.Server.State != MongoServerState.Disconnected)
            //{
            //    mongoCursor.Database.Server.Disconnect();
            //}
            return result;
        }
Exemple #10
0
 protected abstract MongoCursor<BsonDocument> Query(MongoDBVisitor visitor);
        protected override global::MongoDB.Driver.MongoCursor <global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var textContentQuery = (TextContentQuery)ContentQuery;

            if (textContentQuery.Folder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", textContentQuery.Folder.FullName));
            }

            if (visitor.CategoryQueries != null && visitor.CategoryQueries.Count() > 0)
            {
                MongoDBQueryTranslator translator = new MongoDBQueryTranslator();

                IEnumerable <BsonDocument> categoryContents = null;

                foreach (var categoryQuery in visitor.CategoryQueries)
                {
                    var categories = ((IEnumerable <TextContent>)translator.Translate(categoryQuery).Execute()).ToArray();

                    if (categories.Count() > 0)
                    {
                        var categoryQueryComplete = MongoDBHelper.EQIgnoreCase("CategoryFolder", ((TextContentQueryBase)categoryQuery).Folder.FullName);
                        var inCategories          = QueryBuilder.Query.In("CategoryUUID", categories.Select(it => BsonHelper.Create(it.UUID)).ToArray());
                        var relation = textContentQuery.Repository.GetCategoriesCollection().Find(QueryBuilder.Query.And(categoryQueryComplete, inCategories));

                        if (categoryContents == null)
                        {
                            categoryContents = relation;
                        }
                        else
                        {
                            //intersection of sets
                            categoryContents = categoryContents
                                               .Where(it => relation.Any(r => r["ContentUUID"].AsString == it["ContentUUID"].AsString));
                        }
                    }
                }
                if (categoryContents != null && categoryContents.Count() != 0)
                {
                    visitor.SetQuery(QueryBuilder.Query.In("UUID", categoryContents.Select(it => it["ContentUUID"]).ToArray()));
                }
                else
                {
                    visitor.SetQuery(QueryBuilder.Query.Where(new BsonJavaScript("false")));
                }
            }

            return(textContentQuery.Schema.GetCollection().Find(visitor.MongoQuery));
        }
Exemple #12
0
        protected override global::MongoDB.Driver.MongoCursor <global::MongoDB.Bson.BsonDocument> Query(MongoDBVisitor visitor)
        {
            var categoriesQuery = (CategoriesQuery)ContentQuery;
            MongoDBQueryTranslator translator = new MongoDBQueryTranslator();


            if (categoriesQuery.CategoryFolder != null)
            {
                visitor.SetQuery(MongoDBHelper.EQIgnoreCase("FolderName", categoriesQuery.CategoryFolder.FullName));
            }

            var subQuery = translator.Translate(categoriesQuery.InnerQuery);
            var contents = ((IEnumerable <TextContent>)subQuery.Execute());

            if (contents.Count() > 0)
            {
                var categoryQueryComplete = MongoDBHelper.EQIgnoreCase("CategoryFolder", categoriesQuery.CategoryFolder.FullName);

                var inCategories = QueryBuilder.Query.In("ContentUUID", contents.Select(it => BsonHelper.Create(it.UUID)).ToArray());

                var relation = categoriesQuery.Repository.GetCategoriesCollection().Find(QueryBuilder.Query.And(categoryQueryComplete, inCategories));

                visitor.SetQuery(QueryBuilder.Query.In("UUID", relation.Select(it => it["CategoryUUID"]).ToArray()));


                return(categoriesQuery.CategoryFolder.GetSchema().GetCollection().Find(visitor.MongoQuery));
            }
            else
            {
                return(null);
            }
        }