本文整理汇总了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();
}
示例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;
}
示例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;
}