/// <summary> Checks if one object is the instance of another /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">An IDictionary Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns>True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { try { if ((aObj == null) || (aCompareTo == null)) { return(false); } else if ((aObj.GetType().IsInstanceOfType(aCompareTo)) || (aObj.GetType().IsSubclassOf(aCompareTo.GetType()))) { return(true); } else { return(false); } } catch (System.Exception e) { if (Logger.IsFlowEngineWarning) { Logger.FlowEngineSource.TraceEvent(TraceEventType.Warning, 0, "InstanceOf can not execute comparison with context: " + aBRC + "\n parameters: " + Misc.IDictionaryToString(aMap) + "\n first object: " + aObj + "\n second object: " + aCompareTo + "\n stacktrace: " + e.StackTrace); } } return(false); }
public object ContextfullDelegate(IBRERuleContext aBrc, IDictionary aMap, object aStep) { object myParam = aMap["myParam"]; return(((Int32)aBrc.GetObject("5i")) * ((myParam is Int32)?(Int32)myParam:Int32.Parse((string)myParam))); }
/// <summary> If passed the parameter Increment it will increment the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the increment /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { if (aMap.ContainsKey(INCREMENT)) sIdx = sIdx + Int32.Parse((string) aMap[INCREMENT]); return sIdx; }
public object ContextfullDelegate(IBRERuleContext aBrc, Hashtable aMap, object aStep) { object myParam = aMap["myParam"]; return ((Int32)aBrc.GetObject("5i")) * ((myParam is Int32)?(Int32)myParam:Int32.Parse((string)myParam)); }
/// <summary> Checks if one object is the instance of another /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">An IDictionary Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns>True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { try { if ((aObj == null) || (aCompareTo == null)) { return false; } else if ((aObj.GetType().IsInstanceOfType(aCompareTo)) || (aObj.GetType().IsSubclassOf(aCompareTo.GetType()))) { return true; } else { return false; } } catch(System.Exception e) { if (Logger.IsFlowEngineWarning) Logger.FlowEngineSource.TraceEvent(TraceEventType.Warning, 0, "InstanceOf can not execute comparison with context: " + aBRC + "\n parameters: " + Misc.IDictionaryToString(aMap) + "\n first object: " + aObj + "\n second object: " + aCompareTo + "\n stacktrace: " + e.StackTrace); } return false; }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { bool staticCall = false; if (!aMap.ContainsKey(OBJECTID)) { if (!aMap.ContainsKey(TYPE)) { throw new BRERuleException("Parameter 'Type' or 'ObjectId' not found"); } else { staticCall = true; } } if (!aMap.ContainsKey(MEMBER)) { throw new BRERuleException("Parameter 'Member' not found"); } else { if (staticCall) { return(Reflection.ClassCall((string)aMap[TYPE], (string)aMap[MEMBER], GetArguments(aMap))); } else { return(Reflection.ObjectCall(aBrc.GetResult(aMap[OBJECTID]).Result, (string)aMap[MEMBER], GetArguments(aMap))); } } }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { bool staticCall = false; if (!aMap.ContainsKey(OBJECTID)) { if (!aMap.ContainsKey(TYPE)) throw new BRERuleException("Parameter 'Type' or 'ObjectId' not found"); else staticCall = true; } if (!aMap.ContainsKey(MEMBER)) { throw new BRERuleException("Parameter 'Member' not found"); } else { if (staticCall) return Reflection.ClassCall((string)aMap[TYPE], (string)aMap[MEMBER], GetArguments(aMap)); else return Reflection.ObjectCall(aBrc.GetResult(aMap[OBJECTID]).Result, (string)aMap[MEMBER], GetArguments(aMap)); } }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext ruleContext, IDictionary arguments, object step) { var staticCall = false; if (!arguments.Contains(OBJECTID)) { if (!arguments.Contains(TYPE)) { throw new BRERuleException("Parameter 'Type' or 'ObjectId' not found"); } staticCall = true; } if (!arguments.Contains(MEMBER)) { throw new BRERuleException("Parameter 'Member' not found"); } if (staticCall) { return(Reflection.ClassCall((string)arguments[TYPE], (string)arguments[MEMBER], GetArguments(arguments))); } return(Reflection.ObjectCall(ruleContext.GetResult(arguments[OBJECTID]).Result, (string)arguments[MEMBER], GetArguments(arguments))); }
/// <summary> If passed the parameter Increment it will increment the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the increment /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (aMap.Contains(INCREMENT)) sIdx = sIdx + Int32.Parse((string) aMap[INCREMENT]); return sIdx; }
/// <summary> If passed the parameter Decrement it will decrement the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the index /// /// </returns> public virtual object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (aMap.Contains(DECREMENT)) { sIdx = sIdx - System.Int32.Parse((System.String)aMap[DECREMENT]); } return(sIdx); }
/// <summary> If passed the parameter Decrement it will decrement the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the index /// /// </returns> public virtual object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (aMap.Contains(DECREMENT)) { sIdx = sIdx - System.Int32.Parse((System.String) aMap[DECREMENT]); } return sIdx; }
public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj == null) || (aCompareTo == null)) { return false; } else { return ((string)aObj).Contains((string)aCompareTo); } }
/// <summary> If passed the parameter Increment it will increment the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the increment /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { if (aMap.ContainsKey(INCREMENT)) { sIdx = sIdx + Int32.Parse((string)aMap[INCREMENT]); } return(sIdx); }
/// <summary> If passed the parameter Increment it will increment the index. /// Otherwise it will just return the current value of the index /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the increment /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (aMap.Contains(INCREMENT)) { sIdx = sIdx + int.Parse((string)aMap[INCREMENT]); } return(sIdx); }
/// <summary> Initializes the object.<P> /// The default constructor exists so that objects may register /// as listeners before any action takes place. /// </P> /// </summary> /// <param name="aObj">The XML configuration document /// (either System.Xml.XPath.XPathDocument or string poiting to a XML file /// </param> /// <returns> True if successful, False otherwise /// /// </returns> public bool Init(object aObj) { if (running) { DispatchException("BRE already running: a violent Stop will be tried!", LogEventImpl.ERROR); Stop(); } else { DispatchLog("BRE Starting...", LogEventImpl.INFO); } if (aObj == null) { DispatchException("Business Rules provided by external entity\nObject passed to init() must not be Null", LogEventImpl.FATAL); return(false); } if (aObj is IRulesDriver) { rulesDriver = (IRulesDriver)aObj; rulesDriver.LogDispatcher = this; xmlDocument = null; } else if (aObj is XPathDocument) { xmlDocument = (XPathDocument)aObj; } else { DispatchException("Business Rules provided by external entity\nObject passed to init() must be of type System.Xml.XPath.XPathDocument or org.nxbre.ri.drivers.IRulesDriver and not " + aObj.GetType(), LogEventImpl.FATAL); return(false); } DispatchLog("BRE Initializing...", LogEventImpl.INFO); if (ruleContext == null) { ruleContext = new BRERuleContextImpl(new Stack(), new Hashtable(), new Hashtable(), new Hashtable()); } // pre-load all operators foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) { if (null != type.GetInterface(typeof(IBREOperator).FullName, false)) { GetOperator(type.FullName); } } // pre-load factories initialized = LoadFactories(GetXmlDocumentRules().Select("//" + RULE + "[@" + RULE_ATTRS.FACTORY + "]")); return(initialized); }
public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj == null) || (aCompareTo == null)) { return(false); } else { return(((string)aObj).Contains((string)aCompareTo)); } }
public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj == null) || (aCompareTo == null)) { return true; } else if ((aObj is IComparable) && (aCompareTo is IComparable)) { return ((IComparable) aObj).CompareTo(aCompareTo) != 0; } else { return !aCompareTo.Equals(aObj); } }
public object AddRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { var basket = aBrc.GetObject("currentBasket") as Basket; var ruleName = (string)Reflection.CastValue(aMap["ruleName"], typeof(string)); if (!string.IsNullOrEmpty(ruleName)) { basket.DiscountList.Add(ruleName); } return(basket); }
public object SetShop(IBRERuleContext aBrc, IDictionary aMap, object aStep) { var shop = aBrc.GetObject("CurrentShop") as Shop; var vkorg = (string)Reflection.CastValue(aMap["vKorg"], typeof(string)); if (shop == null) { return(null); } shop.VKorg = vkorg; return(shop); }
/// <summary> Throws a BRERuleException with the message "Test Exception" /// unless the parameter Message provides a specific message. /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns>The Exception</returns> public virtual object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { string message = (string)aMap[MESSAGE]; BRERuleException breRuleException; if (message == null) breRuleException = new BRERuleException(); else breRuleException = new BRERuleException(message); if (Logger.IsFlowEngineRuleBaseError) Logger.FlowEngineRuleBaseSource.TraceData(TraceEventType.Error, 0, breRuleException); return breRuleException; }
/// <summary> Throws a BRERuleFatalException with the message "Test Fatal Exception" /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> Nothing. It throws an exception each time /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { string message = (string)aMap[MESSAGE]; if (message == null) { throw new BRERuleFatalException("Test Fatal Exception"); } else { throw new BRERuleFatalException(message); } }
/// <summary> Throws a BRERuleFatalException with the message "Test Fatal Exception" /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns>The exception</returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { var message = (string)aMap[MESSAGE]; var breRuleFatalException = message == null ? new BRERuleFatalException() : new BRERuleFatalException(message); if (Logger.IsFlowEngineRuleBaseCritical) { Logger.FlowEngineRuleBaseSource.TraceData(TraceEventType.Critical, 0, breRuleFatalException); } return(breRuleFatalException); }
/// <summary> Checks if one object is the instance of another /// * /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used. A Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns>True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, Hashtable aMap, object aObj, object aCompareTo) { try { if ((aObj.GetType().IsInstanceOfType(aCompareTo)) || (aObj.GetType().IsSubclassOf(aCompareTo.GetType()))) return true; else return false; } catch(Exception) {} return false; }
public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj == null) || (aCompareTo == null)) { return(true); } var obj = aObj as IComparable; if ((obj != null) && (aCompareTo is IComparable)) { return(obj.CompareTo(aCompareTo) != 0); } return(!aCompareTo.Equals(aObj)); }
/// <summary> Checks the two objects to see if they are equal /// * /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. A Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns> True if they meet the condition, False otherwise. /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, Hashtable aMap, object aObj, object aCompareTo) { if ((aObj is IComparable) && (aCompareTo is IComparable)) { if (((IComparable)aObj).CompareTo(aCompareTo) == 0) { return(true); } return(false); } else { return(aCompareTo.Equals(aObj)); } }
/// <summary> Checks the two objects to see if they are equal /// </summary> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj == null) || (aCompareTo == null)) { return(false); } else if ((aObj is IComparable) && (aCompareTo is IComparable)) { return(((IComparable)aObj).CompareTo(aCompareTo) == 0); } else { return(aCompareTo.Equals(aObj)); } }
public bool ExecuteComparison(IBRERuleContext ruleContext, IDictionary arguments, object left, object right) { if ((left == null) || (right == null)) { return defaultValue; } else if ((left is IComparable) && (right is IComparable)) { if ((! right.GetType().IsInstanceOfType(left)) || (! right.GetType().IsSubclassOf(left.GetType()))) { right = Convert.ChangeType(right, left.GetType()); } return AnalyzeCompared(((IComparable) left).CompareTo(right)); } else { return defaultValue; } }
/// <summary> Checks the two objects to see if they are equal /// * /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. An IDictionary object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns> True if they meet the condition, False otherwise. /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { if ((aObj is IComparable) && (aCompareTo is IComparable)) { if (((IComparable) aObj).CompareTo(aCompareTo) == 0) { return true; } return false; } else { return aCompareTo.Equals(aObj); } }
/// <summary> Checks the two objects to see if one is greater than the other /// <P> /// If the objects are not <code>Comparable</code> then we default /// to the optimism that is set. The default is false. /// * /// </P> /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">An IDictionary object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns> True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object aObj, object aCompareTo) { Init(aMap); if ((aObj is IComparable) && (aCompareTo is IComparable)) { if (((IComparable)aObj).CompareTo(aCompareTo) > 0) { return(true); } return(false); } else { return(optimistic); } }
public object ForEachTester(IBRERuleContext aBrc, IDictionary aMap, object aStep) { int contextValue = (Int32)aBrc.GetObject("ForEachParser"); if (contextValue != ARRAY[forEachProbe]) { forEachError = "ForEachTester mismatch @" + forEachProbe + ": " + contextValue + " != " + ARRAY[forEachProbe]; } forEachProbe++; // we do not care about the returned value in the rules return(null); }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { if (!aMap.ContainsKey(TYPE)) { throw new BRERuleException("Parameter 'Type' not found"); } else { if (!aMap.ContainsKey(VALUE)) { ObjectLookup ol = new ObjectLookup(); object[] arguments = ol.GetArguments(aMap); return(Reflection.ClassNew((string)aMap[TYPE], arguments)); } return(Reflection.CastValue(aMap[VALUE], (string)aMap[TYPE])); } }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { if (!aMap.ContainsKey(TYPE)) { throw new BRERuleException("Parameter 'Type' not found"); } else { if (!aMap.ContainsKey(VALUE)) { ObjectLookup ol = new ObjectLookup(); object[] arguments = ol.GetArguments(aMap); return Reflection.ClassNew((string)aMap[TYPE], arguments); } return Reflection.CastValue(aMap[VALUE], (string)aMap[TYPE]); } }
/// <summary> Checks if one object is the instance of another /// * /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used. A Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns>True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, Hashtable aMap, object aObj, object aCompareTo) { try { if ((aObj.GetType().IsInstanceOfType(aCompareTo)) || (aObj.GetType().IsSubclassOf(aCompareTo.GetType()))) { return(true); } else { return(false); } } catch (Exception) {} return(false); }
/// <summary> Checks the two objects to see if one is greater than the other /// <P> /// If the objects are not <code>Comparable</code> then we default /// to the optimism that is set. The default is false. /// * /// </P> /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. A Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns> True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, Hashtable aMap, object aObj, object aCompareTo) { Init(aMap); if ((aObj is IComparable) && (aCompareTo is IComparable)) { if (((IComparable) aObj).CompareTo(aCompareTo) > 0) { return true; } return false; } else { return optimistic; } }
/// <summary> Check if object matches a regexp pattern /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. An IDictionary object containing the parameters from the XML /// </param> /// <param name="compareTo">The object to compare it to. /// </param> /// <param name="regexPattern">The regexp pattern to match against. /// </param> /// <returns> True if they meet the condition, False otherwise. /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object compareTo, object regexPatternObject) { if ((regexPatternObject == null) || (compareTo == null)) { return false; } else { lock(regexCache) { Regex regex; string regexPattern = regexPatternObject.ToString(); if (!regexCache.TryGetValue(regexPattern, out regex)) { regex = new Regex(regexPattern); regexCache.Add(regexPattern, regex); } return regex.IsMatch(compareTo.ToString()); } } }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (!aMap.Contains(TYPE)) { throw new BRERuleException("Parameter 'Type' not found"); } else { var type = (string)aMap[TYPE]; if (aMap.Contains(VALUE)) { return(Reflection.CastValue(aMap[VALUE], type)); } var ol = new ObjectLookup(); var arguments = ol.GetArguments(aMap); return(CreateValue(type, arguments)); } }
public bool ExecuteComparison(IBRERuleContext ruleContext, IDictionary arguments, object left, object right) { if ((left == null) || (right == null)) { return(defaultValue); } var comparable = left as IComparable; if ((comparable == null) || (!(right is IComparable))) { return(defaultValue); } if ((!right.GetType().IsInstanceOfType(comparable)) || (!right.GetType().IsSubclassOf(comparable.GetType()))) { right = Convert.ChangeType(right, comparable.GetType()); } return(AnalyzeCompared(comparable.CompareTo(right))); }
/// <summary> Checks the two objects to see if they are not equal /// * /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. A Map object containing the parameters from the XML /// </param> /// <param name="aObj">The object (value) to compare against. /// </param> /// <param name="aCompareTo">The object to compare it to. /// </param> /// <returns>s True if they meet the condition, False otherwise. /// /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, Hashtable aMap, object aObj, object aCompareTo) { if ((aObj is IComparable) && (aCompareTo is IComparable)) { if (((IComparable) aObj).CompareTo(aCompareTo) != 0) { return true; } return false; } else { if (!aCompareTo.Equals(aObj)) { return true; } return false; } }
public bool ExecuteComparison(IBRERuleContext ruleContext, IDictionary arguments, object left, object right) { if ((left == null) || (right == null)) { return(defaultValue); } else if ((left is IComparable) && (right is IComparable)) { if ((!right.GetType().IsInstanceOfType(left)) || (!right.GetType().IsSubclassOf(left.GetType()))) { right = Convert.ChangeType(right, left.GetType()); } return(AnalyzeCompared(((IComparable)left).CompareTo(right))); } else { return(defaultValue); } }
/// <summary> If passed the parameter Id and Init it call the Init method of /// the Increment /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the index /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (!aMap.Contains(ID)) { throw new BRERuleException("Parameter 'Id' not found"); } if (!aMap.Contains(INIT)) { throw new BRERuleException("Parameter 'Init' not found"); } if (aBrc.FactoryMap.Contains(aMap[ID])) { ((IInitializable)aBrc.GetFactory(aMap[ID])).Init(aMap[INIT]); } else { throw new BRERuleException("Increment '" + aMap[ID] + "' not found"); } return(null); }
/// <summary> Returns a value cast to a specific type /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The value cast to the specified type /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (!aMap.Contains(TYPE)) { throw new BRERuleException("Parameter 'Type' not found"); } else { string type = (string)aMap[TYPE]; if (!aMap.Contains(VALUE)) { ObjectLookup ol = new ObjectLookup(); object[] arguments = ol.GetArguments(aMap); return CreateValue(type, arguments); } return Reflection.CastValue(aMap[VALUE], type); } }
/// <summary> Throws a BRERuleException with the message "Test Exception" /// unless the parameter Message provides a specific message. /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns>The Exception</returns> public virtual object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { string message = (string)aMap[MESSAGE]; BRERuleException breRuleException; if (message == null) { breRuleException = new BRERuleException(); } else { breRuleException = new BRERuleException(message); } if (Logger.IsFlowEngineRuleBaseError) { Logger.FlowEngineRuleBaseSource.TraceData(TraceEventType.Error, 0, breRuleException); } return(breRuleException); }
/// <summary> Check if object matches a regexp pattern /// </summary> /// <param name="aBRC">The BRERuleContext object containing all the state /// information for use by this method. /// </param> /// <param name="aMap">Not used yet. An IDictionary object containing the parameters from the XML /// </param> /// <param name="compareTo">The object to compare it to. /// </param> /// <param name="regexPattern">The regexp pattern to match against. /// </param> /// <returns> True if they meet the condition, False otherwise. /// </returns> public bool ExecuteComparison(IBRERuleContext aBRC, IDictionary aMap, object compareTo, object regexPatternObject) { if ((regexPatternObject == null) || (compareTo == null)) { return(false); } else { lock (regexCache) { Regex regex; string regexPattern = regexPatternObject.ToString(); if (!regexCache.TryGetValue(regexPattern, out regex)) { regex = new Regex(regexPattern); regexCache.Add(regexPattern, regex); } return(regex.IsMatch(compareTo.ToString())); } } }
/// <summary> If passed the parameter Id and Init it call the Init method of /// the Increment /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> The current value of the index /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { if (!aMap.Contains(ID)) { throw new BRERuleException("Parameter 'Id' not found"); } else if (!aMap.Contains(INIT)) { throw new BRERuleException("Parameter 'Init' not found"); } else { if (aBrc.FactoryMap.Contains(aMap[ID])) { ((IInitializable)aBrc.GetFactory(aMap[ID])).Init(aMap[INIT]); } else { throw new BRERuleException("Increment '"+aMap[ID]+"' not found"); } } return null; }
private bool DoInit(object aObj) { if (running) { if (Logger.IsFlowEngineError) Logger.FlowEngineSource.TraceEvent(TraceEventType.Error, 0, "BRE already running: a violent Stop will be tried!"); Stop(); } else { if (Logger.IsInferenceEngineInformation) Logger.FlowEngineSource.TraceEvent(TraceEventType.Information, 0, "BRE Starting..."); } if (aObj == null) { if (Logger.IsFlowEngineCritical) Logger.FlowEngineSource.TraceEvent(TraceEventType.Critical, 0, "Business Rules provided by external entity\nObject passed to init() must not be Null"); return false; } if (aObj is IRulesDriver) { rulesDriver = (IRulesDriver) aObj; xmlDocument = null; } else if (aObj is XPathDocument) { xmlDocument = (XPathDocument) aObj; } else { if (Logger.IsFlowEngineCritical) Logger.FlowEngineSource.TraceEvent(TraceEventType.Critical, 0, "Business Rules provided by external entity\nObject passed to init() must be of type System.Xml.XPath.XPathDocument or NxBRE.FlowEngine.IO.IRulesDriver and not " + aObj.GetType()); return false; } if (Logger.IsInferenceEngineInformation) Logger.FlowEngineSource.TraceEvent(TraceEventType.Information, 0, "BRE Initializing..."); if (ruleContext == null) ruleContext = new BRERuleContextImpl(new Stack(), new Hashtable(), new Hashtable(), new Hashtable()); // pre-load all operators foreach(Type type in Reflection.NxBREAssembly.GetTypes()) if (null != type.GetInterface(typeof(IBREOperator).FullName, false)) GetOperator(type.FullName); // pre-load factories initialized = LoadFactories(GetXmlDocumentRules().Select("//"+RULE+"[@"+RULE_ATTRS.FACTORY+"]")); return initialized; }
/// <summary> Always returns true /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> Boolean.TRUE /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { return(true); }
/// <summary> Initializes the object.<P> /// The default constructor exists so that objects may register /// as listeners before any action takes place. /// </P> /// </summary> /// <param name="aObj">The XML configuration document /// (either System.Xml.XPath.XPathDocument or string poiting to a XML file /// </param> /// <returns> True if successful, False otherwise /// /// </returns> public bool Init(object aObj) { if (running) { DispatchException("BRE already running: a violent Stop will be tried!", LogEventImpl.ERROR); Stop(); } else DispatchLog("BRE Starting...", LogEventImpl.INFO); if (aObj == null) { DispatchException("Business Rules provided by external entity\nObject passed to init() must not be Null", LogEventImpl.FATAL); return false; } if (aObj is IRulesDriver) { rulesDriver = (IRulesDriver) aObj; rulesDriver.LogDispatcher = this; xmlDocument = null; } else if (aObj is XPathDocument) xmlDocument = (XPathDocument) aObj; else { DispatchException("Business Rules provided by external entity\nObject passed to init() must be of type System.Xml.XPath.XPathDocument or org.nxbre.ri.drivers.IRulesDriver and not "+aObj.GetType(), LogEventImpl.FATAL); return false; } DispatchLog("BRE Initializing...", LogEventImpl.INFO); if (ruleContext == null) ruleContext = new BRERuleContextImpl(new Stack(), new Hashtable(), new Hashtable(), new Hashtable()); // pre-load all operators foreach(Type type in Assembly.GetExecutingAssembly().GetTypes()) if (null != type.GetInterface(typeof(IBREOperator).FullName, false)) GetOperator(type.FullName); // pre-load factories initialized = LoadFactories(GetXmlDocumentRules().Select("//"+RULE+"[@"+RULE_ATTRS.FACTORY+"]")); return initialized; }
public object ExecuteRule(IBRERuleContext aBRC, Hashtable aMap, object aStep) { return(null); }
public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { return executeRuleDelegate(aBrc, aMap, aStep); }
/// <summary> Always returns false /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The IDictionary of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> Boolean.FALSE /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { return false; }
// These methods demonstrate the callback possibilities from rules to code. public object ContextlessDelegate(IBRERuleContext aBrc, Hashtable aMap, object aStep) { return 50; }
public object GetEnumerable(IBRERuleContext aBrc, Hashtable aMap, object aStep) { return new ForEachSource(); }
public object WhileCounter(IBRERuleContext aBrc, Hashtable aMap, object aStep) { whileCount++; // we do not care about the returned value in the rules return null; }
public object ExecuteRule(IBRERuleContext aBRC, IDictionary aMap, object aStep) { return null; }
public object ForEachTester(IBRERuleContext aBrc, Hashtable aMap, object aStep) { int contextValue = (Int32)aBrc.GetObject("ForEachParser"); if (contextValue != ARRAY[forEachProbe]) { forEachError = "ForEachTester mismatch @" + forEachProbe + ": " + contextValue + " != " + ARRAY[forEachProbe]; } forEachProbe++; // we do not care about the returned value in the rules return null; }
public object ExecuteRule(IBRERuleContext aBrc, IDictionary aMap, object aStep) { return executeRuleDelegate(aBrc, aMap, aStep); }
/// <summary> Always returns false /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> Boolean.FALSE /// /// </returns> public object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { return false; }
/// <summary> Throws a BRERuleException with the message "Test Exception" /// unless the parameter Message provides a specific message. /// * /// </summary> /// <param name="aBrc">- The BRERuleContext object /// </param> /// <param name="aMap">- The Map of parameters from the XML /// </param> /// <param name="aStep">- The step that it is on /// </param> /// <returns> Nothing. It throws an exception each time /// /// </returns> public virtual object ExecuteRule(IBRERuleContext aBrc, Hashtable aMap, object aStep) { string message = (string) aMap[MESSAGE]; if (message == null) throw new BRERuleException("Test Exception"); else throw new BRERuleException(message); }
public object GlobalCounter(IBRERuleContext aBrc, IDictionary aMap, object aStep) { globalCount++; // we do not care about the returned value in the rules return(null); }
public object GetEnumerable(IBRERuleContext aBrc, IDictionary aMap, object aStep) { return(new ForEachSource()); }