/// <summary> /// Converts the expression to node. /// </summary> /// <param name="expr">The expr.</param> /// <returns></returns> protected virtual FilterExpressionNode ConvertExpressionToNode(CodeMethodInvokeExpression expr) { CodeExpression target = expr.Method.TargetObject; FilterExpressionNode node = null; string targetString = ConvertTargetToString(expr.Method.TargetObject); if (target is CodeMethodInvokeExpression) { // This is a safier alternative to doing direct propery call (we always assume call is made using the // method, for example this.GetPropertyValueSafe("ParameterName") and extract the first parameter) node = new FilterExpressionNode(String.Format("{0}(\"{1}\")", targetString, ExtractPropertyFromTarget(target))); } else { // This is a method that can be used to call property directly, for example this.Customer.Email, // but you need to make sure the Customer object and Email are not null. node = new FilterExpressionNode(ConvertTargetToString(target)); } node.Name = String.Empty; node.Condition = new ConditionElement(ConditionElementType.Text, expr.Method.MethodName); if (expr.Parameters[0] is CodePrimitiveExpression) { node.Value = ((CodePrimitiveExpression)expr.Parameters[0]).Value; } return(node); //CodePropertyReferenceExpression }
public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node, ConditionElement condition) { string controlId = node["TmpKey"]; if (controlId == null) { controlId = Guid.NewGuid().ToString(); node["TmpKey"] = controlId; } ControlId = controlId; Dictionary <string, string> dicItems = Value as Dictionary <string, string>; if (dicItems != null && dicItems.Count > 0) { StringBuilder sb = new StringBuilder(); sb.Append(dicItems.ElementAt(0).Value); if (dicItems.Count > 1) { sb.Append("+ (" + (dicItems.Count - 1).ToString() + ")"); } lbSelectedEntries.Text = sb.ToString(); } else { lbSelectedEntries.Text = "Please select catalog entries"; } }
/// <summary> /// Filters the node find recursively. /// </summary> /// <param name="nodeCollection">The node collection.</param> /// <param name="predicate">The predicate.</param> /// <returns></returns> public static FilterExpressionNode FilterNodeFindRecursively(IEnumerable <FilterExpressionNode> nodeCollection, Func <FilterExpressionNode, bool> predicate) { FilterExpressionNode retVal = null; if (nodeCollection == null) { throw new ArgumentNullException("nodeCollection"); } foreach (FilterExpressionNode node in nodeCollection) { if (node.ChildNodes != null) { retVal = FilterNodeFindRecursively(node.ChildNodes, predicate); if (retVal != null) { break; } } if (predicate(node)) { retVal = node; break; } } return(retVal); }
/// <summary> /// Converts the node to block. /// </summary> /// <param name="leftNode">The left node.</param> /// <param name="rightNode">The right node.</param> /// <returns></returns> protected virtual CodeBinaryOperatorExpression ConvertNodeToBlock(FilterExpressionNode leftNode, FilterExpressionNode rightNode) { CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(); condition.Left = ConvertNodeToExpression(leftNode); condition.Operator = CodeBinaryOperatorType.BooleanAnd; condition.Right = ConvertNodeToExpression(rightNode); return(condition); }
/// <summary> /// Binds the data. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="expressionKey">The expression key.</param> /// <param name="node">The node.</param> /// <param name="condition">The condition.</param> public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node, ConditionElement condition) { if (node.Attributes == null) BindFromValue(string.Empty); else if (node.Attributes["ReferenceToMetaClassName"] != null) BindFromValue(node.Attributes["ReferenceToMetaClassName"]); else throw new ArgumentNullException("ReferenceToMetaClassName"); }
/// <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); }
public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node, ConditionElement condition) { MetaField mf = Mediachase.Ibn.Core.MetaDataWrapper.GetMetaFieldByName(Mediachase.Ibn.Core.MetaViewGroupUtil.GetIdFromUniqueKey(expressionPlace), node.Key.Split('-')[0]); if (mf.Attributes[McDataTypeAttribute.DecimalPrecision] != null && mf.Attributes[McDataTypeAttribute.DecimalScale] != null) { this.Scale = Convert.ToInt32(mf.Attributes[McDataTypeAttribute.DecimalScale].ToString(), CultureInfo.InvariantCulture); this.Precision = Convert.ToInt32(mf.Attributes[McDataTypeAttribute.DecimalPrecision].ToString(), CultureInfo.InvariantCulture); } BindFromValue(); }
/// <summary> /// Gets the new elements. /// </summary> /// <param name="collection">The collection.</param> /// <param name="metaClass">The meta class.</param> /// <param name="keyPrefix">The key prefix.</param> /// <param name="namePrefix">The name prefix.</param> protected virtual void GetNewElements(List <FilterExpressionNode> collection, MetaClass metaClass, string keyPrefix, string namePrefix) { foreach (MetaField field in metaClass.MetaFields) { string key = String.Format("{0}(\"{1}\")", keyPrefix, field.Name); FilterExpressionNode node = new FilterExpressionNode(key, namePrefix + field.FriendlyName); collection.Add(node); } }
/// <summary> /// Gets the escaped and cleaned expression node right value. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> public static string GetEscapedAndCleanedExpressionNodeRightValue(FilterExpressionNode node) { string retVal = string.Empty; if (node != null && node.Value != null) { retVal = node.Value.ToString(); if (retVal.Contains("\"")) { throw new ArgumentException("Invalid char in node value"); } } 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> /// Binds the data. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="expressionKey">The expression key.</param> /// <param name="node">The node.</param> /// <param name="condition">The condition.</param> public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node, ConditionElement condition) { if (node.Attributes == null) { BindFromValue(string.Empty); } else if (node.Attributes["ReferenceToMetaClassName"] != null) { BindFromValue(node.Attributes["ReferenceToMetaClassName"]); } else { throw new ArgumentNullException("ReferenceToMetaClassName"); } }
/// <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); }
public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node) { string[] parts = expressionPlace.Split(':'); //Change orig place if (parts.Length > 1) { parts[1] = "Sum"; } else { parts = new string[] { parts[0], "Sum" }; } FieldsList.DataSource = ((FilterExpressionFunctionParams)this.Parent).ControlContainer.Provider.GetNewElements(String.Join(":", parts), node); FieldsList.Visible = ((FilterExpressionNodeCollection)FieldsList.DataSource).Count != 0; FieldsList.DataTextField = "Name"; FieldsList.DataValueField = "Key"; FieldsList.DataBind(); //this.CurrentNode = node; }
/// <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); }
/// <summary> /// Converts the node to expression. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> protected virtual CodeBinaryOperatorExpression ConvertNodeToExpression(FilterExpressionNode node) { CodeBinaryOperatorExpression expression = null; if (node.NodeType == FilterExpressionNodeType.Element) { CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression(); CodeFieldReferenceExpression leftExprRef = new CodeFieldReferenceExpression(thisRef, node.Key); expression = new CodeBinaryOperatorExpression(); expression.Left = leftExprRef; expression.Operator = (CodeBinaryOperatorType)Enum.Parse(typeof(CodeBinaryOperatorType), node.Condition.Key, true); expression.Right = new CodePrimitiveExpression(node.Value); } else { throw new ApplicationException("Invalid NodeType"); } return(expression); }
/// <summary> /// Applies the filter. /// </summary> public override void StartFilter() { if (null == this.FilterTarget) { throw new InvalidOperationException("FilterTarget is null."); } // Cache the expression for filtering so subsequent changes are ignored \\ this.CachedFilterExpression = this.FilterExpression; if (null != this.CachedFilterExpression) { this.FilterTarget.Items.Filter = this.FilterExpressionAdapter; this.FilterStatus = FilterStatus.Applied; } else { this.StopFilter(); } }
/// <summary> /// Adds the expression as node. /// </summary> /// <param name="col">The col.</param> /// <param name="expr">The expr.</param> protected virtual void AddExpressionAsNode(ref FilterExpressionNodeCollection col, CodeBinaryOperatorExpression expr) { if (expr.Left is CodeMethodInvokeExpression) { col.Add(ConvertExpressionToNode((CodeMethodInvokeExpression)expr.Left)); } else if (expr.Left is CodeBinaryOperatorExpression) { AddExpressionAsNode(ref col, expr.Left); } // Only need an operator if right is an expression FilterExpressionNode blockNode = null; if (expr.Right is CodeBinaryOperatorExpression) { if (expr.Operator == CodeBinaryOperatorType.BooleanAnd) { blockNode = new FilterExpressionNode(FilterExpressionNodeType.AndBlock, String.Empty); } else if (expr.Operator == CodeBinaryOperatorType.BooleanOr) { blockNode = new FilterExpressionNode(FilterExpressionNodeType.OrBlock, String.Empty); } col.Add(blockNode); FilterExpressionNodeCollection blockCol = new FilterExpressionNodeCollection(); AddExpressionAsNode(ref blockCol, expr.Right); blockNode.ChildNodes = blockCol; } if (expr.Right is CodeMethodInvokeExpression) { col.Add(ConvertExpressionToNode((CodeMethodInvokeExpression)expr.Right)); } }
private static string ConvertNodeToStringExpression(FilterExpressionNode node) { string expression = String.Empty; if (node.NodeType == FilterExpressionNodeType.Element) { // Detect "NOT" statement string key = node.Condition.Key; bool isNegative = false; if (key.StartsWith("Not.")) { key = key.Substring(key.IndexOf(".") + 1); } if (node.Condition.Type == ConditionElementType.Text) { expression = String.Format("{0}{1}.{2}(\"{3}\")", isNegative ? "!" : String.Empty, node.Key, key, node.Value); } else if (node.Condition.Type == ConditionElementType.NotSet) { } else { expression = String.Format("{0}{1}.{2}({3})", isNegative ? "!" : String.Empty, node.Key, key, node.Value); } // Add a series of not null } else { throw new ApplicationException("Invalid NodeType"); } return(expression); }
/// <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> /// 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(); foreach (ElementDefs methodDef in AddressMethodDefs) { retVal.Add(methodDef.Tag as MethodElement); } 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 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) { return(null); }
/// <summary> /// Gets the new elements. /// </summary> /// <param name="expressionPlace">The expression place.</param> /// <param name="parent">The parent.</param> /// <returns></returns> public override FilterExpressionNodeCollection GetNewElements(string expressionPlace, FilterExpressionNode parent) { return(null); }
/// <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) { return(null); }
/// <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> /// 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) { FilterExpressionNodeCollection retVal = new FilterExpressionNodeCollection(); //set default group string currentPromotionGroup = PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Order).Key; string[] expressionPlaceParts = expressionPlace.Split(':'); if (expressionPlaceParts.Length != 0) { currentPromotionGroup = expressionPlaceParts[0]; } IEnumerable <FilterExpressionNode> resultColl; _filterElementsMap.TryGetValue(currentPromotionGroup, out resultColl); if (resultColl != null) { retVal.AddRange(resultColl.Select(x => x.Clone()).ToArray()); } return(retVal); }
/// <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); }
/// <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); }
public void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node, ConditionElement condition) { BindFromValue(); }
/// <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 void BindData(string expressionPlace, string expressionKey, FilterExpressionNode node) { BindFromValue(); }