SqlServerTextContentQuerier.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Providers » SqlServer » 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 » Providers » SqlServer » SqlServerTextContentQuerier.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.Data;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Data.Extensions;

using Everest.Library;
using Everest.Library.Data;
using Everest.Library.Data.Entity;
using Everest.Library.ExtensionMethod;
using Everest.CmsServices.Models;
using Everest.CmsServices.Services;
using Everest.CmsServices.DataRule;
using Everest.Library.Providers.Logging;
using Everest.Library.Providers.Caching;
namespace Everest.CmsServices.Providers.SqlServer{
    public class SqlServerTextContentQuerier : ITextContentQuerier
    {
        public SqlServerTextContentQuerier()
        {
            SetQueryType(QueryType.Published);
        }
        #region QueryContent
        /// <summary>
        /// Queries the content.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="queryStatement"></param>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public IDictionary<string, object> QueryContent(IEverestCmsDataContext dataContext, Cms_Schema schema,
            string queryStatement, string orderBy, IDictionary<string, object> queryString, TimeSpan? cacheTime)
        {
            if (StringExtensions.IsNullOrEmptyTrim(orderBy))
            {
                orderBy = "ContentId DESC";
            }
            string cacheKey = string.Empty;
            IDictionary<string, object> data = null;
            if (cacheTime.HasValue)
            {
                cacheKey = string.Format("SqlServerTextContentQueries.QueryContent_SchemaUUID:{0}_QueryStatement:{1}_OrderBy:{2}_QueryString:{3}_CacheTime:{4}",
                    schema.UUID, queryStatement == null ? "" : queryStatement, orderBy, queryString == null ? "" : queryString.ToKeyValueString(), cacheTime.Value.ToString());
                data = CacheManager.Get(schema.UUID.ToString(), cacheKey) as IDictionary<string, object>;
                if (data != null)
                {
                    return data;
                }
            }
            var schemaApplcation = CachedData.GetApplicationBySchema(schema.UUID);
            DbCommand dbCommand = dataContext.ObjectContext.CreateStoreCommand("*");
            StringBuilder stringBuilder = new StringBuilder("1 = 1");
            ContentProviderHelper.CombineUserCondition(queryStatement, queryString, dbCommand, stringBuilder);

            if (QueriedContentStatus.HasValue)
            {
                stringBuilder.AppendFormat(" AND ContentStatus = @ContentStatus");
                dbCommand.CreateParameter("@ContentStatus", DbType.Int32, (int)QueriedContentStatus.Value);
            }

            dbCommand.CommandText = BuildQueryContentSQL(ContentProviderHelper.GetTableName(schemaApplcation.ApplicationName,
                schema.SchemaName), stringBuilder, orderBy);

            SqlServerContentProvider.Log("SqlServerTextContentQueries.QueryContent", dbCommand);
            using (dbCommand.Connection.CreateConnectionScope())
            {
                IDataReader dataReader = dbCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    data = DataReaderToDictionary(dataReader, null);
                }
            }

            if (cacheTime.HasValue)
            {
                CacheManager.Add(schema.UUID.ToString(), cacheKey, data, CacheItemPriority.None, null, new SlidingTime(cacheTime.Value));
            }

            return data;
        }

        protected virtual string BuildQueryContentSQL(string tableName, StringBuilder queryExpression, string orderBy)
        {
            return string.Format(@"
SELECT * 
   FROM (SELECT A.UUID,A.ContentId, A.Title,A.UserKey,A.ApplicationId,A.FolderUUID,A.SchemaUUID,A.UserName,A.BaseUUID,A.OriginalUUID,A.ModifiedDate,A.PostDate,A.ContentStatus,B.*
            FROM Cms_Content A,
                 [{0}] B
          WHERE A.UUID = B.ContentUUID 
         ) C
WHERE {1} ORDER BY {2}", tableName, queryExpression.ToString(), orderBy);
        }
        #endregion

        /// <summary>
        /// Queries the content.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.The statement like: app_News:id={id} and name like '%name%'</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="folders">The folders.</param>
        /// <param name="parentUUID">The parent UUID.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="referencingUUID">The referencing UUID.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="cacheTime">The cache time.</param>
        /// <returns></returns>
        protected virtual IEnumerable<IDictionary<string, object>> QueryContents(IEverestCmsDataContext dataContext, string queryStatement, string orderBy,
            IDictionary<string, object> queryString, Cms_Schema schema, Cms_Folder folder, IEnumerable<Cms_Folder> folders, Guid? parentUUID, IEnumerable<Guid> categories,
            Guid? referencingUUID, int startIndex, int limit, TimeSpan? cacheTime)
        {
            if (startIndex < 1)
            {
                startIndex = 1;
            }
            if (limit == int.MaxValue)
            {
                limit = limit - 1;
            }
            var schemaApplication = CachedData.GetApplicationBySchema(schema.UUID);
            if (StringExtensions.IsNullOrEmptyTrim(orderBy))
            {
                orderBy = "ContentId DESC";
            }

            string cacheKey = string.Empty;
            List<IDictionary<string, object>> data = null;

            if (cacheTime.HasValue)
            {
                var categoriesCacheKey = "";
                if (categories != null && categories.Count() > 0)
                {
                    categoriesCacheKey = string.Join(",", categories.Select(c => c.ToString()).ToArray());
                }
                cacheKey = string.Format(@"SqlServerTextContentQueries.QueryContents_queryStatement:{0}_orderBy:{1}_
                    queryString:{2}_schema:{3}_folder:{4}_folders:{5}_parentUUID:{6}_referencedUUID:{7}_referencingUUID:{8}_startIndex:{9}_
                    limit:{10}_cacheTime:{11}",
                    queryStatement == null ? "" : queryStatement, orderBy, queryString == null ? "" : queryString.ToKeyValueString(),
                    schema.UUID, folder == null ? "" : folder.UUID.ToString(), folders == null ? "" : string.Join(",", folders.Select(f => folder.UUID.ToString()).ToArray()),
                parentUUID == null ? "" : parentUUID.Value.ToString(), categoriesCacheKey,
                referencingUUID == null ? "" : referencingUUID.Value.ToString(), startIndex, limit, cacheTime.Value.ToString());

                data = CacheManager.Get(schema.UUID.ToString(), cacheKey) as List<IDictionary<string, object>>;
                if (data != null)
                {
                    return data;
                }
            }


            DbCommand dbCommand = dataContext.ObjectContext.CreateStoreCommand("a", CommandType.Text);
            var queryExpression = ContentProviderHelper.ContentQueryCondition(queryStatement, queryString, folders, parentUUID, dbCommand);

            StringBuilder selectColumns = new StringBuilder("B.ContentUUID");
            var columns = CachedData.GetColumnsBySchema(schema.UUID);
            foreach (var column in columns)
            {
                selectColumns.AppendFormat(",B.[{0}]", column.ColumnName);
            }
            string referencingTable = "";
            if (categories != null && categories.Count() > 0)
            {
                referencingTable = ",Cms_ContentReferencing Ref";
                queryExpression.Append(" AND Ref.ContentUUID=CmsContent.UUID AND ( 1<>1  ");
                int i = 0;
                foreach (var c in categories)
                {
                    var paramName = "@ReferencedUUID" + i;
                    queryExpression.Append(" OR Ref.ReferencedContentOriginalUUID=" + paramName);
                    dbCommand.CreateParameter(paramName, DbType.Guid, c);
                    i++;
                }
                queryExpression.Append(")");
                if (folders != null)
                {
                    queryExpression.AppendFormat(" AND ( 1 <> 1 ");
                    foreach (var f in folders)
                    {
                        queryExpression.AppendFormat(" OR CmsContent.FolderUUID = '{0}'", f.UUID);
                    }
                    queryExpression.AppendFormat(")");
                }
            }

            if (referencingUUID != null)
            {
                referencingTable = ",Cms_ContentReferencing Ref";
                queryExpression.Append(" AND Ref.ReferencedContentOriginalUUID=CmsContent.OriginalUUID AND Ref.ContentUUID=@ReferencingContentId");
                dbCommand.CreateParameter("@ReferencingContentId", DbType.Guid, referencingUUID.Value);
                if (folders != null)
                {
                    queryExpression.AppendFormat(" AND ( 1 <> 1 ");
                    foreach (var f in folders)
                    {
                        queryExpression.AppendFormat(" OR CmsContent.FolderUUID = '{0}'", f.UUID);
                    }
                    queryExpression.AppendFormat(")");
                }
            }

            if (QueriedContentStatus.HasValue)
            {
                queryExpression.AppendFormat(" AND CmsContent.ContentStatus = @ContentStatus");
                dbCommand.CreateParameter("@ContentStatus", DbType.Int32, (int)QueriedContentStatus.Value);
            }

            string includeFolder = "Cms_Content";
            if (folder != null)
            {
                dbCommand.CreateParameter("FolderUUID", DbType.Guid, folder.UUID);
                includeFolder = IncludeFolderSQL;
            }

            dbCommand.CommandText = BuildQueryContentsSQL(orderBy, ContentProviderHelper.GetTableName(schemaApplication.ApplicationName, schema.SchemaName), queryExpression, selectColumns, referencingTable, includeFolder);

            dbCommand.CreateParameter("SchemaUUID", DbType.Guid, schema.UUID);
            dbCommand.CreateParameter("startIndex", DbType.Int32, startIndex);
            dbCommand.CreateParameter("limit", DbType.Int32, limit);

            SqlServerContentProvider.Log("SqlServerTextContentQueries.QueryContents", dbCommand);
            using (dbCommand.Connection.CreateConnectionScope())
            {
                IDataReader dataReader = dbCommand.ExecuteReader();
                data = new List<IDictionary<string, object>>();
                while (dataReader.Read())
                {
                    IDictionary<string, object> dic = DataReaderToDictionary(dataReader, folder);
                    data.Add(dic);
                }
            }

            if (cacheTime.HasValue)
            {
                CacheManager.Add(schema.UUID.ToString(), cacheKey, data, CacheItemPriority.None, null, new SlidingTime(cacheTime.Value));
            }
            return data;
        }

        protected virtual string IncludeFolderSQL
        {
            get
            {
                return @"(SELECT Cms_Content.[ContentId]
                                              ,Cms_Content.[UUID]
                                              ,Cms_Content.[ApplicationId]
                                              ,Cms_Content.[UserName]
                                              ,Cms_Content.[Title]
                                              ,Cms_Content.[ModifiedDate]
                                              ,Cms_Content.[OriginalUUID]
                                              ,Cms_Content.[PostDate]
                                              ,Cms_Content.[BaseUUID]
                                              ,Cms_Content.[ParentUUID]
                                              ,Cms_Content.[SchemaUUID]
                                              ,Cms_Content.[FolderUUID]
                                              ,Cms_Content.[ContentStatus]
                                              ,Cms_Content.[UserKey]
                                              ,Cms_Content.[ApplicationLevel]
                                              ,Cms_Content.[FolderLevel] FROM Cms_Content LEFT JOIN Cms_ContentInFolder 
                  ON Cms_ContentInFolder.ContentUUID = Cms_Content.UUID 
                  WHERE (Cms_Content.FolderUUID = @FolderUUID OR Cms_ContentInFolder.FolderUUID = @FolderUUID))";
            }
        }


        protected virtual string BuildQueryContentsSQL(string orderBy, string tableName, StringBuilder queryExpression, StringBuilder selectColumns, string referencingTable, string includeFolder)
        {
            return string.Format(@"
SELECT *,(SELECT ApplicationName FROM aspnet_Applications WHERE ApplicationId=D.ApplicationId) AS [Application]
            FROM (SELECT ROW_NUMBER() OVER(ORDER BY {2}) AS RowIndex,A.ContentId,A.UUID,A.ParentUUID,A.Title,A.UserKey,A.ApplicationId,A.FolderUUID,
                         A.SchemaUUID,A.UserName,A.BaseUUID,A.ModifiedDate,A.PostDate,A.ContentStatus,A.OriginalUUID,{3}
                    FROM
                        (SELECT MAX(CmsContent.FolderLevel) AS MaxFolderLevel,CmsContent.OriginalUUID AS MaxOriginalUUID 
                            FROM {5} CmsContent,
                                 [{0}] {4}
                          WHERE CmsContent.UUID = [{0}].ContentUUID AND {1}
                          Group By OriginalUUID) C, 
                        {5} A,
                        [{0}] B                         
          WHERE A.UUID = B.ContentUUID AND A.FolderLevel = C.MaxFolderLevel AND A.OriginalUUID=C.MaxOriginalUUID)D         
WHERE (RowIndex >= @startIndex) AND (RowIndex < @startIndex + @limit)"
                , tableName, queryExpression.ToString(), orderBy
                , selectColumns.ToString(), referencingTable, includeFolder);
        }

        private static IDictionary<string, object> DataReaderToDictionary(IDataReader dataReader, Cms_Folder folder)
        {
            IDictionary<string, object> dic = ContentProviderHelper.ToDictionary(dataReader);
            if (folder != null && dic["FolderUUID"] != DBNull.Value)
            {
                dic["IsLocalized"] = (Guid)dic["FolderUUID"] == folder.UUID;
            }
            if (dic.ContainsKey("ContentStatus"))
            {
                dic["ContentStatusName"] = ((ContentStatus)dic["ContentStatus"]).ToString();
            }
            return dic;
        }

        /// <summary>
        /// Counts the contents.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.The statement like : app_News:id={id} and name like '%name%'</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="folders">The folders.</param>
        /// <param name="parentUUID">The parent UUID.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="referencingUUID">The referencing UUID.</param>
        /// <param name="cacheTime">The cache time.</param>
        /// <returns></returns>
        protected int CountContents(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> queryString,
             Cms_Schema schema, Cms_Folder folder, IEnumerable<Cms_Folder> folders, Guid? parentUUID, IEnumerable<Guid> categories,
            Guid? referencingUUID, TimeSpan? cacheTime)
        {

            string cacheKey = string.Empty;
            int? data = null;

            if (cacheTime.HasValue)
            {
                var categoriesCacheKey = "";
                if (categories != null && categories.Count() > 0)
                {
                    categoriesCacheKey = string.Join(",", categories.Select(c => c.ToString()).ToArray());
                }
                cacheKey = string.Format(@"SqlServerTextContentQueries.CountContents_queryStatement:{0}_
                    queryString:{1}_schema:{2}_folder:{3}_folders:{4}_parentUUID:{5}_referencedUUID:{6}_referencingUUID:{7}_cacheTime:{8}",
                    queryStatement == null ? "" : queryStatement, queryString == null ? "" : queryString.ToKeyValueString(),
                    schema.UUID, folder == null ? "" : folder.UUID.ToString(), folders == null ? "" : string.Join(",", folders.Select(f => folder.UUID.ToString()).ToArray()),
                parentUUID == null ? "" : parentUUID.Value.ToString(), categoriesCacheKey,
                referencingUUID == null ? "" : referencingUUID.Value.ToString(), cacheTime.Value.ToString());

                data = CacheManager.Get(schema.UUID.ToString(), cacheKey) as int?;
                if (data != null)
                {
                    return data.Value;
                }
            }

            var schemaApplication = CachedData.GetApplicationBySchema(schema.UUID);
            DbCommand dbCommand = dataContext.ObjectContext.CreateStoreCommand("A");

            var queryExpression = ContentProviderHelper.ContentQueryCondition(queryStatement, queryString, folders, parentUUID, dbCommand);

            string referencingTable = "";
            if (categories != null && categories.Count() > 0)
            {
                referencingTable = ",Cms_ContentReferencing Ref";
                queryExpression.Append(" AND Ref.ContentUUID=CmsContent.UUID AND (1<>1 ");
                int i = 0;
                foreach (var c in categories)
                {
                    var paramName = "@ReferencedUUID" + i;
                    queryExpression.Append(" OR Ref.ReferencedContentOriginalUUID=" + paramName);
                    dbCommand.CreateParameter(paramName, DbType.Guid, c);
                    i++;
                }
                queryExpression.Append(")");
                if (folders != null)
                {
                    queryExpression.AppendFormat(" AND ( 1 <> 1 ");
                    foreach (var f in folders)
                    {
                        queryExpression.AppendFormat(" OR CmsContent.FolderUUID = '{0}'", f.UUID);
                    }
                    queryExpression.AppendFormat(")");
                }
            }
            if (referencingUUID != null)
            {
                referencingTable = ",Cms_ContentReferencing Ref";
                queryExpression.Append(" AND Ref.ReferencedContentOriginalUUID=CmsContent.OriginalUUID AND Ref.ContentUUID=@ReferencingContentId");
                dbCommand.CreateParameter("@ReferencingContentId", DbType.Guid, referencingUUID.Value);
                if (folders != null)
                {
                    queryExpression.AppendFormat(" AND ( 1 <> 1 ");
                    foreach (var f in folders)
                    {
                        queryExpression.AppendFormat(" OR CmsContent.FolderUUID = '{0}'", f.UUID);
                    }
                    queryExpression.AppendFormat(")");
                }
            }
            if (QueriedContentStatus.HasValue)
            {
                queryExpression.AppendFormat(" AND CmsContent.ContentStatus = @ContentStatus");
                dbCommand.CreateParameter("@ContentStatus", DbType.Int32, (int)QueriedContentStatus.Value);
            }
            string includeFolder = "Cms_Content";
            if (folder != null)
            {
                dbCommand.CreateParameter("FolderUUID", DbType.Guid, folder.UUID);
                includeFolder = IncludeFolderSQL;
            }

            dbCommand.CommandText = BuildCountContentSQL(ContentProviderHelper.GetTableName(schemaApplication.ApplicationName, schema.SchemaName), queryExpression, referencingTable, includeFolder);
            dbCommand.CreateParameter("SchemaUUID", DbType.Guid, schema.UUID);
            SqlServerContentProvider.Log("SqlServerTextContentQueries.CountContents", dbCommand);

            using (dbCommand.Connection.CreateConnectionScope())
            {
                data = int.Parse(dbCommand.ExecuteScalar().ToString());
            }
            if (cacheTime.HasValue)
            {
                CacheManager.Add(schema.UUID.ToString(), cacheKey, data, CacheItemPriority.None, null, new SlidingTime(cacheTime.Value));
            }
            return data.Value;
        }

        protected virtual string BuildCountContentSQL(string tableName, StringBuilder queryExpression, string referencingTable, string includeFolder)
        {
            return string.Format(@"
SELECT COUNT(*)
    FROM (SELECT MAX(CmsContent.FolderLevel) AS MaxFolderLevel,CmsContent.OriginalUUID AS MaxOriginalUUID 
            FROM {3} CmsContent,
                    [{0}] {2}  
          WHERE CmsContent.UUID = [{0}].ContentUUID AND {1} Group By OriginalUUID) C
"
                , tableName, queryExpression.ToString()
                , referencingTable, includeFolder);
        }

        #region QueryContents
        public IEnumerable<IDictionary<string, object>> QueryContents(IEverestCmsDataContext dataContext, string queryStatement,
          string orderBy, IDictionary<string, object> queryString, Cms_Folder folder, IEnumerable<Cms_Folder> folders, int startIndex, int limit, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.QueryContents(dataContext, queryStatement, orderBy, queryString, schema, folder, folders,
                null, null, null, startIndex, limit, cacheTime);
        }

        public int CountContents(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> queryString,
            Cms_Folder folder, IEnumerable<Cms_Folder> folders, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.CountContents(dataContext, queryStatement, queryString, schema, folder, folders, null, null, null, cacheTime);
        }
        #endregion

        #region QuerySubContents
        public IEnumerable<IDictionary<string, object>> QuerySubContents(IEverestCmsDataContext dataContext, string queryStatement, string orderBy,
            IDictionary<string, object> queryString, Cms_Schema schema, Guid? parentUUID, int startIndex, int limit, TimeSpan? cacheTime)
        {
            return this.QueryContents(dataContext, queryStatement, orderBy, queryString, schema, null, null, parentUUID
                , null, null, startIndex, limit, cacheTime);
        }

        public int CountSubContents(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> queryString,
            Cms_Schema schema, Guid? parentUUID, TimeSpan? cacheTime)
        {
            return this.CountContents(dataContext, queryStatement, queryString, schema, null, null, parentUUID, null, null, cacheTime);
        }
        #endregion

        #region QueryReferToContents
        /// <summary>
        /// Queries the refer to contents.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="cacheTime">The cache time.</param>
        /// <returns></returns>
        public IEnumerable<IDictionary<string, object>> QueryContentsByCategory(IEverestCmsDataContext dataContext, string queryStatement, string orderBy,
            IDictionary<string, object> queryString, Cms_Schema schema, IEnumerable<Guid> categories, int startIndex, int limit, TimeSpan? cacheTime)
        {
            return this.QueryContents(dataContext, queryStatement, orderBy, queryString, schema, null, null, null,
                categories, null, startIndex, limit, cacheTime);
        }

        /// <summary>
        /// Counts the refer to counts.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="cacheTime">The cache time.</param>
        /// <returns></returns>
        public int CountContentsByCategory(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> queryString,
            Cms_Schema schema, IEnumerable<Guid> categories, TimeSpan? cacheTime)
        {
            return this.CountContents(dataContext, queryStatement, queryString, schema, null, null, null, categories, null, cacheTime);

        }
        /// <summary>
        /// Queries the ReferTo contents.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="parameterValues">The parameter values.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="folders">The folders.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="cacheTime">The cache time.</param>
        /// <returns></returns>
        public IEnumerable<IDictionary<string, object>> QueryContentsByCategory(IEverestCmsDataContext dataContext, string queryStatement, string orderBy,
            IDictionary<string, object> parameterValues, Cms_Folder folder, IEnumerable<Cms_Folder> folders, IEnumerable<Guid> categories,
            int startIndex, int limit, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.QueryContents(dataContext, queryStatement, orderBy, parameterValues, schema, folder, folders, null, categories,
                null, startIndex, limit, cacheTime);
        }

        /// <summary>
        /// Counts the refer to counts.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="parameterValues">The parameter values.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="folders">The folders.</param>
        /// <param name="referencedContentUUID">The referenced content UUID.</param>
        /// <returns></returns>
        public int CountContentsByCategory(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> parameterValues
            , Cms_Folder folder, IEnumerable<Cms_Folder> folders, IEnumerable<Guid> categories, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.CountContents(dataContext, queryStatement, parameterValues, schema, folder, folders, null, categories,
                null, cacheTime);
        }

        #endregion

        #region QueryReferredByContents
        /// <summary>
        /// Queries the referenced contents.Such like query the categories.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="orderBy">The order by.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="referencingContentId">The referencing content id.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="limit">The limit.</param>
        /// <returns></returns>
        public IEnumerable<IDictionary<string, object>> QueryCategories(IEverestCmsDataContext dataContext, string queryStatement, string orderBy,
            IDictionary<string, object> queryString, Cms_Schema schema, Guid referencingContentUUID, int startIndex, int limit, TimeSpan? cacheTime)
        {
            return this.QueryContents(dataContext, queryStatement, orderBy, queryString, schema, null, null,
                null, null, referencingContentUUID, startIndex, limit, cacheTime);
        }

        /// <summary>
        /// Counts the referencing counts.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <param name="queryStatement">The query statement.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="schema">The schema.</param>
        /// <param name="referencingContentId"></param>
        /// <returns></returns>
        public int CountCategories(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> queryString,
            Cms_Schema schema, Guid referencingContentUUID, TimeSpan? cacheTime)
        {
            return this.CountContents(dataContext, queryStatement, queryString, schema, null, null, null, null, referencingContentUUID, cacheTime);
        }

        public IEnumerable<IDictionary<string, object>> QueryCategories(IEverestCmsDataContext dataContext, string queryStatement,
            string orderBy, IDictionary<string, object> parameterValues, Cms_Folder folder, IEnumerable<Cms_Folder> folders,
            Guid referencingContentUUID, int startIndex, int limit, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.QueryContents(dataContext, queryStatement, orderBy, parameterValues, schema, folder,
                folders, null, null, referencingContentUUID, startIndex, limit, cacheTime);
        }

        public int CountCategories(IEverestCmsDataContext dataContext, string queryStatement, IDictionary<string, object> parameterValues,
            Cms_Folder folder, IEnumerable<Cms_Folder> folders, Guid referencingContentUUID, TimeSpan? cacheTime)
        {
            var schema = CachedData.GetSchemaByFolder(folder.UUID);
            return this.CountContents(dataContext, queryStatement, parameterValues, schema, folder, folders, null,
                null, referencingContentUUID, cacheTime);
        }
        #endregion

        #region ITextContentQuerier Members

        public ContentStatus? QueriedContentStatus
        {
            get;
            set;
        }


        public ITextContentQuerier SetQueryType(QueryType queryType)
        {
            switch (queryType)
            {
                case QueryType.All:
                    QueriedContentStatus = null;
                    break;
                case QueryType.Published:
                    QueriedContentStatus = ContentStatus.Published;
                    break;
                case QueryType.Unpublished:
                    QueriedContentStatus = ContentStatus.Draft;
                    break;
                default:
                    break;
            }
            return this;
        }

        #endregion
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.