当前位置: 首页>>代码示例>>C#>>正文


C# Query.AddSorting方法代码示例

本文整理汇总了C#中Query.AddSorting方法的典型用法代码示例。如果您正苦于以下问题:C# Query.AddSorting方法的具体用法?C# Query.AddSorting怎么用?C# Query.AddSorting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Query的用法示例。


在下文中一共展示了Query.AddSorting方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindComponentUrisBySchemas

        private string[] FindComponentUrisBySchemas(string[] schemaUris, int? limit, DateTime? sinceLastPublished)
        {
            TcmUri schemaTcmUri = new TcmUri(schemaUris.First());

            PublicationCriteria publicationCriteria = new PublicationCriteria(schemaTcmUri.PublicationId);

            Criteria[] schemaCriterias = schemaUris
                .Select(uri => new ItemSchemaCriteria(new TcmUri(uri).ItemId))
                .ToArray();

            Criteria basedOnSchema = CriteriaFactory.Or(schemaCriterias);
            Criteria basedOnSchemaAndInPublication = CriteriaFactory.And(publicationCriteria, basedOnSchema);

            if (sinceLastPublished.HasValue)
            {
                ItemLastPublishedDateCriteria dateLastPublished = new ItemLastPublishedDateCriteria(sinceLastPublished.Value.ToString("yyyy-MM-dd hh:mm:ss"), Criteria.GreaterThanOrEqual);
                basedOnSchemaAndInPublication = CriteriaFactory.And(basedOnSchemaAndInPublication, dateLastPublished);
            }

            Query q = new Query(basedOnSchemaAndInPublication);

            SortParameter sortParameter = new SortParameter(SortParameter.ItemLastPublishedDate, SortParameter.Descending);
            q.AddSorting(sortParameter);

            if (limit.HasValue && limit.Value > 0)
            {
                q.AddLimitFilter(new LimitFilter(limit.Value));
            }
            else
            {
                q.AddLimitFilter(new LimitFilter(maximumComponent));
            }

            return q.ExecuteQuery();
        }
开发者ID:rainmaker2k,项目名称:TridionMVCDotNet,代码行数:35,代码来源:TridionComponentFactoryBase.cs

示例2: ToTridionQuery


//.........这里部分代码省略.........
            // Add filtering for meta data
            Criteria schemasAndMetaData;
            if (metaQueryItems.Count > 0)
            {
                Criteria metaQuery;
                Criteria[] metaCriterias = new Criteria[metaQueryItems.Count];
                int metaCount = 0;
                foreach (MetaQueryItem queryItem in metaQueryItems)
                {
                    CustomMetaKeyCriteria metaField = new CustomMetaKeyCriteria(queryItem.MetaField);
                    CustomMetaValueCriteria metaCriteria;
                    FieldOperator metaOperator = typeof(Criteria).GetField(queryItem.MetaOperator.ToString()).GetValue(null) as FieldOperator;

                    switch (queryItem.MetaValue.GetType().Name)
                    {
                        case "DateTime":
                            DateTime tempDate = (DateTime)queryItem.MetaValue;
                            metaCriteria = new CustomMetaValueCriteria(metaField, tempDate.ToString("yyyy-MM-dd HH:mm:ss.fff"), "yyyy-MM-dd HH:mm:ss.SSS", metaOperator);
                            break;
                        case "Float":
                            metaCriteria = new CustomMetaValueCriteria(metaField, (float)queryItem.MetaValue, metaOperator);
                            break;
                        case "String":
                            metaCriteria = new CustomMetaValueCriteria(metaField, queryItem.MetaValue as string, metaOperator);
                            break;
                        default:
                            throw new System.Exception("Unexpected query item data type; " + queryItem.MetaValue.GetType().Name);
                    }

                    metaCriterias.SetValue(metaCriteria, metaCount);
                    metaCount++;
                }

                if (MetaQueryLogic == QueryLogic.AllCriteriaMatch)
                {
                    metaQuery = CriteriaFactory.And(metaCriterias);
                }
                else
                {
                    metaQuery = CriteriaFactory.Or(metaCriterias);
                }
                schemasAndMetaData = CriteriaFactory.And(basedOnSchemaAndInPublication, metaQuery);
            }
            else
            {
                schemasAndMetaData = basedOnSchemaAndInPublication;
            }

            Criteria allConditions;
            if (KeywordValues.Count > 0)
            {
                Criteria[] keywordCriterias = new Criteria[KeywordValues.Count];
                int keywordCount = 0;
                foreach (KeywordItem keyCriteria in KeywordValues)
                {
                    TaxonomyKeywordCriteria keywordField = new TaxonomyKeywordCriteria(keyCriteria.CategoryUri, keyCriteria.KeywordUri, false);
                    keywordCriterias.SetValue(keywordField, keywordCount);
                    keywordCount++;
                }

                Criteria keyQuery;
                if (KeywordQueryLogic == QueryLogic.AllCriteriaMatch)
                {
                    keyQuery = CriteriaFactory.And(keywordCriterias);
                }
                else
                {
                    keyQuery = CriteriaFactory.Or(keywordCriterias);
                }
                allConditions = CriteriaFactory.And(schemasAndMetaData, keyQuery);
            }
            else
            {
                allConditions = schemasAndMetaData;
            }


            q = new Query(allConditions);
            if (maxmimumComponents != 0 && maxmimumComponents != int.MaxValue)
            {
                LimitFilter limitResults = new LimitFilter(maxmimumComponents);
                q.SetResultFilter(limitResults);
            }

            // Sort column should either be a standard or custom metaData field
            SortColumn paramSort;
            if (typeof(SortParameter).GetField(QuerySortField) != null)
            {
                paramSort = typeof(SortParameter).GetField(QuerySortField).GetValue(null) as SortColumn;
            }
            else
            {
                // Why do we need to tell Tridion what data type the field is! Its in the database already!
                paramSort = new CustomMetaKeyColumn(QuerySortField, typeof(MetadataType).GetField(SortType.ToString()).GetValue(null) as MetadataType);
            }
            SortDirection paramSortDirection = typeof(SortParameter).GetField(QuerySortOrder.ToString()).GetValue(null) as SortDirection;
            SortParameter sortParameter = new SortParameter(paramSort, paramSortDirection);
            q.AddSorting(sortParameter);
            return q;
        }
开发者ID:dd4t,项目名称:DD4T.Providers.SDLTridion2011sp1,代码行数:101,代码来源:ExtendedQueryParameters.cs

示例3: LastPublished

        public DateTime LastPublished(string[] schemaUris)
        {
            TcmUri schemaTcmUri = new TcmUri(schemaUris.First());

            PublicationCriteria publicationCriteria = new PublicationCriteria(schemaTcmUri.PublicationId);

            Criteria[] schemaCriterias = schemaUris
                .Select(uri => new ItemSchemaCriteria(new TcmUri(uri).ItemId))
                .ToArray();

            Criteria basedOnSchema = CriteriaFactory.Or(schemaCriterias);
            Criteria basedOnSchemaAndInPublication = CriteriaFactory.And(publicationCriteria, basedOnSchema);

            Query q = new Query(basedOnSchemaAndInPublication);

            SortParameter sortParameter = new SortParameter(SortParameter.ItemLastPublishedDate, SortParameter.Descending);
            q.AddSorting(sortParameter);
            q.AddLimitFilter(new LimitFilter(1));

            string[] foundUris = q.ExecuteQuery();

            if (foundUris.Length > 0)
            {
                using (Tridion.ContentDelivery.Meta.ComponentMetaFactory fac = new Tridion.ContentDelivery.Meta.ComponentMetaFactory(schemaTcmUri.PublicationId))
                {
                    Tridion.ContentDelivery.Meta.IComponentMeta meta = fac.GetMeta(foundUris[0]);
                    return meta.LastPublicationDate;
                }
            }

            return DateTime.MinValue;
        }
开发者ID:rainmaker2k,项目名称:TridionMVCDotNet,代码行数:32,代码来源:TridionComponentFactoryBase.cs


注:本文中的Query.AddSorting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。