本文整理汇总了C#中Query.ExecuteQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Query.ExecuteQuery方法的具体用法?C# Query.ExecuteQuery怎么用?C# Query.ExecuteQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query.ExecuteQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryRedirect
public void TryRedirect(Object s, EventArgs e)
{
HttpContext context = HttpContext.Current;
int publicationId = int.Parse(ConfigurationManager.AppSettings["GlobalPubId"]);
string redirectField = ConfigurationManager.AppSettings["RedirectUrlField"];
string url = context.Request.Url.PathAndQuery;
int pos = url.IndexOf("?");
if (pos > 0) url = url.Substring(0, pos);
PublicationCriteria publicationCriteria = new PublicationCriteria(publicationId);
ItemTypeCriteria itemCriteria = new ItemTypeCriteria(64);
CustomMetaValueCriteria cmvCriteria = new CustomMetaValueCriteria(new CustomMetaKeyCriteria(redirectField), url);
AndCriteria andCriteria = new AndCriteria(new Criteria[] { publicationCriteria, itemCriteria, cmvCriteria });
Query query = new Query(andCriteria);
string[] results = query.ExecuteQuery();
if (results.Length > 0)
{
PageLink pageLink = new PageLink(publicationId);
Link link = pageLink.GetLink(results[0]);
if (link.IsResolved)
{
// Redirect
HttpResponse response = context.Response;
response.Clear();
response.RedirectLocation = link.Url;
response.StatusCode = 301;
response.StatusDescription = "301 Moved Permanently";
response.Write("Page has moved to " + link.Url);
response.End();
}
}
}
示例2: 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();
}
示例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;
}
示例4: TryFindBinary
public bool TryFindBinary(string url, out IBinary binary)
{
string encodedUrl = HttpUtility.UrlPathEncode(url);
binary = null;
//using (var sqlBinMetaHome = new Com.Tridion.Broker.Binaries.Meta.SQLBinaryMetaHome())
//{
// Com.Tridion.Meta.BinaryMeta binaryMeta = sqlBinMetaHome.FindByURL(PublicationId, encodedUrl); // "/Images/anubis_pecunia160_tcm70-520973.jpg"
// if (binaryMeta != null)
// {
// using (var sqlBinaryHome = new Com.Tridion.Broker.Binaries.SQLBinaryHome())
// {
// Com.Tridion.Data.BinaryData binData = sqlBinaryHome.FindByPrimaryKey(PublicationId, (int)binaryMeta.GetId());
// if (binData != null)
// {
// binary = new Binary(this)
// {
// Id = String.Format("tcm:{0}-{1}", binData.GetPublicationId(), binData.GetId()),
// Url = url,
// LastPublishedDate = DateTime.Now,
// Multimedia = null,
// VariantId = binData.GetVariantId()
// };
// return true;
// }
// }
// }
// return false;
//}
Query binaryQuery = new Query();
ItemTypeCriteria isMultiMedia = new ItemTypeCriteria(32);
PublicationCriteria inPub = new PublicationCriteria(PublicationId);
Criteria allCriteria = CriteriaFactory.And(isMultiMedia, inPub);
string[] results = binaryQuery.ExecuteQuery();
binary = null;
return true;
foreach (var item in results) {
}
}
示例5: FindComponents
//.........这里部分代码省略.........
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("TridionMetaQueryFactory-Unexpected query item data type; " + queryItem.MetaValue.GetType().Name);
break;
}
metaCriterias.SetValue(metaCriteria, metaCount);
metaCount++;
}
if (queryParameters.MetaQueryLogic == ExtendedQueryParameters.QueryLogic.AllCriteriaMatch)
{
metaQuery = CriteriaFactory.And(metaCriterias);
}
else
{
metaQuery = CriteriaFactory.Or(metaCriterias);
}
schemasAndMetaData = CriteriaFactory.And(basedOnSchemaAndInPublication, metaQuery);
}
else
{
schemasAndMetaData = basedOnSchemaAndInPublication;
}
Criteria allConditions;
if (queryParameters.KeywordValues.Count > 0)
{
Criteria[] keywordCriterias = new Criteria[queryParameters.KeywordValues.Count];
int keywordCount = 0;
foreach (KeywordItem keyCriteria in queryParameters.KeywordValues)
{
TaxonomyKeywordCriteria keywordField = new TaxonomyKeywordCriteria(keyCriteria.CategoryUri, keyCriteria.KeywordUri, false);
keywordCriterias.SetValue(keywordField, keywordCount);
keywordCount++;
}
Criteria keyQuery;
if (queryParameters.KeywordQueryLogic == ExtendedQueryParameters.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(queryParameters.QuerySortField) != null)
{
paramSort = typeof(SortParameter).GetField(queryParameters.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(queryParameters.QuerySortField, typeof(MetadataType).GetField(queryParameters.SortType.ToString()).GetValue(null) as MetadataType);
}
SortDirection paramSortDirection = typeof(SortParameter).GetField(queryParameters.QuerySortOrder.ToString()).GetValue(null) as SortDirection;
SortParameter sortParameter = new SortParameter(paramSort, paramSortDirection);
q.AddSorting(sortParameter);
string[] results = q.ExecuteQuery();
return results;
}