CategoryByContentNSchemaQueryable.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » LINQ » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » LINQ » CategoryByContentNSchemaQueryable.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;

using Everest.Library.ExtensionMethod;
using Everest.CmsServices.MvcHelper;

namespace Everest.CmsServices.LINQ{
    public class CategoryByContentNSchemaQueryable: ContentQueryable<ContentContainer>
    {
        public CategoryByContentNSchemaQueryable(Guid contentUUID, string schemaName)
            : base()
        {
            this.ContentUUID = contentUUID;
            this.SchemaName = schemaName;
        }
        public CategoryByContentNSchemaQueryable(int contentId, string schemaName)
            : base()
        {
            this.ContentId = contentId;
            this.SchemaName = schemaName;
        }
        internal CategoryByContentNSchemaQueryable(Guid contentUUID, int contentId, string schemaName, Expression expression)
            : base(expression)
        {
            this.ContentUUID = contentUUID;
            this.ContentId = contentId;

            this.SchemaName = schemaName;
        }
        public int ContentId { get; private set; }
        public Guid ContentUUID { get; private set; }
        public string SchemaName { get; private set; }

        public override IQueryProvider Provider
        {
            get { return new CategoryByContentNSchemaQueryProvider(this); }
        }
    }

    internal class CategoryByContentNSchemaQueryProvider : ContentQueryProvider
    {
        private CategoryByContentNSchemaQueryable queryable;
        public CategoryByContentNSchemaQueryProvider(CategoryByContentNSchemaQueryable queryable)
        {
            this.queryable = queryable;
        }
        public override IQueryable<TElement> CreateQuery<TElement>(System.Linq.Expressions.Expression expression)
        {
            return (IQueryable<TElement>)new CategoryByContentNSchemaQueryable(queryable.ContentUUID, queryable.ContentId, queryable.SchemaName, expression);
        }

        public override IQueryable CreateQuery(System.Linq.Expressions.Expression expression)
        {
            Type elementType = TypeSystem.GetElementType(expression.Type);
            try
            {
                return (IQueryable)Activator.CreateInstance(typeof(CategoryByContentNSchemaQueryable), new object[] { this, queryable.ContentUUID, queryable.ContentId, queryable.SchemaName, expression });
            }
            catch (TargetInvocationException tie)
            {
                throw tie.InnerException;
            }
        }

        private object countValue;
        protected override object Count(StatementExpression exp)
        {
            if (countValue == null)
            {
                if (queryable.ContentId != 0)
                {
                    countValue = ContentService.GetCategoryCountByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.Parameters.ToNameValueCollection(), null);
                }
                else
                {
                    countValue = ContentService.GetCategoryCountByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.Parameters.ToNameValueCollection(), null);
                }
            }
            return countValue;
        }

        private object firstValue;
        protected override object First(StatementExpression exp)
        {
            if (firstValue == null)
            {
                if (queryable.ContentId != 0)
                {
                    firstValue = new ContentContainer(ContentService.GetCategoriesByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.OrderBy,
                        exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, 1, null).First());
                }
                else
                {
                    firstValue = new ContentContainer(ContentService.GetCategoriesByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.OrderBy,
                       exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, 1, null).First());
                }
            }
            return firstValue;
        }
        private object firstOrDefaultValue;
        protected override object FirstOrDefault(StatementExpression exp)
        {
            if (firstOrDefaultValue == null)
            {
                IDictionary<string, object> retValue = null;
                if (queryable.ContentId != 0)
                {
                    retValue = ContentService.GetCategoriesByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.OrderBy, exp.Parameters.ToNameValueCollection(),
                        exp.SkipCount + 1, 1, null).FirstOrDefault();
                }
                else
                {
                    retValue = new ContentContainer(ContentService.GetCategoriesByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.OrderBy,
                       exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, 1, null).First());
                }

                if (retValue != null)
                {
                    firstOrDefaultValue = new ContentContainer(retValue);
                }
                else
                {
                    firstOrDefaultValue = retValue;
                }
            }
            return firstOrDefaultValue;
        }

        private object lastValue;
        protected override object Last(StatementExpression exp)
        {
            if (lastValue == null)
            {
                var startIndex = exp.SkipCount;
                if (exp.TakeCount == 0)
                {
                    startIndex = startIndex + (int)Count(exp);
                }
                else
                {
                    startIndex = startIndex + exp.TakeCount;
                }
                if (queryable.ContentId != 0)
                {
                    lastValue = new ContentContainer(ContentService.GetCategoriesByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.OrderBy,
                        exp.Parameters.ToNameValueCollection(), startIndex, 1, null).First());
                }
                else
                {
                    lastValue = new ContentContainer(ContentService.GetCategoriesByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.OrderBy,
                       exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, 1, null).First());
                }

            }
            return lastValue;
        }

        private object lastOrDefaultValue;
        protected override object LastOrDefault(StatementExpression exp)
        {
            if (lastValue == null)
            {
                var startIndex = exp.SkipCount;
                if (exp.TakeCount == 0)
                {
                    startIndex = startIndex + (int)Count(exp);
                }
                else
                {
                    startIndex = startIndex + exp.TakeCount;
                }
                IDictionary<string, object> retValue = null;
                if (queryable.ContentId != 0)
                {
                    retValue = ContentService.GetCategoriesByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.OrderBy, exp.Parameters.ToNameValueCollection(), startIndex, 1, null).FirstOrDefault();
                }
                else
                {
                    retValue = ContentService.GetCategoriesByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.OrderBy, exp.Parameters.ToNameValueCollection(), startIndex, 1, null).FirstOrDefault();
                }
                if (retValue != null)
                {
                    lastOrDefaultValue = new ContentContainer(retValue);
                }
                else
                {
                    lastOrDefaultValue = retValue;
                }
            }
            return lastValue;
        }
        private object value;
        protected override object ExecuteCore(StatementExpression exp)
        {
            if (value == null)
            {
                var pageSize = exp.TakeCount;
                if (pageSize == 0)
                {
                    pageSize = int.MaxValue;
                }
                IList<ContentContainer> list = new List<ContentContainer>();
                IEnumerable<IDictionary<string, object>> contents = null;

                if (queryable.ContentId != 0)
                {
                    contents = ContentService.GetCategoriesByContentAndSchema(queryable.ContentId, queryable.SchemaName, exp.QueryStatement, exp.OrderBy, exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, pageSize, null);
                }
                else
                {
                    contents = ContentService.GetCategoriesByContentAndSchema(queryable.ContentUUID, queryable.SchemaName, exp.QueryStatement, exp.OrderBy, exp.Parameters.ToNameValueCollection(), exp.SkipCount + 1, pageSize, null);
                }
                foreach (var item in contents)
                {
                    list.Add(new ContentContainer(item));
                }
                value = list;
            }
            return value;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.