/// <summary> /// Gets the element conditions. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="node">The node.</param> /// <returns></returns> public override ConditionElementCollection GetElementConditions(string expressionPlace, FilterExpressionNode node) { ConditionElementCollection retVal = new ConditionElementCollection(); if (node != null) { ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } //Default Decimal conditions var conditions = elementDef.Conditions ?? ConditionDecimalDefs; if (elementDef.HasChildren && node.Method != null) { ElementDefs methodDef = elementDef.GetMethodDef(node.Method.Key); if (methodDef == null) { throw new ArgumentException("method " + node.Method.Key + " not registered"); } conditions = methodDef.Conditions; } //Add stored condition elements in Tag property in definition foreach (ElementDefs conditionDef in conditions) { retVal.Add(conditionDef.Tag as ConditionElement); } } return(retVal); }
public object Clone() { ElementDefs retVal = new ElementDefs(); retVal.Key = this.Key; retVal.Name = this.Name; retVal.Descr = this.Descr; if (this.Conditions != null) { retVal.Conditions = this.Conditions.Select(x => x.Clone() as ElementDefs); } if (this.Methods != null) { retVal.Methods = this.Methods.Select(x => x.Clone() as ElementDefs); } if (this.Childrens != null) { retVal.Childrens = this.Methods.Select(x => x.Clone() as ElementDefs); } if (this.Tag != null) { ICloneable clonedObjTag = this.Tag as ICloneable; if (clonedObjTag != null) { retVal.Tag = clonedObjTag.Clone(); } } return(retVal); }
/// <summary> /// Creates the filter expression node. /// </summary> /// <param name="pattern">The pattern.</param> /// <param name="displayName">The display name.</param> /// <param name="metaClass">The meta class.</param> /// <returns></returns> protected virtual IEnumerable <ElementDefs> GetElementDefsByMetaClass(string pattern, MetaClass metaClass) { if (metaClass == null) { throw new ArgumentNullException("metaClass"); } foreach (MetaField field in metaClass.MetaFields) { if (customFieldFiter.All(x => x(field))) { IEnumerable <ElementDefs> conditonDef; if (MetaDataType2ElDefMap.TryGetValue(field.DataType, out conditonDef)) { string codeExpr = string.IsNullOrEmpty(pattern) ? field.Name : string.Format(pattern, field.Name); string dynamicKey = ElementDefs.GetDynamicKey(metaClass.Name + "." + field.Name + "." + codeExpr); ElementDefs retVal = new ElementDefs() { Key = dynamicKey, Name = codeExpr, Descr = field.FriendlyName, Conditions = conditonDef }; yield return(retVal); } } } }
/// <summary> /// Searches in registered ElementDefs /// </summary> /// <param name="key">The key.</param> /// <returns></returns> public ElementDefs FindElementDef(string key) { ElementDefs retVal = null; AllRegisteredDefinitionsMap.TryGetValue(key, out retVal); return(retVal); }
/// <summary> /// Creates the method element by him definitions /// </summary> /// <param name="methodDef">The method def.</param> /// <param name="customControlPath">The custom control path.</param> /// <returns></returns> protected virtual MethodElement CreateMethodElement(ElementDefs methodDef, string customControlPath) { MethodElement retVal = new MethodElement(methodDef.Key, methodDef.Descr, methodDef.Descr); retVal.CustomControlPath = customControlPath; methodDef.Tag = retVal; return(retVal); }
/// <summary> /// Creates the filter expression node by him definitions /// </summary> /// <param name="elementDef">The element def.</param> /// <returns></returns> protected override FilterExpressionNode CreateFilterExpressionNode(ElementDefs elementDef) { FilterExpressionNode retVal = base.CreateFilterExpressionNode(elementDef); retVal.Attributes = new System.Collections.Specialized.NameValueCollection(); //Disable adding child elements retVal.Attributes.Add(FilterExpressionNode.filterExpressionChildEnableKey, false.ToString()); return(retVal); }
/// <summary> /// Creates the condition eement by him definitions /// </summary> /// <param name="conditionDef">The condition def.</param> /// <param name="condElType">Type of the cond el.</param> /// <param name="customControlPath">The custom control path.</param> /// <returns></returns> protected virtual ConditionElement CreateConditionEement(ElementDefs conditionDef, ConditionElementType condElType, string customControlPath) { ConditionElement retVal = new ConditionElement(condElType, conditionDef.Key, conditionDef.Descr, conditionDef.Descr); retVal.CustomControlPath = customControlPath; conditionDef.Tag = retVal; return(retVal); }
/// <summary> /// Gets the element methods. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="node">The node.</param> /// <returns></returns> public override MethodElementCollection GetElementMethods(string expressionPlace, FilterExpressionNode node) { MethodElementCollection retVal = new MethodElementCollection(); ElementDefs elementDef = FindElementDef(node.Key); if (elementDef != null && elementDef.Methods != null) { foreach (ElementDefs methodDef in elementDef.Methods) { retVal.Add(methodDef.Tag as MethodElement); } } return(retVal); }
/// <summary> /// Gets the new elements. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <returns></returns> /// <summary> /// Gets the new elements. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <returns></returns> public override FilterExpressionNodeCollection GetNewElements(string expressionPlace, FilterExpressionNode parent) { List <FilterExpressionNode> retVal = new List <FilterExpressionNode>(); FilterExpressionNode parentMethodNode = null; FilterExpressionNode parentNext = parent; string[] expressionPlaceParts = expressionPlace.Split(':'); string realExpressionPlace = expressionPlaceParts.Length > 1 ? expressionPlaceParts[1] : string.Empty; //detected presents parent block type MethodBlock while (parentNext != null && parentMethodNode == null) { if (parentNext.NodeType == FilterExpressionNodeType.MethodBlock) { parentMethodNode = parentNext; } parentNext = parentNext.ParentNode; } //Get Account elements by default IEnumerable <ElementDefs> returnedElementDefs = AccountDefs; //Get child elements if parent node is method block if (parentMethodNode != null) { ElementDefs collectionElementDef = FindElementDef(parentMethodNode.Key); if (collectionElementDef == null) { throw new NullReferenceException("element " + parentMethodNode.Key + " not registered"); } returnedElementDefs = collectionElementDef.Childrens; //Is call from custom method control //Do not return any elements for method control binding if (realExpressionPlace == "Sum") { returnedElementDefs = null; } } if (returnedElementDefs != null) { retVal.AddRange(returnedElementDefs.Select(x => (x.Tag as FilterExpressionNode).Clone(true))); } // Sort retVal By Name retVal.Sort(delegate(FilterExpressionNode x, FilterExpressionNode y) { return(x.Name.CompareTo(y.Name)); }); return(new FilterExpressionNodeCollection(retVal.ToArray())); }
/// <summary> /// Creates the filter expression node by him definitions /// </summary> /// <param name="elementDef">The element def.</param> /// <returns></returns> protected virtual FilterExpressionNode CreateFilterExpressionNode(ElementDefs elementDef) { FilterExpressionNode retVal = new FilterExpressionNode(elementDef.Key, elementDef.Descr); elementDef.Tag = retVal; if (elementDef.Childrens != null || elementDef.Methods != null) { retVal.NodeType = FilterExpressionNodeType.MethodBlock; retVal.ChildNodes = new FilterExpressionNodeCollection(); if (elementDef.Childrens != null) { retVal.ChildNodes.AddRange(elementDef.Childrens.Select(x => CreateFilterExpressionNode(x)).ToArray()); } } return(retVal); }
/// <summary> /// Gets the element conditions. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="node">The node.</param> /// <returns></returns> public override ConditionElementCollection GetElementConditions(string expressionPlace, FilterExpressionNode node) { ConditionElementCollection retVal = new ConditionElementCollection(); ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } foreach (ElementDefs condDef in elementDef.Conditions) { retVal.Add(condDef.Tag as ConditionElement); } return(retVal); }
/// <summary> /// Converts the node to string expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected virtual string ConvertNodeToStringExpression(FilterExpressionNode node) { string retVal = String.Empty; ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } if (node.Condition != null) { ElementDefs condition = elementDef.GetConditionDefByName(node.Condition.Key); //Apply type conversion pattern string nodeCode = string.Format(condition.ConverstionPattern, elementDef.Name); string conditionCode = condition.Name; bool isNegative = false; // Detect "NOT" statement if (conditionCode.StartsWith("Not.")) { conditionCode = conditionCode.Substring(conditionCode.IndexOf(".") + 1); isNegative = true; } string nodeValue = GetEscapedAndCleanedExpressionNodeRightValue(node); //for text conditions nees specific format if (ConditionTextDefs.Contains(condition)) { retVal = String.Format("{0}{1}.{2}(\"{3}\")", isNegative ? "!" : String.Empty, nodeCode, conditionCode, nodeValue); } else { retVal = String.Format("{0} {1} {2}", nodeCode, conditionCode, nodeValue); } } else { throw new ApplicationException("Invalid NodeType"); } return(retVal); }
protected override void RegisterProviderElementDefinitions() { //First call base implementation base.RegisterProviderElementDefinitions(); #region Method definitions MethodSumDef = new ElementDefs() { Key = ElementDefs.Method_Sum, Name = "GetCollectionSum", Descr = "Sum", Conditions = ConditionDecimalDefs }; MethodCountDef = new ElementDefs() { Key = ElementDefs.Method_Count, Name = "GetValidatedCount", Descr = "Count", Conditions = ConditionIntegerDefs }; MethodAnyDef = new ElementDefs() { Key = ElementDefs.Method_Any, Name = "ValidateAny", Descr = "Any", Conditions = ConditionBoolDefs }; MethodAllDef = new ElementDefs() { Key = ElementDefs.Method_All, Name = "ValidateAll", Descr = "All", Conditions = ConditionBoolDefs }; CollectionMethodDefs = new ElementDefs[] { MethodSumDef, MethodCountDef, MethodAllDef, MethodAnyDef }; RegisterDefinitions(CollectionMethodDefs); #endregion #region element definitions ShipmentDefs = new ElementDefs[] { //new ElementDefs() { Key = ElementDefs.Shipment_LienItems, Name = "this.PreparePromotionEntries(this.PromotionContext.SourceEntriesSet.Entries)", Descr="Shipment.LineItems", Methods = CollectionMethodDefs, Childrens = LineItemDefs}, new ElementDefs() { Key = ElementDefs.Shipment_ShippingMethodName, Name = "this.PromotionCurrentShipment.ShippingMethodName", Descr = "Shipment.ShippingMethodName", Conditions = ConditionTextDefs }, //TODO: Add other prop }; RegisterDefinitions(ShipmentDefs); OrderAddressDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.OrderAddress_Name, Name = "this['Name']", Descr = "Name", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_FirstName, Name = "this['FirstName']", Descr = "FirstName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_LastName, Name = "this['LastName']", Descr = "LastName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_Organization, Name = "this['Organization']", Descr = "Organization", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_Line1, Name = "this['Line1']", Descr = "Line1", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_Line2, Name = "this['Line2']", Descr = "Line2", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_City, Name = "this['City']", Descr = "City", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_State, Name = "this['State']", Descr = "State", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_CountryCode, Name = "this['CountryCode']", Descr = "CountryCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_CountryName, Name = "this['CountryName']", Descr = "CountryName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_PostalCode, Name = "this['PostalCode']", Descr = "PostalCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_RegionCode, Name = "this['RegionCode']", Descr = "RegionCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_RegionName, Name = "this['RegionName']", Descr = "RegionName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_DaytimePhoneNumber, Name = "this['DaytimePhoneNumber']", Descr = "DaytimePhoneNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_EveningPhoneNumber, Name = "this['EveningPhoneNumber']", Descr = "EveningPhoneNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_FaxNumber, Name = "this['FaxNumber']", Descr = "FaxNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderAddress_Email, Name = "this['Email']", Descr = "Email", Conditions = ConditionTextDefs }, }.Concat(base.GetElementDefsByMetaClass("this['{0}']", OrderContext.Current.OrderAddressMetaClass)).Select(x => { x.Name = x.Name.Replace("\"", "'"); return(x); }); RegisterDefinitions(OrderAddressDefs); LineItemDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.LineItem_Address, Name = "this['Address']", Descr = "Address", Methods = new ElementDefs[] { MethodAnyDef }, Childrens = OrderAddressDefs }, new ElementDefs() { Key = ElementDefs.LineItem_Quantity, Name = "this.Quantity", Descr = "Quantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_ListPrice, Name = "this.CostPerEntry", Descr = "ListPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_Catalog, Name = "this.CatalogName", Descr = "Catalog", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_CatalogNode, Name = "this.CatalogNodeCode", Descr = "CatalogNode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_CatalogEntryId, Name = "this.CatalogEntryCode", Descr = "CatalogEntryId", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_MinQuantity, Name = "this['MinQuantity']", Descr = "MinQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_MaxQuantity, Name = "this['MaxQuantity']", Descr = "MaxQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_PlacedPrice, Name = "this['PlacedPrice']", Descr = "PlacedPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_LineItemDiscountAmount, Name = "this['LineItemDiscountAmount']", Descr = "LineItemDiscountAmount", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_OrderLevelDiscountAmount, Name = "this['OrderLevelDiscountAmount']", Descr = "OrderLevelDiscountAmount", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_ShippingMethodName, Name = "this['ShippingMethodName']", Descr = "ShippingMethodName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_ExtendedPrice, Name = "this['ExtendedPrice']", Descr = "ExtendedPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_Description, Name = "this['Description']", Descr = "Description", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_Status, Name = "this['Status']", Descr = "Status", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_DisplayName, Name = "this['DisplayName']", Descr = "DisplayName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.LineItem_AllowBackordersAndPreorders, Name = "this['AllowBackordersAndPreorders']", Descr = "AllowBackordersAndPreorders", Conditions = ConditionBoolDefs }, new ElementDefs() { Key = ElementDefs.LineItem_InStockQuantity, Name = "this['InStockQuantity']", Descr = "InStockQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_PreorderQuantity, Name = "this['PreorderQuantity']", Descr = "PreorderQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_BackorderQuantity, Name = "this['BackorderQuantity']", Descr = "BackorderQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.LineItem_InventoryStatus, Name = "this['InventoryStatus']", Descr = "InventoryStatus", Conditions = ConditionIntegerDefs } }.Concat(base.GetElementDefsByMetaClass("this['{0}']", OrderContext.Current.LineItemMetaClass)).Select(x => { x.Name = x.Name.Replace("\"", "'"); return(x); }); RegisterDefinitions(LineItemDefs); //Create lineItems with address elements LineItemWithAddressDefs = LineItemDefs.Concat(OrderAddressDefs); ShoppingCartDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.ShoppingCart_BillingCurrency, Name = "this.ShoppingCart.BillingCurrency", Descr = "ShoppingCart.BillingCurrency", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_CustomerName, Name = "this.ShoppingCart.CustomerName", Descr = "ShoppingCart.CustomerName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_HandlingTotal, Name = "this.ShoppingCart.HandlingTotal", Descr = "ShoppingCart.HandlingTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_Name, Name = "this.ShoppingCart.Name", Descr = "ShoppingCart.Name", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_ShippingTotal, Name = "this.ShoppingCart.ShippingTotal", Descr = "ShoppingCart.ShippingTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_Status, Name = "this.ShoppingCart.Status", Descr = "ShoppingCart.Status", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_SubTotal, Name = "this.ShoppingCart.SubTotal", Descr = "ShoppingCart.SubTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_TaxTotal, Name = "this.ShoppingCart.TaxTotal", Descr = "ShoppingCart.TaxTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.ShoppingCart_Total, Name = "this.ShoppingCart.Total", Descr = "ShoppingCart.Total", Conditions = ConditionDecimalDefs } }.Concat(base.GetElementDefsByMetaClass("this.ShoppingCart[\"{0}\"]", OrderContext.Current.ShoppingCartMetaClass)); RegisterDefinitions(ShoppingCartDefs); OrderFormDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.OrderForm_LineItems, Name = "this.PromotionContext.SourceEntriesSet.Entries", Descr = "OrderForm.LineItems", Methods = CollectionMethodDefs, Childrens = LineItemDefs }, //AHTUNG: Need add property to OrderForm.BillingAddress represents coolections of addresses new ElementDefs() { Key = ElementDefs.OrderForm_BillingAddress, Name = "this.PromotionOrderFormBillingAddress", Descr = "OrderForm.BillingAddress", Methods = new ElementDefs[] { MethodAnyDef }, Childrens = OrderAddressDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_Shipments, Name = "this.PromotionCurrentOrderForm.Shipments", Descr = "OrderForm.Shipments", Methods = CollectionMethodDefs, Childrens = ShipmentDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_DiscountAmount, Name = "this.PromotionCurrentOrderForm.DiscountAmount", Descr = "OrderForm.DiscountAmount", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_Name, Name = "this.PromotionCurrentOrderForm.Name", Descr = "OrderForm.Name", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_HandlingTotal, Name = "this.PromotionCurrentOrderForm.HandlingTotal", Descr = "OrderForm.HandlingTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_ShippingTotal, Name = "this.PromotionCurrentOrderForm.ShippingTotal", Descr = "OrderForm.ShippingTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_Status, Name = "this.PromotionCurrentOrderForm.Status", Descr = "OrderForm.Status", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_SubTotal, Name = "this.PromotionCurrentOrderForm.SubTotal", Descr = "OrderForm.SubTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_TaxTotal, Name = "this.PromotionCurrentOrderForm.TaxTotal", Descr = "OrderForm.TaxTotal", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.OrderForm_Total, Name = "this.PromotionCurrentOrderForm.Total", Descr = "OrderForm.Total", Conditions = ConditionDecimalDefs } }.Concat(base.GetElementDefsByMetaClass("this.PromotionCurrentOrderForm[\"{0}\"]", OrderContext.Current.OrderFormMetaClass)); RegisterDefinitions(OrderFormDefs); //TargetLineItem TargetLineItemDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.TargetLineItem_ListPrice, Name = "this.PromotionTargetLineItem.CostPerEntry", Descr = "TargetLineItem.ListPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_Catalog, Name = "this.PromotionTargetLineItem.CatalogName", Descr = "TargetLineItem.Catalog", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_CatalogNode, Name = "this.PromotionTargetLineItem.CatalogNodeCode", Descr = "TargetLineItem.CatalogNode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_CatalogEntryId, Name = "this.PromotionTargetLineItem.CatalogEntryCode", Descr = "TargetLineItem.CatalogEntryId", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_MinQuantity, Name = "this.PromotionTargetLineItem[\"MinQuantity\"]", Descr = "TargetLineItem.MinQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_MaxQuantity, Name = "this.PromotionTargetLineItem[\"MaxQuantity\"]", Descr = "TargetLineItem.MaxQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_PlacedPrice, Name = "this.PromotionTargetLineItem[\"PlacedPrice\"]", Descr = "TargetLineItem.PlacedPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_LineItemDiscountAmount, Name = "this.PromotionTargetLineItem[\"LineItemDiscountAmount\"]", Descr = "TargetLineItem.LineItemDiscountAmount", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_OrderLevelDiscountAmount, Name = "this.PromotionTargetLineItem[\"OrderLevelDiscountAmount\"]", Descr = "TargetLineItem.OrderLevelDiscountAmount", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_ShippingMethodName, Name = "this.PromotionTargetLineItem[\"ShippingMethodName\"]", Descr = "TargetLineItem.ShippingMethodName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_ExtendedPrice, Name = "this.PromotionTargetLineItem[\"ExtendedPrice\"]", Descr = "TargetLineItem.ExtendedPrice", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_Description, Name = "this.PromotionTargetLineItem[\"Description\"]", Descr = "TargetLineItem.Description", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_Status, Name = "this.PromotionTargetLineItem[\"Status\"]", Descr = "TargetLineItem.Status", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_DisplayName, Name = "this.PromotionTargetLineItem[\"DisplayName\"]", Descr = "TargetLineItem.DisplayName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_AllowBackordersAndPreorders, Name = "this.PromotionTargetLineItem[\"AllowBackordersAndPreorders\"]", Descr = "TargetLineItem.AllowBackordersAndPreorders", Conditions = ConditionBoolDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_InStockQuantity, Name = "this.PromotionTargetLineItem[\"InStockQuantity\"]", Descr = "TargetLineItem.InStockQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_PreorderQuantity, Name = "this.PromotionTargetLineItem[\"PreorderQuantity\"]", Descr = "TargetLineItem.PreorderQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_BackorderQuantity, Name = "this.PromotionTargetLineItem[\"BackorderQuantity\"]", Descr = "TargetLineItem.BackorderQuantity", Conditions = ConditionDecimalDefs }, new ElementDefs() { Key = ElementDefs.TargetLineItem_InventoryStatus, Name = "this.PromotionTargetLineItem[\"InventoryStatus\"]", Descr = "TargetLineItem.InventoryStatus", Conditions = ConditionIntegerDefs } }.Concat(base.GetElementDefsByMetaClass("this.PromotionTargetLineItem[\"{0}\"]", OrderContext.Current.LineItemMetaClass)); RegisterDefinitions(TargetLineItemDefs); //RunningTotal RuningTotalDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.RunningTotal, Name = "this.PromotionResult.RunningTotal", Descr = "RunningTotal", Conditions = ConditionDecimalDefs } }; RegisterDefinitions(RuningTotalDefs); #endregion }
/// <summary> /// Gets the new elements. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="parent"></param> /// <returns></returns> public override FilterExpressionNodeCollection GetNewElements(string expressionPlace, FilterExpressionNode parent) { List <FilterExpressionNode> retVal = new List <FilterExpressionNode>(); FilterExpressionNode parentMethodNode = null; FilterExpressionNode parentNext = parent; //set default group string currentPromotionGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Order).Key; //expressionPlace string realExpressionPlace = string.Empty; //Get current promotion target group from ExpressionPlace {promotionGroup : custom controls data } string[] expressionPlaceParts = expressionPlace.Split(':'); if (expressionPlaceParts.Length != 0) { currentPromotionGroup = expressionPlaceParts[0]; } if (expressionPlaceParts.Length > 1) { realExpressionPlace = expressionPlaceParts[1]; } IEnumerable <FilterExpressionNode> resultColl; _filterElementsMap.TryGetValue(currentPromotionGroup, out resultColl); //detected presents parent block type MethodBlock while (parentNext != null && parentMethodNode == null) { if (parentNext.NodeType == FilterExpressionNodeType.MethodBlock) { parentMethodNode = parentNext; } parentNext = parentNext.ParentNode; } if (parent == null || parentMethodNode == null) { if (resultColl != null) { //Add all registered element retVal.AddRange(resultColl); } } else { if (resultColl != null) { //Collections support FilterExpressionNode parentNode = FilterNodeFindRecursively(resultColl, x => x.Key == parentMethodNode.Key); IEnumerable <FilterExpressionNode> childEls = null; if (parentNode != null) { //gets all child element for current parrent node childEls = parentNode.ChildNodes; } //is call from custom cotrol for get elements for binding if (realExpressionPlace == "Sum") { ElementDefs parentElementDef = FindElementDef(parent.Key); ElementDefs methodDef = parentElementDef.GetMethodDef(parent.Method.Key); //For method SUM return only Decimal type elemnts if (methodDef == MethodSumDef) { var result = new List <FilterExpressionNode>(); foreach (FilterExpressionNode node in childEls) { ElementDefs nodeDef = FindElementDef(node.Key); if (nodeDef != null && nodeDef.Conditions == ConditionDecimalDefs) { result.Add(node); } } childEls = result; } else { childEls = new FilterExpressionNode[] { }; } } retVal.AddRange(childEls); } } // Sort retVal By Name retVal.Sort(delegate(FilterExpressionNode x, FilterExpressionNode y) { return(x.Name.CompareTo(y.Name)); }); return(new FilterExpressionNodeCollection(retVal.Select(x => x.Clone(true)).ToArray())); }
/// <summary> /// Converts the node to string expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected override string ConvertNodeToStringExpression(FilterExpressionNode node) { string retVal = string.Empty; if (node.NodeType == FilterExpressionNodeType.OrBlock) { return(ConvertNodesToStringExpression(node.ChildNodes, "||")); } if (node.NodeType == FilterExpressionNodeType.AndBlock) { return(ConvertNodesToStringExpression(node.ChildNodes, "&&")); } if (node != null && node.Key == FilterExpressionItem.chooseBlock) { return(retVal); } ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } //is Method Block if (elementDef.Methods != null) { //Get selected methods ElementDefs methodDef = elementDef.GetMethodDef(node.Method.Key); if (methodDef == null) { throw new ArgumentException("method " + node.Method.Key + " not registered"); } //Get methods conditions ElementDefs conditionDef = methodDef.GetConditionDefByName(node.Condition.Key); if (conditionDef == null) { throw new ArgumentException("condition " + node.Condition.Key + " not registered"); } string collectionName = elementDef.Name; string conditionOp = conditionDef.Name; MethodElementParams methodParams = node.Method.Params; string rightStatement = GetEscapedAndCleanedExpressionNodeRightValue(node); string predicateExpression = "1 == 1"; string leftStatement = null; if (node.ChildNodes != null && node.ChildNodes.Count != 0) { predicateExpression = ConvertNodesToStringExpression(node.ChildNodes); //Parser bug. Nested double quotes predicateExpression = predicateExpression.Replace('\"', '\''); } if (methodDef == MethodSumDef) { FilterExpressionNode filterNode = methodParams[0] as FilterExpressionNode; ElementDefs methodElementDef = FindElementDef(filterNode.Key); if (methodElementDef == null) { throw new ArgumentException("element method" + filterNode.Key + " not registered"); } leftStatement = methodElementDef.Name.Replace("this", string.Empty).Trim(new char[] { '[', ']', '\'', '.' }); retVal = String.Format(@"({0}.{1}({2},""{3}"",""{4}"")) {5} {6}", ContextClass, methodDef.Name, collectionName, leftStatement, predicateExpression, conditionOp, rightStatement); } else if (methodDef == MethodCountDef) { retVal = String.Format(@"{0}.{1}({2},""{3}"") {4} {5}", ContextClass, methodDef.Name, collectionName, predicateExpression, conditionOp, rightStatement); } else { retVal = String.Format(@"{0}.{1}({2},""{3}"")", ContextClass, methodDef.Name, collectionName, predicateExpression); } } else { //call base impl retVal = base.ConvertNodeToStringExpression(node); } return(retVal); }
protected override void RegisterProviderElementDefinitions() { //First call base implementation base.RegisterProviderElementDefinitions(); #region Condition definitions #endregion #region Method definitions AddressMethodDefs = new ElementDefs[] { base.MethodAllDef, base.MethodAnyDef }; RegisterDefinitions(AddressMethodDefs); #endregion #region element definitions AddressDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.AccountAddress_Name, Name = "this.Name", Descr = "Name", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_FirstName, Name = "this.FirstName", Descr = "FirstName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_LastName, Name = "this.LastName", Descr = "LastName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_Organization, Name = "this.Organization", Descr = "Organization", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_Line1, Name = "this.Line1", Descr = "Line1", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_Line2, Name = "this.Line2", Descr = "Line2", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_City, Name = "this.City", Descr = "City", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_State, Name = "this.State", Descr = "State", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_CountryCode, Name = "this.CountryCode", Descr = "CountryCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_CountryName, Name = "this.CountryName", Descr = "CountryName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_PostalCode, Name = "this.PostalCode", Descr = "PostalCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_RegionCode, Name = "this.RegionCode", Descr = "RegionCode", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_RegionName, Name = "this.RegionName", Descr = "RegionName", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_DaytimePhoneNumber, Name = "this.DaytimePhoneNumber", Descr = "DaytimePhoneNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_EveningPhoneNumber, Name = "this.EveningPhoneNumber", Descr = "EveningPhoneNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_FaxNumber, Name = "this.FaxNumber", Descr = "FaxNumber", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.AccountAddress_Email, Name = "this.Email", Descr = "Email", Conditions = ConditionTextDefs } }; RegisterDefinitions(AddressDefs); AccountDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Account_Addresses, Name = "this.CustomerAccount.Addresses.ToArray()", Descr = "Addresses", Methods = AddressMethodDefs, Childrens = AddressDefs }, new ElementDefs() { Key = ElementDefs.Account_CustomerGroup, Name = "this.CustomerAccount.CustomerGroup", Descr = "Customer Group", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.Account_Name, Name = "this.CustomerAccount.Name", Descr = "Name", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.Account_Description, Name = "this.CustomerAccount.Description", Descr = "Description", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.Account_Type, Name = "this.CustomerAccount.Type", Descr = "Type", Conditions = ConditionTextDefs }, new ElementDefs() { Key = ElementDefs.Account_State, Name = "this.CustomerAccount.State", Descr = "State", Conditions = ConditionIntegerDefs } }; RegisterDefinitions(AccountDefs); #endregion }
/// <summary> /// Registers the provider element definitions. /// </summary> protected override void RegisterProviderElementDefinitions() { //First call base implementation base.RegisterProviderElementDefinitions(); #region Condition definitions //Conditions not need const key registration in elementDef because is not used fore searching ConditionSkuSelectDefs = new ElementDefs() { Key = ElementDefs.Action_Condition_SkuSelect, Name = "of SKU", Descr = "of SKU" }; ConditionFreeShipingDefs = new ElementDefs() { Key = ElementDefs.Action_Condition_FreeShiping, Name = "", Descr = "" }; ConditionPercentDecimalDefs = new ElementDefs() { Key = ElementDefs.Action_Condition_PercentDecimal, Name = "reward", Descr = "reward" }; ConditionDecimalDefs = new ElementDefs() { Key = ElementDefs.Action_Condition_Decimal, Name = "reward", Descr = "reward" }; #endregion #region Method definitions MethodEachEntryDefs = new ElementDefs() { Key = ElementDefs.Method_Action_EachEntry, Name = "", Descr = "reward amount" }; MethodAllEntryDefs = new ElementDefs() { Key = ElementDefs.Method_Action_AllEntry, Name = "", Descr = "reward amount" }; MethodAllEntryPercentDefs = new ElementDefs() { Key = ElementDefs.Method_Action_AllEntryPercent, Name = "", Descr = "reward amount" }; MethodGiftDefs = new ElementDefs() { Key = ElementDefs.Method_Action_Gift, Name = "", Descr = "gift quantity" }; #endregion #region element definitions ActionsEntryDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Action_AllEntryValueOfItem, Name = PromotionRewardAmountType.Value + ":" + PromotionRewardType.AllAffectedEntries, Descr = "get $ off item", Conditions = new ElementDefs[] { ConditionDecimalDefs } }, new ElementDefs() { Key = ElementDefs.Action_AllEntryPercentOfItem, Name = PromotionRewardAmountType.Percentage + ":" + PromotionRewardType.AllAffectedEntries, Descr = "get % off item", Conditions = new ElementDefs[] { ConditionPercentDecimalDefs } } }; RegisterDefinitions(ActionsEntryDefs); ActionsOrderDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Action_WholeOrderValue, Name = PromotionRewardAmountType.Value + ":" + PromotionRewardType.WholeOrder, Descr = "get $ off whole order", Conditions = new ElementDefs[] { ConditionDecimalDefs } }, new ElementDefs() { Key = ElementDefs.Action_WholeOrderPercent, Name = PromotionRewardAmountType.Percentage + ":" + PromotionRewardType.WholeOrder, Descr = "get % off whole order", Conditions = new ElementDefs[] { ConditionPercentDecimalDefs } }, new ElementDefs() { Key = ElementDefs.Action_AllEntryValueOfSkuSet, Name = PromotionRewardAmountType.Value + ":" + PromotionRewardType.AllAffectedEntries, Descr = "get $ fixed", Methods = new ElementDefs[] { MethodAllEntryDefs }, Conditions = new ElementDefs[] { ConditionSkuSelectDefs } }, new ElementDefs() { Key = ElementDefs.Action_AllEntryPercentOfSkuSet, Name = PromotionRewardAmountType.Percentage + ":" + PromotionRewardType.AllAffectedEntries, Descr = "get % fixed", Methods = new ElementDefs[] { MethodAllEntryPercentDefs }, Conditions = new ElementDefs[] { ConditionSkuSelectDefs } }, new ElementDefs() { Key = ElementDefs.Action_EachEntryValueOfSkuSet, Name = PromotionRewardAmountType.Value + ":" + PromotionRewardType.EachAffectedEntry, Descr = "get $ per each item", Methods = new ElementDefs[] { MethodEachEntryDefs }, Conditions = new ElementDefs[] { ConditionSkuSelectDefs } }, new ElementDefs() { Key = ElementDefs.Action_GiftOfSkuSet, Name = "", Descr = "get gift items", Methods = new ElementDefs[] { MethodGiftDefs }, Conditions = new ElementDefs[] { ConditionSkuSelectDefs } } }; RegisterDefinitions(ActionsOrderDefs); #endregion }
/// <summary> /// Registers the provider element definitions. /// </summary> protected virtual void RegisterProviderElementDefinitions() { #region Condition definitions ConditionTextDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Condition_Text_Equals, Name = "Equals", Descr = "Equals (Text)" }, new ElementDefs() { Key = ElementDefs.Condition_Text_NotEquals, Name = "Not.Equals", Descr = "Does not equal (Text)" }, new ElementDefs() { Key = ElementDefs.Condition_Text_Contains, Name = "Contains", Descr = "Contains" }, new ElementDefs() { Key = ElementDefs.Condition_Text_NotContains, Name = "Not.Contains", Descr = "Does not contain" }, new ElementDefs() { Key = ElementDefs.Condition_Text_StartsWith, Name = "StartsWith", Descr = "Begins with" }, new ElementDefs() { Key = ElementDefs.Condition_Text_EndsWith, Name = "EndsWith", Descr = "Ends with" } }.Select(x => { x.ConverstionPattern = "{0}.ToString()"; return(x); }); RegisterDefinitions(ConditionTextDefs); ConditionDecimalDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Condition_Decimal_Equals, Name = "==", Descr = "Equals" }, new ElementDefs() { Key = ElementDefs.Condition_Decimal_NotEquals, Name = "!=", Descr = "Not equal" }, new ElementDefs() { Key = ElementDefs.Condition_Decimal_Less, Name = "<", Descr = "Less than" }, new ElementDefs() { Key = ElementDefs.Condition_Decimal_Greater, Name = ">", Descr = "Greater than" } }.Select(x => { x.ConverstionPattern = "((decimal){0})"; return(x); }); RegisterDefinitions(ConditionDecimalDefs); ConditionIntegerDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Condition_Int_Equals, Name = "==", Descr = "Equals" }, new ElementDefs() { Key = ElementDefs.Condition_Int_NotEquals, Name = "!=", Descr = "Not equal" }, new ElementDefs() { Key = ElementDefs.Condition_Int_Less, Name = "<", Descr = "Less than" }, new ElementDefs() { Key = ElementDefs.Condition_Int_Greater, Name = ">", Descr = "Greater than" } }.Select(x => { x.ConverstionPattern = "((int){0})"; return(x); }); RegisterDefinitions(ConditionIntegerDefs); ConditionBoolDefs = new ElementDefs[] { new ElementDefs() { Key = ElementDefs.Condition_Bool_Equals, Name = "==", Descr = "Equals" } }.Select(x => { x.ConverstionPattern = "((bool){0})"; return(x); }); RegisterDefinitions(ConditionBoolDefs); #endregion //Register available conditions for McDataType types //Integer var metaDataTypes = new MetaDataType[] { MetaDataType.BigInt, MetaDataType.Int, MetaDataType.Integer, MetaDataType.SmallInt, MetaDataType.Timestamp }; foreach (MetaDataType metaDataType in metaDataTypes) { MetaDataType2ElDefMap.Add(metaDataType, ConditionIntegerDefs); } //Decimal metaDataTypes = new MetaDataType[] { MetaDataType.Decimal, MetaDataType.Money, MetaDataType.Numeric, MetaDataType.SmallMoney, MetaDataType.Float, MetaDataType.Real }; foreach (MetaDataType metaDataType in metaDataTypes) { MetaDataType2ElDefMap.Add(metaDataType, ConditionDecimalDefs); } //Text metaDataTypes = new MetaDataType[] { MetaDataType.LongHtmlString, MetaDataType.LongString, MetaDataType.NChar, MetaDataType.NText, MetaDataType.NVarChar, MetaDataType.ShortString, MetaDataType.Text, MetaDataType.URL, MetaDataType.VarChar }; foreach (MetaDataType metaDataType in metaDataTypes) { MetaDataType2ElDefMap.Add(metaDataType, ConditionTextDefs); } //Boolean metaDataTypes = new MetaDataType[] { MetaDataType.Bit, MetaDataType.Boolean, MetaDataType.MetaObject }; foreach (MetaDataType metaDataType in metaDataTypes) { MetaDataType2ElDefMap.Add(metaDataType, ConditionBoolDefs); } //TODO: Not suppoerted types // MetaDataType.UniqueIdentifier // MetaDataType.Date, MetaDataType.SmallDateTime, , MetaDataType.DateTime }
/// <summary> /// Converts the node to string expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected override string ConvertNodeToStringExpression(FilterExpressionNode node) { string expression = String.Empty; decimal quantity = 0; decimal rewardAmount = 0; var skuList = new string[] { }; MethodElementParams methodParams = null; //Find registered element definition by key ElementDefs elementDef = FindElementDef(node.Key); if (elementDef == null) { throw new ArgumentException("element " + node.Key + " not registered"); } if (elementDef.Methods != null) { skuList = node.Value != null ? ((Dictionary <string, string>)node.Value).Keys.ToArray() : skuList; skuList = EntryId2LineItemCode(skuList).ToArray(); methodParams = node.Method.Params; } else { rewardAmount = Convert.ToDecimal(node.Value); } //Find registered method definition by key ElementDefs methodDef = null; if (elementDef.Methods != null) { methodDef = elementDef.GetMethodDef(node.Method.Key); } string[] namePart = elementDef.Name.Split(':'); string rewardAmountType = PromotionRewardAmountType.Value; string rewardType = PromotionRewardType.WholeOrder; if (namePart.Count() == 2) { rewardAmountType = namePart[0]; rewardType = namePart[1]; } //gift if (methodDef == MethodGiftDefs) { if (skuList.Count() != 0) { quantity = Convert.ToDecimal(methodParams[0]); var skuPattern = skuList.Select(x => String.Format("\"{0}\"", x)); expression = String.Format("this.AddFreeGiftToCart(\"{0}\", {1})", quantity.ToString(CultureInfo.InvariantCulture), String.Join(",", skuPattern.ToArray())); } } //with quantity, amount, sku list else if (methodDef == MethodEachEntryDefs) { quantity = Convert.ToDecimal(methodParams[1]); rewardAmount = Convert.ToDecimal(methodParams[0]); if (skuList.Count() != 0) { var entryPattern = "this.CreatePromotionEntriesSetFromTarget(\"{0}\", {1})"; expression = String.Format("AddPromotionItemRecord(this.CreatePromotionReward(\"{0}\", \"{1}\", \"{2}\"), {3})", rewardType, rewardAmount.ToString(CultureInfo.InvariantCulture), rewardAmountType, String.Join(",", skuList.Select(x => String.Format(entryPattern, x, quantity)).ToArray())); } } //with amount, sku list else if (methodDef == MethodAllEntryDefs || methodDef == MethodAllEntryPercentDefs) { rewardAmount = Convert.ToDecimal(methodParams[0]); if (skuList.Count() != 0) { var entryPattern = "this.CreatePromotionEntriesSetFromTarget(\"{0}\")"; expression = String.Format("AddPromotionItemRecord(this.CreatePromotionReward(\"{0}\", \"{1}\", \"{2}\"), {3})", rewardType, rewardAmount.ToString(CultureInfo.InvariantCulture), rewardAmountType, String.Join(",", skuList.Select(x => String.Format(entryPattern, x)).ToArray())); } } // only amount else { var pattern = "this.AddPromotionItemRecord(this.CreatePromotionReward(\"{0}\", \"{1}\", \"{2}\")," + "this.PromotionContext.TargetEntriesSet)"; expression = String.Format(pattern, rewardType, rewardAmount.ToString(CultureInfo.InvariantCulture), rewardAmountType); } return(expression); }