本文整理汇总了C#中Query.AppendField方法的典型用法代码示例。如果您正苦于以下问题:C# Query.AppendField方法的具体用法?C# Query.AppendField怎么用?C# Query.AppendField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query.AppendField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveProductItem
/// <summary>
/// Resolves the product item.
/// </summary>
/// <param name="arguments">The arguments.</param>
/// <returns>The product item.</returns>
public override Item ResolveProductItem(params string[] arguments)
{
Assert.ArgumentNotNull(arguments, "arguments");
string[] nameAndCode = arguments[0].Split('_');
string name = nameAndCode[0];
string code = nameAndCode[1];
Assert.IsNotNullOrEmpty(name, "name");
Assert.IsNotNullOrEmpty(code, "code");
Item productFolderItem = Sitecore.Context.Database.GetItem(Context.Entity.GetConfiguration<BusinessCatalogSettings>().ProductsLink);
Assert.IsNotNull(productFolderItem, "Products root item cannot be null.");
Query query = new Query { SearchRoot = productFolderItem.ID.ToString() };
query.AppendField("Product Code", code, MatchVariant.Exactly);
query.AppendCondition(QueryCondition.And);
query.AppendAttribute("key", name, MatchVariant.Exactly);
foreach (Item item in this.SearchProvider.Search(query, Sitecore.Context.Database))
{
if (ProductRepositoryUtil.IsBasedOnTemplate(item.Template, new ID(this.ProductTemplateId)))
{
return item;
}
}
return default(Item);
}
示例2: Parse
/// <summary>
/// Parses the specified query.
/// </summary>
/// <param name="query">The query.</param>
/// <returns>The converted query.</returns>
/// <exception cref="InvalidOperationException">Query contains operators that are not supported</exception>
public virtual Query Parse(Sitecore.Data.Query.Opcode query)
{
Assert.IsNotNull(query, "Query must not be null");
Sitecore.Data.Query.Predicate predicate = query as Sitecore.Data.Query.Predicate;
if (predicate != null)
{
Assert.IsNull(predicate.NextStep, "Continuation is not supported");
return this.Parse(predicate.Expression);
}
Sitecore.Data.Query.BinaryOperator binaryOperator = query as Sitecore.Data.Query.BinaryOperator;
if (binaryOperator != null)
{
if (binaryOperator is Sitecore.Data.Query.AndOperator)
{
Query result = new Query();
result.AppendSubquery(this.Parse(binaryOperator.Left));
result.AppendCondition(QueryCondition.And);
result.AppendSubquery(this.Parse(binaryOperator.Right));
return result;
}
if (binaryOperator is Sitecore.Data.Query.OrOperator)
{
Query result = new Query();
result.AppendSubquery(this.Parse(binaryOperator.Left));
result.AppendCondition(QueryCondition.Or);
result.AppendSubquery(this.Parse(binaryOperator.Right));
return result;
}
string fieldName = null;
string fieldValue = null;
if (binaryOperator.Left is Sitecore.Data.Query.FieldElement)
{
fieldName = ((Sitecore.Data.Query.FieldElement)binaryOperator.Left).Name;
if (binaryOperator.Right is Sitecore.Data.Query.BooleanValue)
{
fieldValue = ((Sitecore.Data.Query.BooleanValue)binaryOperator.Right).Value.ToString();
}
else if (binaryOperator.Right is Sitecore.Data.Query.Number)
{
fieldValue = ((Sitecore.Data.Query.Number)binaryOperator.Right).Value.ToString();
}
else if (binaryOperator.Right is Sitecore.Data.Query.Literal)
{
fieldValue = ((Sitecore.Data.Query.Literal)binaryOperator.Right).Text;
}
}
if (binaryOperator.Right is Sitecore.Data.Query.FieldElement)
{
fieldName = ((Sitecore.Data.Query.FieldElement)binaryOperator.Right).Name;
if (binaryOperator.Left is Sitecore.Data.Query.BooleanValue)
{
fieldValue = ((Sitecore.Data.Query.BooleanValue)binaryOperator.Left).Value.ToString();
}
else if (binaryOperator.Left is Sitecore.Data.Query.Number)
{
fieldValue = ((Sitecore.Data.Query.Number)binaryOperator.Left).Value.ToString();
}
else if (binaryOperator.Left is Sitecore.Data.Query.Literal)
{
fieldValue = ((Sitecore.Data.Query.Literal)binaryOperator.Left).Text;
}
}
if (binaryOperator is Sitecore.Data.Query.EqualsOperator)
{
Assert.IsNotNull(fieldName, "fieldName must not be null");
Assert.IsNotNull(fieldValue, "fieldValue must not be null");
Query result = new Query();
if (fieldValue.StartsWith("%") && fieldValue.EndsWith("%") && (fieldValue.Length > 1))
{
if (fieldName.StartsWith("@"))
{
result.AppendAttribute(fieldName.Substring(1), fieldValue.Substring(1, fieldValue.Length - 2), MatchVariant.Like);
}
else
{
result.AppendField(fieldName, fieldValue.Substring(1, fieldValue.Length - 2), MatchVariant.Like);
}
}
else
//.........这里部分代码省略.........
示例3: Process
/// <summary>
/// Runs the processor.
/// </summary>
/// <param name="args">The arguments.</param>
public void Process([NotNull] PipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
Assert.IsNotNull(this.ShopContext, Texts.UnableToSaveTheOrderShopContextCannotBeNull);
Assert.IsNotNull(this.OrderManager, Texts.UnableToSaveTheOrderOrderManagerCannotBeNull);
Assert.IsNotNull(this.OrderRepository, Texts.UnableToSaveTheOrderOrderRepositoryCannotBeNull);
Assert.IsNotNull(this.TransientOrderConverter, Texts.UnableToSaveTheOrderTransientOrderConverterCannotBeNull);
Query searchQuery = new Query();
searchQuery.AppendField("OrderNumber", string.Empty, MatchVariant.Like);
IEnumerator<Order> orderEnumerator = this.OrderManager.GetOrders(searchQuery).GetEnumerator();
ICollection<Exception> caughtExceptions = new LinkedList<Exception>();
do
{
try
{
if (!orderEnumerator.MoveNext())
{
break;
}
Order originalOrder = orderEnumerator.Current;
OrderManagement.Orders.Order convertedOrder = this.TransientOrderConverter.Convert(originalOrder);
convertedOrder.ShopContext = this.ShopContext.InnerSite.Name;
new ProcessingOrder(convertedOrder).ApplyCalculations();
this.OrderRepository.Save(new[] { convertedOrder });
}
catch (Exception e)
{
caughtExceptions.Add(e);
}
}
while (true);
if (caughtExceptions.Count > 0)
{
throw new AggregateException(caughtExceptions);
}
}