Esempio n. 1
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			XmlDocument doc = context.ContextDocument.XmlDocument;

			if( context.ContextDocument.XmlNamespaceManager == null )
			{
				context.ContextDocument.AddNamespaces( context.PolicyDocument.Namespaces );
			}

			string xPath = GetStringArgument( args, 0 );
			XmlNodeList firstList = doc.DocumentElement.SelectNodes( xPath, context.ContextDocument.XmlNamespaceManager );

			xPath = GetStringArgument( args, 1 );
			XmlNodeList secondList = doc.DocumentElement.SelectNodes( xPath, context.ContextDocument.XmlNamespaceManager );

			foreach( XmlNode firstNode in firstList )
			{
				foreach( XmlNode secondNode in secondList )
				{
					if( firstNode == secondNode )
					{
						return EvaluationValue.True;
					}
				}
			}
			return EvaluationValue.False;
		}
Esempio n. 2
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IDataType type = DataType;
			BagValue retBag = new BagValue( type );
			inf.IFunction function = type.EqualFunction;
			inf.IFunction functionDup = type.IsInFunction;
			foreach( object par1 in args[0].Elements )
			{
				foreach( object par2 in args[1].Elements )
				{
					EvaluationValue retVal = function.Evaluate( 
						context,
						new EvaluationValue( par1, args[0].GetType( context ) ), 
						new EvaluationValue( par2, args[1].GetType( context ) ) );
					if( retVal.BoolValue )
					{
						retVal = functionDup.Evaluate( context, new EvaluationValue( par2, args[1].GetType( context ) ), retBag );
						if( !retVal.BoolValue )
						{
							retBag.Add( new EvaluationValue( par1, args[0].GetType( context ) ) );
						}
					}
				}
			}
			return new EvaluationValue( retBag, type );
		}
Esempio n. 3
0
		/// <summary>
		/// Method called by the EvaluationEngine to evaluate the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
		/// <returns></returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = args[0].GetFunction( 0 );
			foreach( object par1 in args[1].Elements )
			{
				bool hasFound = false;
				foreach( object par2 in args[2].Elements )
				{
					EvaluationValue retVal = function.Evaluate(
						context,
						new EvaluationValue( par1, args[1].GetType( context ) ), 
						new EvaluationValue( par2, args[2].GetType( context ) ) );
					if( retVal.BoolValue )
					{
						hasFound = true;
						break;
					}
				}
				if( !hasFound )
				{
					return EvaluationValue.False;
				}
			}
			return EvaluationValue.True;
		}
		/// <summary>
		/// The evaluation implementation in the pseudo-code described in the specification.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="policies">The policies that must be evaluated.</param>
		/// <returns>The final decission for the combination of the policy evaluation.</returns>
		public Decision Evaluate( EvaluationContext context, IMatchEvaluableCollection policies )
		{
			foreach( IMatchEvaluable policy in policies )
			{
				Decision decision = policy.Evaluate( context );

				context.TraceContextValues();

				if( decision == Decision.Deny )
				{
					context.ProcessingError = false;
					context.IsMissingAttribute = false;
					return Decision.Deny;
				}
				if( decision == Decision.Permit )
				{
					context.ProcessingError = false;
					context.IsMissingAttribute = false;
					return Decision.Permit;
				}
				if( decision == Decision.NotApplicable )
				{
					continue;
				}
				if( decision == Decision.Indeterminate )
				{
					return Decision.Indeterminate;
				}
			}
			return Decision.NotApplicable;
		}
 /// <summary>
 /// Method called by the EvaluationEngine when an attribute is not found.
 /// </summary>
 /// <param name="context">The evaluation context instance.</param>
 /// <param name="designator">The attribute designator.</param>
 /// <returns>An instance of an Attribute with it's value.</returns>
 public ctx.AttributeElement GetAttribute(rtm.EvaluationContext context, pol.AttributeDesignatorBase designator)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (designator == null)
     {
         throw new ArgumentNullException("designator");
     }
     foreach (ctx.AttributeElement attrib in _attributes)
     {
         if (attrib.AttributeId == designator.AttributeId)
         {
             if (designator.Issuer != null && designator.Issuer.Length != 0)
             {
                 if (designator.Issuer == attrib.Issuer)
                 {
                     return(attrib);
                 }
             }
             else
             {
                 return(attrib);
             }
         }
     }
     return(null);
 }
Esempio n. 6
0
		/// <summary>
		/// Method called by the EvaluationEngine to evaluate the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
		/// <returns></returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			int argCount = GetIntegerArgument( args, 0 );
			if( args.Length - 1 < argCount )
			{
				return EvaluationValue.Indeterminate;
			}
			else if( argCount == 0 )
			{
				return EvaluationValue.True;
			}
			else
			{
				int count = 0;
				for( int i = 1; i < args.Length; i++ )
				{
					if( GetBooleanArgument( args, i ) )
					{
						count++;
					}
					if( count == argCount )
					{
						return EvaluationValue.True;
					}
				}
				return EvaluationValue.False;
			}
		}
Esempio n. 7
0
		/// <summary>
		/// Method called by the EvaluationEngine to evaluate the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
		/// <returns></returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = args[0].GetFunction( 0 );
			if( function.Returns != DataTypeDescriptor.Boolean )
			{
				return EvaluationValue.Indeterminate;
			}
		
			foreach( object par1 in args[1].Elements )
			{
				foreach( object par2 in args[2].Elements )
				{
					EvaluationValue retVal = function.Evaluate(
						context,
						new EvaluationValue( par1, args[1].GetType( context ) ), new EvaluationValue( par2, args[2].GetType( context ) ) );
					if( !retVal.BoolValue )
					{
						return EvaluationValue.False;
					}
				}
			}
			return EvaluationValue.True;
		}
Esempio n. 8
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			if( GetBase64BinaryArgument( args, 0 ).Equals( GetBase64BinaryArgument( args, 1 ) ) )
			{
				return EvaluationValue.True;
			}
			return EvaluationValue.False;
		}
Esempio n. 9
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			bool retVal = GetBooleanArgument( args, 0 );
			for( int i = 1; i < args.Length; i++ )
			{
				retVal &= GetBooleanArgument( args, i );
			}
			return new EvaluationValue( retVal, DataTypeDescriptor.Boolean );
		}
Esempio n. 10
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			UriBuilder uri = new UriBuilder( GetAnyUriArgument( args, 0 ) );
			for( int i = 1; i < args.Length; i++ )
			{
				uri.Path = Path.Combine( uri.Path, GetStringArgument( args, i ) );
			}
			return new EvaluationValue( uri.Uri, DataTypeDescriptor.AnyUri );
		}
Esempio n. 11
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			double add = 0;
			for( int i = 0; i < args.Length; i++ )
			{
				add += GetDoubleArgument( args, i );
			}
			return new EvaluationValue( add, DataTypeDescriptor.Double );
		}
Esempio n. 12
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			StringBuilder concat = new StringBuilder();
			for( int i = 0; i < args.Length; i++ )
			{
				concat.Append( GetStringArgument( args, i ) );
			}
			return new EvaluationValue( concat.ToString(), DataTypeDescriptor.String );
		}
Esempio n. 13
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IDataType type =  DataType;
			BagValue bag = new BagValue( type );
			for( int i = 0; i < args.Length; i++ )
			{
				bag.Add( args[ i ].GetTypedValue( type, i ) );
			}
			return new EvaluationValue( bag, type );
		}
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			DateTime baseDate = GetDateArgument( args, 0 );
			typ.YearMonthDuration yearMonthDuration = (typ.YearMonthDuration)args[1].GetTypedValue( DataTypeDescriptor.YearMonthDuration, 1 );

			baseDate = baseDate.AddYears( yearMonthDuration.Years*-1 );
			baseDate = baseDate.AddMonths( yearMonthDuration.Months*-1 );

			return new EvaluationValue( baseDate, DataTypeDescriptor.Date );
		}
		/// <summary>
		/// The evaluation implementation in the pseudo-code described in the specification.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="policies">The policies that must be evaluated.</param>
		/// <returns>The final decission for the combination of the policy evaluation.</returns>
		public Decision Evaluate( EvaluationContext context, IMatchEvaluableCollection policies )
		{
			Boolean atLeastOne = false;
			Policy selectedPolicy = null;
			TargetEvaluationValue appResult;
			for( int i = 0; i < policies.Count; i++ )
			{
				Policy tempPolicy = (Policy)policies[ i ];
				appResult = appResult = tempPolicy.Match( context );
				if( appResult == TargetEvaluationValue.Indeterminate )
				{
					context.ProcessingError = true;
					context.TraceContextValues();
					return Decision.Indeterminate;
				}
				if( appResult == TargetEvaluationValue.Match )
				{
					if ( atLeastOne )
					{
						context.ProcessingError = true;
						context.TraceContextValues();
						return Decision.Indeterminate;
					}
					else
					{
						atLeastOne = true;
						selectedPolicy = (Policy)policies[i];
					}
				}
				if ( appResult == TargetEvaluationValue.NoMatch )
				{
					continue;
				}
			}
			if ( atLeastOne )
			{
				Decision retValue = selectedPolicy.Evaluate( context );
				
				context.TraceContextValues();

				if( retValue == Decision.Deny || retValue == Decision.Permit )
				{
					context.ProcessingError = false;
					context.IsMissingAttribute = false;
				}
				return retValue;
			}
			else
			{
				return Decision.NotApplicable;
			}
		}
Esempio n. 16
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			if( ((typ.Rfc822Name)args[1].GetTypedValue( DataTypeDescriptor.Rfc822Name, 1 )).Matches( GetStringArgument( args, 0 ) ) )
			{
				return EvaluationValue.True;
			}
			else
			{
				return EvaluationValue.False;
			}
		}
Esempio n. 17
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			if(String.Compare( GetStringArgument( args, 0 ), GetStringArgument( args, 1 ) ) < 0 )
			{
				return EvaluationValue.True;
			}
			else
			{
				return EvaluationValue.False;
			}
		}
Esempio n. 18
0
        /// <summary>
        /// Method called by the EvaluationEngine when the evaluation is executed without a policy document, this
        /// method search in the policy repository and return the first policy that matches its target with the
        /// context document specified.
        /// </summary>
        /// <param name="context">The evaluation context instance.</param>
        /// <returns>The policy document ready to be used by the evaluation engine.</returns>
        public pol.PolicyDocument Match(rtm.EvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            pol.PolicyDocument polEv = null;

            //Search if there is a policySet which target matches the context document
            foreach (pol.PolicyDocument policy in _policySets.Values)
            {
                rtm.PolicySet tempPolicy = new rtm.PolicySet(context.Engine, (pol.PolicySetElement)policy.PolicySet);

                rtm.EvaluationContext tempContext = new rtm.EvaluationContext(context.Engine, policy, context.ContextDocument);

                // Match the policy set target with the context document
                if (tempPolicy.Match(tempContext) == rtm.TargetEvaluationValue.Match)
                {
                    if (polEv == null)
                    {
                        polEv = policy;
                    }
                    else
                    {
                        throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_duplicated_policy_in_repository]);
                    }
                }
            }

            //Search if there is a policy which target matches the context document
            foreach (pol.PolicyDocument policy in _policies.Values)
            {
                rtm.Policy tempPolicy = new rtm.Policy((pol.PolicyElement)policy.Policy);

                rtm.EvaluationContext tempContext = new rtm.EvaluationContext(context.Engine, policy, context.ContextDocument);

                // Match the policy target with the context document
                if (tempPolicy.Match(tempContext) == rtm.TargetEvaluationValue.Match)
                {
                    if (polEv == null)
                    {
                        polEv = policy;
                    }
                    else
                    {
                        throw new EvaluationException(Resource.ResourceManager[Resource.MessageKey.exc_duplicated_policy_in_repository]);
                    }
                }
            }
            return(polEv);
        }
Esempio n. 19
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			if( args[0].IsBag && args[0].BagSize == 1 )
			{
				inf.IFunctionParameter attrib = (inf.IFunctionParameter)args[0].Elements[0];
				return new EvaluationValue( GetTypedValue( attrib ), DataType );
			}
			else
			{
				return EvaluationValue.Indeterminate;
			}
		}
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			DateTime baseDate = GetDateTimeArgument( args, 0 );
			typ.DaytimeDuration dayTimeDuration = GetDaytimeDurationArgument( args, 1 );

			baseDate = baseDate.AddDays( dayTimeDuration.Days );
			baseDate = baseDate.AddHours( dayTimeDuration.Hours );
			baseDate = baseDate.AddMinutes( dayTimeDuration.Minutes );
			baseDate = baseDate.AddSeconds( dayTimeDuration.Seconds );

			return new EvaluationValue( baseDate, DataTypeDescriptor.DateTime );
		}
Esempio n. 21
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			XmlDocument doc = context.ContextDocument.XmlDocument;

			if( context.ContextDocument.XmlNamespaceManager == null )
			{
				context.ContextDocument.AddNamespaces( context.PolicyDocument.Namespaces );
			}

			string xPath = GetStringArgument( args, 0 );
			XmlNodeList list = doc.DocumentElement.SelectNodes( xPath, context.ContextDocument.XmlNamespaceManager );
			return new EvaluationValue( list.Count, DataTypeDescriptor.Integer );
		}
Esempio n. 22
0
		/// <summary>
		/// Method called by the EvaluationEngine to evaluate the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
		/// <returns></returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = args[0].GetFunction( 0 );
			EvaluationValue value = new EvaluationValue( args[1], args[1].GetType( context ) );
			foreach( object par in args[2].Elements )
			{
				EvaluationValue retVal = function.Evaluate( context, value, new EvaluationValue( par, args[2].GetType( context ) ) );
				if( !retVal.BoolValue )
				{
					return retVal;
				}
			}
			return EvaluationValue.True;
		}
Esempio n. 23
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			string pattern = GetStringArgument( args, 0 );
			string input = GetArgumentAsString( args, 1 );

			Regex regEx = new Regex( pattern );
			Match m = regEx.Match( input );
			if( m.Success )
			{
				return EvaluationValue.True;
			}
			else
			{
				return EvaluationValue.False;
			}
		}
Esempio n. 24
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = DataType.SubsetFunction;
			if( ( function.Evaluate( 
				context,
				new EvaluationValue( args[0], args[0].GetType( context ) ), new EvaluationValue( args[1], args[1].GetType( context ) ) ) == EvaluationValue.True ) && 
				( function.Evaluate( 
				context,
				new EvaluationValue( args[1], args[1].GetType( context ) ), new EvaluationValue( args[0], args[0].GetType( context ) ) ) == EvaluationValue.True ) )
			{
				return EvaluationValue.True;
			}
			else
			{
				return EvaluationValue.False;
			}
		}
Esempio n. 25
0
		/// <summary>
		/// Method called by the EvaluationEngine to evaluate the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
		/// <returns></returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = args[0].GetFunction( 0 );
			if( !args[ 1 ].IsBag )
			{
				return EvaluationValue.False;
			}
			BagValue retVal = new BagValue( args[1].GetType( context ) );
			foreach( object par in args[1].Elements )
			{
				retVal.Add( 
					function.Evaluate( 
						context, 
						new EvaluationValue( par, args[1].GetType( context ) ) ) );
			}
			return new EvaluationValue( retVal, args[1].GetType( context ) );
		}
Esempio n. 26
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			if( args[1].IsBag )
			{
				inf.IFunction function = DataType.EqualFunction;
				foreach( object value in args[1].Elements )
				{
					if( function.Evaluate( 
						context,
						new EvaluationValue( args[0], args[0].GetType( context ) ), 
						new EvaluationValue( value, args[1].GetType( context ) ) ) == EvaluationValue.True )
					{
						return EvaluationValue.True;
					}
				}
			}
			return EvaluationValue.False;
		}
Esempio n. 27
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			try
			{
				if( GetAnyUriArgument( args, 0 ).Equals( GetAnyUriArgument( args, 1 ) ) )
				{
					return EvaluationValue.True;
				}
				else
				{
					return EvaluationValue.False;
				}
			}
			catch( EvaluationException e )
			{
				context.Trace( Resource.TRACE_ERROR, e.Message ); 
				return EvaluationValue.False;
			}
		}
Esempio n. 28
0
		/// <summary>
		/// Evaluates the function.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="args">The function arguments.</param>
		/// <returns>The result value of the function evaluation.</returns>
		public override EvaluationValue Evaluate( EvaluationContext context, params inf.IFunctionParameter[] args )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (args == null) throw new ArgumentNullException("args");
			inf.IFunction function = DataType.EqualFunction;
			foreach( object par1 in args[0].Elements )
			{
				foreach( object par2 in args[1].Elements )
				{
					EvaluationValue retVal = function.Evaluate( 
						context, 
						new EvaluationValue( par1, args[0].GetType( context ) ), 
						new EvaluationValue( par2, args[1].GetType( context ) ) );
					if( retVal.BoolValue )
					{
						return EvaluationValue.True;
					}
				}
			}
			return EvaluationValue.False;
		}
		/// <summary>
		/// The evaluation implementation in the pseudo-code described in the specification.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="rules">The policies that must be evaluated.</param>
		/// <returns>The final decission for the combination of the rule evaluation.</returns>
		public Decision Evaluate( EvaluationContext context, RuleCollection rules )
		{
			Decision decision = Decision.Indeterminate;
			context.Trace( "Evaluating rules..." );
			context.AddIndent();
			try
			{
				foreach( Rule rule in rules )
				{
					decision = rule.Evaluate( context );
					context.TraceContextValues();

					if( decision == Decision.Deny )
					{
						decision = Decision.Deny;
						return decision;
					}
					if( decision == Decision.Permit )
					{
						decision = Decision.Permit;
						return decision;
					}
					if( decision == Decision.NotApplicable )
					{
						continue;
					}
					if( decision == Decision.Indeterminate )
					{
						decision = Decision.Indeterminate;
						return decision;
					}
				}
				return Decision.NotApplicable;
			}
			finally
			{
				context.Trace( "Rule combination algorithm: {0}", decision.ToString() );
				context.RemoveIndent();
			}
		}
		/// <summary>
		/// The evaluation implementation in the pseudo-code described in the specification.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <param name="policies">The policies that must be evaluated.</param>
		/// <returns>The final decission for the combination of the policy evaluation.</returns>
		public Decision Evaluate( EvaluationContext context, IMatchEvaluableCollection policies )
		{
            if (context == null) throw new ArgumentNullException("context");
            if (policies == null) throw new ArgumentNullException("policies");
			bool atLeastOnePermit = false;
			foreach( IMatchEvaluable policy in policies )
			{
				Decision decision = policy.Evaluate( context );
				if( decision == Decision.Deny )
				{
					context.ProcessingError = false;
					context.IsMissingAttribute = false;
					return Decision.Deny;
				}
				if( decision == Decision.Permit )
				{
					atLeastOnePermit = true;
					continue;
				}
				if( decision == Decision.NotApplicable )
				{
					continue;
				}
				if( decision == Decision.Indeterminate )
				{
					context.ProcessingError = false;
					context.IsMissingAttribute = false;
					return Decision.Deny;
				}
			}
			if( atLeastOnePermit )
			{
				context.ProcessingError = false;
				context.IsMissingAttribute = false;
				return Decision.Permit;
			}
			return Decision.NotApplicable;
		}
Esempio n. 31
0
		/// <summary>
		/// Evaluates the rule contents.
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <returns>A decission for this evalauation.</returns>
		public Decision Evaluate( EvaluationContext context )
		{
            if (context == null) throw new ArgumentNullException("context");
			context.Trace( "Evaluating rule: {0}", _rule.Description );
			context.AddIndent();
			context.CurrentRule = this;
			try
			{
				// Validate the Target element
				TargetEvaluationValue targetEvaluation = Match( context );

				// If the target matches the conditions ar evaluated
				EvaluationValue conditionEvaluation = EvaluationValue.True;
				if( _rule.HasCondition )
				{
					// Evaluate the condition
					conditionEvaluation = _condition.Evaluate( context );
				}
				else
				{
					context.Trace( "Rule does not have a condition" );
				}

				// Decite the final rule evaluation value
				if( targetEvaluation == TargetEvaluationValue.Indeterminate || conditionEvaluation.IsIndeterminate )
				{
					_evaluationValue = Decision.Indeterminate;
				}
				else if( targetEvaluation == TargetEvaluationValue.Match && conditionEvaluation.BoolValue )
				{
					_evaluationValue = ((_rule.Effect == pol.Effect.Permit) ? Decision.Permit : Decision.Deny);
				}
				else if( ( targetEvaluation == TargetEvaluationValue.NoMatch ) ||
					( targetEvaluation == TargetEvaluationValue.Match && !conditionEvaluation.BoolValue ) )
				{
					_evaluationValue = Decision.NotApplicable;
				}

				// Return the value
				context.Trace( "Rule: {0}", _evaluationValue );
				return _evaluationValue;
			}
			finally
			{
				context.RemoveIndent();
				context.CurrentRule = null;
			}
		}
Esempio n. 32
0
		/// <summary>
		/// Verifies if the rule target matches
		/// </summary>
		/// <param name="context">The evaluation context instance.</param>
		/// <returns>The result of the Match process.</returns>
		public TargetEvaluationValue Match( EvaluationContext context )
		{
            if (context == null) throw new ArgumentNullException("context");
			TargetEvaluationValue targetEvaluationValue = TargetEvaluationValue.Indeterminate;
			context.Trace( "Evaluating rule target" );
			context.AddIndent();
			try
			{
				// Evaluate the policy target
				targetEvaluationValue = TargetEvaluationValue.Match;
				if( _target != null )
				{
					targetEvaluationValue = _target.Evaluate( context );

					context.TraceContextValues();
				}
				return targetEvaluationValue;
			}
			finally
			{
				context.RemoveIndent();
				context.Trace( "Target: {0}", targetEvaluationValue );
			}
		}
Esempio n. 33
0
 /// <summary>
 /// Gets the data type of the value.
 /// </summary>
 /// <param name="context">The evaluation context.</param>
 /// <returns>The data type descriptor.</returns>
 public inf.IDataType GetType(rtm.EvaluationContext context)
 {
     return(rtm.EvaluationEngine.GetDataType(DataTypeValue));
 }