public override  bool BoolEvaluate (IExpressionContext context)
		{
			if (left.CanEvaluateToNumber (context) && right.CanEvaluateToNumber (context)) {
				float l,r;
				
				l = left.NumberEvaluate (context);
				r = right.NumberEvaluate (context);
				
				return NumberCompare (l, r, op);
			} else if (left.CanEvaluateToBool (context) && right.CanEvaluateToBool (context)) {
				bool l,r;
				
				l = left.BoolEvaluate (context);
				r = right.BoolEvaluate (context);
				
				return BoolCompare (l, r, op);
			} else {
				string l,r;
				
				l = left.StringEvaluate (context);
				r = right.StringEvaluate (context);
				
				return StringCompare (l, r, op);
			}
		}
Example #2
0
 public ValueStack(IExceptionHandler handler, IExpressionContext expressionContext)
 {
     Values = new CustomDictionary();
     _exceptionHandler = handler;
     _evaluator = expressionContext.CreateEvaluator(this);
     Persistables = new Dictionary<string, IPersistable>();
 }
		public override  bool BoolEvaluate (IExpressionContext context)
		{
			if (left.BoolEvaluate (context))
				return true;
			if (right.BoolEvaluate (context))
				return true;
			return false;
		}
		public override bool BoolEvaluate (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			if (trueValues [evaluatedToken.Value] != null)
				return true;
			else if (falseValues [evaluatedToken.Value] != null)
				return false;
			else
				throw new InvalidOperationException ();
		}
Example #5
0
		public static bool ParseAndEvaluate (string condition, IExpressionContext context)
		{
			if (String.IsNullOrEmpty (condition))
				return true;

			ConditionExpression ce = ParseCondition (condition);

			if (!ce.CanEvaluateToBool (context))
				throw new Exception (String.Format ("Can not evaluate \"{0}\" to bool.", condition));

			return ce.BoolEvaluate (context);
		}
		public override bool BoolEvaluate (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			if (trueValues [evaluatedToken.Value] != null)
				return true;
			else if (falseValues [evaluatedToken.Value] != null)
				return false;
			else
				throw new ExpressionEvaluationException (
						String.Format ("Expression \"{0}\" evaluated to \"{1}\" instead of a boolean value",
								token.Value, evaluatedToken.Value));
		}
		public override  bool BoolEvaluate (IExpressionContext context)
		{
			Func<string, IExpressionContext, bool> func;
			if (!functions.TryGetValue (name, out func)) {
				// MSB4091
				throw new Exception (string.Format ("Found a call to an undefined function \"{0}\".", name));
			}

			if (args.Count != 1) {
				// MSB4089
				throw new Exception (string.Format ("Incorrect number of arguments to function in condition \"{0}\". Found {1} argument(s) when expecting {2}.",
					name, args.Count, 1));
			}
			
			return func (args [0].StringEvaluate (context), context);
		}
		public override  bool BoolEvaluate (IExpressionContext context)
		{
			if (!functions.ContainsKey (name))
				throw new InvalidOperationException ("Unknown function named: " + name);
			
			if (functions [name] == null)
				throw new InvalidOperationException ("Unknown function named: " + name);
				
			MethodInfo mi = functions [name];
			object [] argsArr = new object [args.Count + 1];
			int i = 0;
			foreach (ConditionFactorExpression cfe in args)
				argsArr [i++] = cfe.StringEvaluate (context);
			argsArr [i] = context;
				
			return (bool) mi.Invoke (null, argsArr);
		}
Example #9
0
		public static bool ParseAndEvaluate (string condition, IExpressionContext context)
		{
			if (String.IsNullOrEmpty (condition))
				return true;

			try {
				ConditionExpression ce = ParseCondition (condition);

				if (!ce.CanEvaluateToBool (context))
					throw new InvalidProjectFileException (String.Format ("Can not evaluate \"{0}\" to bool.", condition));

				return ce.BoolEvaluate (context);
			} catch (ExpressionParseException epe) {
				throw new InvalidProjectFileException (
						String.Format ("Unable to parse condition \"{0}\" : {1}", condition, epe.Message),
						epe);
			} catch (ExpressionEvaluationException epe) {
				throw new InvalidProjectFileException (
						String.Format ("Unable to evaluate condition \"{0}\" : {1}", condition, epe.Message),
						epe);
			}
		}
#pragma warning disable 0169
#region Functions
		// FIXME imported projects
		static bool Exists (string file, IExpressionContext context)
		{
			if (string.IsNullOrEmpty (file))
				return false;

			string directory = context.FullDirectoryName;

			file = MSBuildProjectService.FromMSBuildPath (directory, file);
			bool res;
			if (context.ExistsEvaluationCache.TryGetValue (file, out res))
				return res;
			
			res = File.Exists (file) || Directory.Exists (file);
			context.ExistsEvaluationCache [file] = res;
			return res;
		}
 public abstract string StringEvaluate(IExpressionContext context);
Example #12
0
 public static void Init(IExpressionContext context)
 {
     Current = context;
 }
 public abstract bool CanEvaluateToString(IExpressionContext context);
 /// <summary>
 /// Gets the member infos for the specified type.
 /// </summary>
 /// <param name="context">The expression context.</param>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 protected override IEnumerable <ConstructorInfo> GetMemberInfosForType(IExpressionContext context, Type type)
 {
     return(type.GetConstructors());
 }
Example #15
0
 public override bool CanEvaluateToBool(IExpressionContext context)
 {
     // Short-circuiting, check only left expr, right
     // would be required only if left == true
     return(left.CanEvaluateToBool(context));
 }
Example #16
0
 public static Log Log(this IExpressionContext context) => context.Item <Log>();
Example #17
0
 public override IExpression Invoke(IExpressionContext context) => Constant.Create(nameof(OmniLog.LogLevel), context.Log().Name());
 public override bool CanEvaluateToNumber(IExpressionContext context)
 {
     return(false);
 }
 public IEnumerable <MemberInfo> GetMembers(IExpressionContext context)
 {
     return(this.Select(m => m.ToMemberInfo(context)));
 }
 // FIXME: check if we really can do it
 public override bool CanEvaluateToBool(IExpressionContext context)
 {
     return(true);
 }
 public override string StringEvaluate(IExpressionContext context)
 {
     throw new NotSupportedException();
 }
 public override float NumberEvaluate(IExpressionContext context)
 {
     throw new NotSupportedException();
 }
		// FIXME: in some situations items might not be allowed
		static Token EvaluateToken (Token token, IExpressionContext context)
		{
			string val = context.EvaluateString (token.Value);
			return new Token (val, TokenType.String);
		}
Example #24
0
 /// <summary>
 /// Converts this instance to an boolean expression.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entity.</typeparam>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public Expression <Func <TEntity, bool> > ToBooleanExpression <TEntity>(IExpressionContext context = null)
 {
     return(ToExpression(ConvertToBooleanExpression <TEntity>, context ?? new ExpressionContext()));
 }
 public abstract float NumberEvaluate(IExpressionContext context);
 public abstract bool CanEvaluateToBool(IExpressionContext context);
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return expression.CanEvaluateToBool (context);
		}
Example #28
0
		public abstract bool CanEvaluateToString (IExpressionContext context);
		public override bool CanEvaluateToString (IExpressionContext context)
		{
			return false;
		}
Example #30
0
        /// <summary>
        /// Invokes the expression with the specified expression context and
        /// binding options.
        /// </summary>
        /// <param name="expressionContext">The expression context used to
        /// bind and execute the expression.</param>
        /// <param name="options">The options used to bind the expression.</param>
        /// <returns>The result of the expression.</returns>
        public object Invoke(IExpressionContext expressionContext, BoundExpressionOptions options)
        {
            if (expressionContext == null)
                expressionContext = new ExpressionContext();

            return Bind(expressionContext, options).Invoke(expressionContext);
        }
Example #31
0
 /// <summary>
 /// Converts this instance to an expression.
 /// </summary>
 /// <typeparam name="TDelegate">The type of the delegate.</typeparam>
 /// <param name="conversionFunction">The conversion function.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException">
 /// Parameter <paramref name="conversionFunction"/> or <paramref name="context"/> is null.
 /// </exception>
 public Expression <TDelegate> ToExpression <TDelegate>(Func <ExpressionNode, IExpressionContext, Expression <TDelegate> > conversionFunction, IExpressionContext context)
 {
     if (conversionFunction == null)
     {
         throw new ArgumentNullException(nameof(conversionFunction));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return(conversionFunction(this, context));
 }
 public abstract bool CanEvaluateToNumber(IExpressionContext context);
Example #33
0
        /// <summary>
        /// Converts to an expression.
        /// </summary>
        /// <typeparam name="TDelegate">The type of the delegate.</typeparam>
        /// <param name="expressionNode">The expression node.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private static Expression <TDelegate> ConvertToExpression <TDelegate>(ExpressionNode expressionNode, IExpressionContext context)
        {
            var expression = expressionNode.ToExpression(context);

            return((Expression <TDelegate>)expression);
        }
Example #34
0
 /// <summary>
 /// Converts to a boolean expression.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entity.</typeparam>
 /// <param name="expressionNode">The expression node.</param>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 private static Expression <Func <TEntity, bool> > ConvertToBooleanExpression <TEntity>(ExpressionNode expressionNode, IExpressionContext context)
 {
     return(ConvertToExpression <Func <TEntity, bool> >(expressionNode, context));
 }
Example #35
0
 /// <summary>
 /// Invokes the expression with the specified expression context.
 /// </summary>
 /// <param name="expressionContext">The expression context used to
 /// bind and execute the expression.</param>
 /// <returns>The result of the expression.</returns>
 public object Invoke(IExpressionContext expressionContext)
 {
     return Invoke(expressionContext, null);
 }
Example #36
0
 /// <summary>
 /// Converts this instance to an expression.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public virtual Expression ToExpression(IExpressionContext context)
 {
     return(null);
 }
#pragma warning disable 0169
#region Functions
		// FIXME imported projects
		static bool Exists (string file, IExpressionContext context)
		{
			if (string.IsNullOrEmpty (file))
				return false;

			string directory  = null;
			
			if (context.FullFileName != String.Empty)
				directory = Path.GetDirectoryName (context.FullFileName);

			file = MSBuildProjectService.FromMSBuildPath (directory, file);

			return File.Exists (file) || Directory.Exists (file);
		}
Example #38
0
 /// <summary>
 /// Converts this instance to an expression.
 /// </summary>
 /// <typeparam name="TDelegate">The type of the delegate.</typeparam>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public Expression <TDelegate> ToExpression <TDelegate>(IExpressionContext context = null)
 {
     return(ToExpression(ConvertToExpression <TDelegate>, context ?? new ExpressionContext()));
 }
		static bool HasTrailingSlash (string file, IExpressionContext context)
		{
			if (file == null)
				return false;

			file = file.Trim ();

			int len = file.Length;
			if (len == 0)
				return false;

			return file [len - 1] == '\\' || file [len - 1] == '/';
		}
 public abstract bool TryEvaluateToBool(IExpressionContext context, out bool result);
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return functions.ContainsKey (name);
		}
		public override float NumberEvaluate (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			return Single.Parse (evaluatedToken.Value, CultureInfo.InvariantCulture);
		}
		public override bool CanEvaluateToNumber (IExpressionContext context)
		{
			if (token.Type == TokenType.Number)
				return true;
			else
				return false;
		}
		// FIXME: check if we really can do it
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			if (token.Type == TokenType.String && allValues [evaluatedToken.Value] != null)
				return true;
			else
				return false;
		}
 public virtual bool TryEvaluateToNumber(IExpressionContext context, out float result)
 {
     result = 0;
     return(false);
 }
 public abstract bool BoolEvaluate(IExpressionContext context);
		public override string StringEvaluate (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			return evaluatedToken.Value;
		}
 public virtual bool TryEvaluateToString(IExpressionContext context, out string result)
 {
     result = null;
     return(false);
 }
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return left.CanEvaluateToBool (context) && right.CanEvaluateToBool (context);
		}
 public virtual bool TryEvaluateToVersion(IExpressionContext context, out Version result)
 {
     result = null;
     return(false);
 }
		public override  bool BoolEvaluate (IExpressionContext context)
		{
			return !(expression.BoolEvaluate (context));
		}
		public override string StringEvaluate (IExpressionContext context)
		{
			throw new NotSupportedException ();
		}
 public override System.Linq.Expressions.Expression ToLinqExpression(IExpressionContext ctx)
 {
     throw new NotImplementedException();
 }
Example #54
0
 public static void Init(IExpressionContext context)
 {
     Current = context;
 }
		public override float NumberEvaluate (IExpressionContext context)
		{
			throw new NotSupportedException ();
		}
Example #56
0
        protected override IAggregateFluent <ProductSubgroupView> ConvertToViewAggreagate(IAggregateFluent <ProductSubgroup> mappings, IExpressionContext <ProductSubgroup, ProductSubgroupView> context)
        {
            var unwind = new AggregateUnwindOptions <ProductSubgroupView> {
                PreserveNullAndEmptyArrays = true
            };

            return(mappings.Lookup("product_group", "product_group_code", "code", "ProductGroup")
                   .Unwind("ProductGroup", unwind)
                   .As <ProductSubgroupView>().Match(context.GetPostExpression()));
        }
		// FIXME: check if we really can do it
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return true;
		}
 protected override IEnumerable <FieldInfo> GetMemberInfosForType(IExpressionContext context, Type type)
 {
     return(type.GetFields());
 }
Example #59
0
 public ValueStackContext(IDbRefFactory dbRefFactory, IExpressionContext expressionContext)
 {
     _dbRefFactory = dbRefFactory;
     _expressionContext = expressionContext;
 }
Example #60
0
        public override string StringEvaluate(IExpressionContext context)
        {
            Token evaluatedToken = EvaluateToken(token, context);

            return(evaluatedToken.Value);
        }