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);
			}
		}
Exemplo n.º 2
0
 public ValueStack(IExceptionHandler handler, IExpressionContext expressionContext)
 {
     Values = new CustomDictionary();
     _exceptionHandler = handler;
     _evaluator = expressionContext.CreateEvaluator(this);
     Persistables = new Dictionary<string, IPersistable>();
 }
Exemplo n.º 3
0
		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 ();
		}
Exemplo n.º 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);
		}
Exemplo n.º 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;
		}
Exemplo n.º 11
0
 public abstract string StringEvaluate(IExpressionContext context);
Exemplo n.º 12
0
 public static void Init(IExpressionContext context)
 {
     Current = context;
 }
Exemplo n.º 13
0
 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());
 }
Exemplo n.º 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));
 }
Exemplo n.º 16
0
 public static Log Log(this IExpressionContext context) => context.Item <Log>();
Exemplo n.º 17
0
 public override IExpression Invoke(IExpressionContext context) => Constant.Create(nameof(OmniLog.LogLevel), context.Log().Name());
 public override bool CanEvaluateToNumber(IExpressionContext context)
 {
     return(false);
 }
Exemplo n.º 19
0
 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();
 }
Exemplo n.º 23
0
		// 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);
		}
Exemplo n.º 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()));
 }
Exemplo n.º 25
0
 public abstract float NumberEvaluate(IExpressionContext context);
Exemplo n.º 26
0
 public abstract bool CanEvaluateToBool(IExpressionContext context);
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return expression.CanEvaluateToBool (context);
		}
Exemplo n.º 28
0
		public abstract bool CanEvaluateToString (IExpressionContext context);
Exemplo n.º 29
0
		public override bool CanEvaluateToString (IExpressionContext context)
		{
			return false;
		}
Exemplo n.º 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);
        }
Exemplo n.º 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));
 }
Exemplo n.º 32
0
 public abstract bool CanEvaluateToNumber(IExpressionContext context);
Exemplo n.º 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);
        }
Exemplo n.º 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));
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
		}
Exemplo n.º 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);
		}
Exemplo n.º 42
0
		public override float NumberEvaluate (IExpressionContext context)
		{
			Token evaluatedToken = EvaluateToken (token, context);
		
			return Single.Parse (evaluatedToken.Value, CultureInfo.InvariantCulture);
		}
Exemplo n.º 43
0
		public override bool CanEvaluateToNumber (IExpressionContext context)
		{
			if (token.Type == TokenType.Number)
				return true;
			else
				return false;
		}
Exemplo n.º 44
0
		// 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);
 }
Exemplo n.º 46
0
 public abstract bool BoolEvaluate(IExpressionContext context);
Exemplo n.º 47
0
		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);
 }
Exemplo n.º 49
0
		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));
		}
Exemplo n.º 52
0
		public override string StringEvaluate (IExpressionContext context)
		{
			throw new NotSupportedException ();
		}
Exemplo n.º 53
0
 public override System.Linq.Expressions.Expression ToLinqExpression(IExpressionContext ctx)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 54
0
 public static void Init(IExpressionContext context)
 {
     Current = context;
 }
Exemplo n.º 55
0
		public override float NumberEvaluate (IExpressionContext context)
		{
			throw new NotSupportedException ();
		}
Exemplo n.º 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()));
        }
Exemplo n.º 57
0
		// FIXME: check if we really can do it
		public override bool CanEvaluateToBool (IExpressionContext context)
		{
			return true;
		}
Exemplo n.º 58
0
 protected override IEnumerable <FieldInfo> GetMemberInfosForType(IExpressionContext context, Type type)
 {
     return(type.GetFields());
 }
Exemplo n.º 59
0
 public ValueStackContext(IDbRefFactory dbRefFactory, IExpressionContext expressionContext)
 {
     _dbRefFactory = dbRefFactory;
     _expressionContext = expressionContext;
 }
Exemplo n.º 60
0
        public override string StringEvaluate(IExpressionContext context)
        {
            Token evaluatedToken = EvaluateToken(token, context);

            return(evaluatedToken.Value);
        }