예제 #1
0
 /// <summary> Sets a parameter for use by RuleFactories
 /// *
 /// </summary>
 /// <param name="aId">The UID of the parameter
 /// </param>
 /// <param name="aValue">The value to set
 ///
 /// </param>
 public virtual void  SetOperator(object aId, IBREOperator aValue)
 {
     if (operators != null)
     {
         if (operators.Contains(aId))
         {
             operators.Remove(aId);
         }
         operators.Add(aId, aValue);
     }
 }
예제 #2
0
파일: BREImpl.cs 프로젝트: vkiktev/NxBRE
        ///<summary>Lazy loading of operator.</summary>
        /// <param name="operatorId">Full qualified name of an operator</param>
        /// <returns>An operator object implementing IBREOperator</returns>
        private IBREOperator GetOperator(string operatorId)
        {
            IBREOperator ruleOperator = null;

            if (!ruleContext.OperatorMap.ContainsKey(operatorId))
            {
                DispatchLog("Loading Operator: " + operatorId, LogEventImpl.DEBUG);
                ruleOperator = (IBREOperator)Assembly.GetExecutingAssembly().CreateInstance(operatorId);
                ruleContext.SetOperator(operatorId, ruleOperator);
            }
            else
            {
                ruleOperator = ruleContext.GetOperator(operatorId);
            }

            return(ruleOperator);
        }
예제 #3
0
        ///<summary>Lazy loading of operator.</summary>
        /// <param name="operatorId">Full qualified name of an operator</param>
        /// <returns>An operator object implementing IBREOperator</returns>
        private IBREOperator GetOperator(string operatorId)
        {
            IBREOperator ruleOperator = null;

            if (!ruleContext.OperatorMap.Contains(operatorId))
            {
                if (Logger.IsFlowEngineVerbose)
                {
                    Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Loading Operator: " + operatorId);
                }
                ruleOperator = (IBREOperator)Reflection.ClassNew(operatorId, null);
                ruleContext.SetOperator(operatorId, ruleOperator);
            }
            else
            {
                ruleOperator = ruleContext.GetOperator(operatorId);
            }

            return(ruleOperator);
        }
예제 #4
0
        /// <summary> This methods processes the Compare nodes that may exist in the XML.
        /// <P>
        /// The best comparison works when the object implements Comparable.
        /// </P>
        /// <P>
        /// If the object does not do so, it eliminates the &lt;,&gt;,&lt;=,&gt;=
        /// functionality as we are left with .equals(), !.equals(), and
        /// exception
        /// </P>
        /// </summary>
        /// <param name="aNode">The Node to process
        /// </param>
        /// <param name="aMap"/>
        /// <returns> True if the If stmt passes, False otherwise
        ///
        /// </returns>
        private bool ProcessCompareNode(XPathNavigator aNode, Hashtable aMap)
        {
            bool resultBool = false;

            // This is required in the XML, so we shouldn't have to worry about nulls....
            string leftId     = aNode.GetAttribute(COMPARE_ATTRS.LEFTID, String.Empty);
            string rightId    = aNode.GetAttribute(COMPARE_ATTRS.RIGHTID, String.Empty);
            string operatorId = aNode.GetAttribute(COMPARE_ATTRS.OPERATOR, String.Empty);

            IBREOperator ruleOperator = GetOperator(operatorId);

            if (ruleOperator != null)
            {
                // Get the results
                IBRERuleResult leftResult  = (IBRERuleResult)ruleContext.GetResult(leftId);
                IBRERuleResult rightResult = (IBRERuleResult)ruleContext.GetResult(rightId);

                // If it does not, consider a null in left or right members as exceptions!
                if ((!ruleOperator.AcceptsNulls) && (leftResult == null))
                {
                    if (Logger.IsFlowEngineError)
                    {
                        Logger.FlowEngineSource.TraceEvent(TraceEventType.Error, 0, "RuleResult " + leftId + " not found in RuleContext");
                    }
                }
                else if ((!ruleOperator.AcceptsNulls) && (rightResult == null))
                {
                    if (Logger.IsFlowEngineError)
                    {
                        Logger.FlowEngineSource.TraceEvent(TraceEventType.Error, 0, "RuleResult " + rightId + " not found in RuleContext");
                    }
                }
                else
                {
                    if (Logger.IsFlowEngineVerbose)
                    {
                        Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Retrieved results for comparison");
                    }

                    object left  = (leftResult == null)?null:leftResult.Result;
                    object right = (rightResult == null)?null:rightResult.Result;

                    try
                    {
                        if (Logger.IsFlowEngineVerbose)
                        {
                            Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "BREOperator " + operatorId + " executing");
                        }
                        resultBool = ruleOperator.ExecuteComparison(ruleContext, aMap, left, right);
                    }
                    catch (InvalidCastException ice)
                    {
                        if (Logger.IsFlowEngineCritical)
                        {
                            Logger.FlowEngineSource.TraceData(TraceEventType.Critical,
                                                              0,
                                                              new BREException("Specified BREOperator "
                                                                               + operatorId
                                                                               + " not of type BREOperator or objects being compared are not"
                                                                               + " of the same type.\n"
                                                                               + "Left Object Name:" + leftId
                                                                               + "\nLeft Object Type:" + left.GetType().FullName
                                                                               + "\nRight Object Name:" + rightId
                                                                               + "\nRight Object Type:" + right.GetType().FullName
                                                                               + "\n", ice));
                        }
                    }
                    catch (Exception e)
                    {
                        if (Logger.IsFlowEngineCritical)
                        {
                            Logger.FlowEngineSource.TraceData(TraceEventType.Critical,
                                                              0,
                                                              new BREException("Error when processing BREOperator "
                                                                               + operatorId
                                                                               + ".\n"
                                                                               + "Left Object Name:" + leftId
                                                                               + "\nLeft Object:" + left
                                                                               + "\nRight Object Name:" + rightId
                                                                               + "\nRight Object:" + right
                                                                               + "\n", e));
                        }
                    }
                }
            }
            else
            {
                if (Logger.IsFlowEngineCritical)
                {
                    Logger.FlowEngineSource.TraceData(TraceEventType.Critical, 0, new BREException("Operator could not be loaded from BRERuleContext"));
                }
            }

            if (Logger.IsFlowEngineVerbose)
            {
                Logger.FlowEngineSource.TraceEvent(TraceEventType.Verbose, 0, "Compare result: " + resultBool);
            }
            return(resultBool);
        }
예제 #5
0
파일: BREImpl.cs 프로젝트: vkiktev/NxBRE
        /// <summary> This methods processes the Compare nodes that may exist in the XML.
        /// <P>
        /// The best comparison works when the object implements Comparable.
        /// </P>
        /// <P>
        /// If the object does not do so, it eliminates the &lt;,&gt;,&lt;=,&gt;=
        /// functionality as we are left with .equals(), !.equals(), and
        /// exception
        /// </P>
        /// </summary>
        /// <param name="aNode">The Node to process
        /// </param>
        /// <param name="aMap"/>
        /// <returns> True if the If stmt passes, False otherwise
        ///
        /// </returns>
        private Boolean ProcessCompareNode(XPathNavigator aNode, Hashtable aMap)
        {
            bool resultBool = false;

            // This is required in the XML, so we shouldn't have to worry about nulls....
            string leftId     = aNode.GetAttribute(COMPARE_ATTRS.LEFTID, String.Empty);
            string rightId    = aNode.GetAttribute(COMPARE_ATTRS.RIGHTID, String.Empty);
            string operatorId = aNode.GetAttribute(COMPARE_ATTRS.OPERATOR, String.Empty);

            IBREOperator ruleOperator = GetOperator(operatorId);

            if (ruleOperator != null)
            {
                // Get the results
                IBRERuleResult leftResult  = (IBRERuleResult)ruleContext.GetResult(leftId);
                IBRERuleResult rightResult = (IBRERuleResult)ruleContext.GetResult(rightId);

                // If it does not, consider a null in left or right members as exceptions!
                if ((!ruleOperator.AcceptsNulls) && (leftResult == null))
                {
                    DispatchException(new BREException("RuleResult " + leftId + " not found in RuleContext"), ExceptionEventImpl.ERROR);
                }
                else if ((!ruleOperator.AcceptsNulls) && (rightResult == null))
                {
                    DispatchException(new BREException("RuleResult " + rightId + " not found in RuleContext"), ExceptionEventImpl.ERROR);
                }
                else
                {
                    DispatchLog("Retrieved results for comparison", LogEventImpl.DEBUG);

                    object left  = (leftResult == null)?null:leftResult.Result;
                    object right = (rightResult == null)?null:rightResult.Result;

                    try
                    {
                        DispatchLog("BREOperator " + operatorId + " executing.", LogEventImpl.DEBUG);
                        resultBool = ruleOperator.ExecuteComparison(ruleContext, aMap, left, right);
                    }
                    catch (System.InvalidCastException)
                    {
                        DispatchException(new BREException("Specified BREOperator "
                                                           + operatorId
                                                           + " not of type BREOperator or objects being compared are not"
                                                           + " of the same type.\n"
                                                           + "Left Object Name:" + leftId
                                                           + "\nLeft Object Type:" + left.GetType().FullName
                                                           + "\nRight Object Name:" + rightId
                                                           + "\nRight Object Type:" + right.GetType().FullName
                                                           + "\n"),
                                          ExceptionEventImpl.FATAL);
                    }
                    catch (System.Exception e)
                    {
                        DispatchException(new BREException(e.ToString()), ExceptionEventImpl.FATAL);
                    }
                }
            }
            else
            {
                DispatchException(new BREException("Operator could not be loaded from BRERuleContext"), ExceptionEventImpl.FATAL);
            }

            DispatchLog("Compare result: " + resultBool, LogEventImpl.DEBUG);
            return(resultBool);
        }
예제 #6
0
		/// <summary> Sets a parameter for use by RuleFactories
		/// *
		/// </summary>
		/// <param name="aId">The UID of the parameter
		/// </param>
		/// <param name="aValue">The value to set
		/// 
		/// </param>
		public virtual void  SetOperator(object aId, IBREOperator aValue)
		{
			if (operators != null) {
				if (operators.Contains(aId)) operators.Remove(aId);
				operators.Add(aId, aValue);
			}
		}
예제 #7
0
		/// <summary> Sets a parameter for use by RuleFactories
		/// *
		/// </summary>
		/// <param name="aId">The UID of the parameter
		/// </param>
		/// <param name="aValue">The value to set
		/// 
		/// </param>
		public virtual void  SetOperator(object aId, IBREOperator aValue)
		{
			if (operators != null) {
                operators[aId] = aValue;
			}
		}