Example #1
0
        public RequestHandler(IMethodCacheBuilder cacheBuilder, IEnumerable<IParameterResolver> parameterResolvers)
        {
            if (cacheBuilder == null) throw new ArgumentNullException("cacheBuilder");
            if (parameterResolvers == null) throw new ArgumentNullException("parameterResolvers");

            _parameterResolvers = parameterResolvers;
            _methodCache = cacheBuilder.Build();
        }
 public ReflectionCache(Type ownerType)
 {
     this._OwnerType        = ownerType;
     this._Fields           = new FieldAccessorCache(ownerType);
     this._Properties       = new PropertyAccessorCache(ownerType);
     this._StaticFields     = new StaticFieldAccessorCache(ownerType);
     this._StaticProperties = new StaticPropertyAccessorCache(ownerType);
     _Methods       = new InstanceMethodCache(ownerType);
     _StaticMethods = new StaticMethodCache(ownerType);
 }
Example #3
0
        /// <summary>
        /// Executes this modification.
        /// </summary>
        public bool Execute(IVariantResolver inResolver, object inContext = null, IMethodCache inInvoker = null)
        {
            Variant operandValue;

            if (Operand.TryResolve(inResolver, inContext, out operandValue, inInvoker))
            {
                return(inResolver.TryModify(inContext, VariableKey, Operator, operandValue));
            }

            return(false);
        }
Example #4
0
        public RequestHandler(IMethodCacheBuilder cacheBuilder, IEnumerable <IParameterResolver> parameterResolvers)
        {
            if (cacheBuilder == null)
            {
                throw new ArgumentNullException("cacheBuilder");
            }
            if (parameterResolvers == null)
            {
                throw new ArgumentNullException("parameterResolvers");
            }

            _parameterResolvers = parameterResolvers;
            _methodCache        = cacheBuilder.Build();
        }
Example #5
0
        /// <summary>
        /// Evaluates this comparison.
        /// </summary>
        public bool Evaluate(IVariantResolver inResolver, object inContext = null, IMethodCache inInvoker = null)
        {
            Variant leftValue, rightValue;
            bool    bRetrievedLeft  = Left.TryResolve(inResolver, inContext, out leftValue, inInvoker);
            bool    bRetrievedRight = Right.TryResolve(inResolver, inContext, out rightValue, inInvoker);

            switch (Operator)
            {
            case VariantCompareOperator.LessThan:
                return(leftValue < rightValue);

            case VariantCompareOperator.LessThanOrEqualTo:
                return(leftValue <= rightValue);

            case VariantCompareOperator.EqualTo:
                return(leftValue == rightValue);

            case VariantCompareOperator.NotEqualTo:
                return(leftValue != rightValue);

            case VariantCompareOperator.GreaterThanOrEqualTo:
                return(leftValue >= rightValue);

            case VariantCompareOperator.GreaterThan:
                return(leftValue > rightValue);

            case VariantCompareOperator.Exists:
                return(bRetrievedLeft);

            case VariantCompareOperator.DoesNotExist:
                return(!bRetrievedLeft);

            case VariantCompareOperator.True:
                return(leftValue.AsBool());

            case VariantCompareOperator.False:
                return(!leftValue.AsBool());

            default:
                throw new InvalidOperationException("Unknown operator " + Operator.ToString());
            }
        }
Example #6
0
 public SubscribeHandler(IServiceProvider _serviceProvider, ILogger <SubscribeHandler> _logger, IMethodCache _methodCache)
 {
     serviceProvider = _serviceProvider;
     logger          = _logger;
     methodCache     = _methodCache;
 }
Example #7
0
 public DynamicMethodExpression(IMethodCache _methodCache)
 {
     exec        = new ConcurrentDictionary <string, Delegate>();
     methodCache = _methodCache;
 }
Example #8
0
        /// <summary>
        /// Attempts to apply one or more modifications, described by the given string.
        /// </summary>
        static public bool TryModify(this IVariantResolver inResolver, object inContext, StringSlice inModifyData, IMethodCache inInvoker = null)
        {
            if (inModifyData.IsWhitespace)
            {
                return(true);
            }

            StringSlice.ISplitter splitter = QuoteAwareSplitter ?? (QuoteAwareSplitter = new StringUtils.ArgsList.Splitter(false));
            bool bSuccess = true;
            VariantModification mod;

            foreach (var group in inModifyData.EnumeratedSplit(splitter, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!VariantModification.TryParse(group, out mod) || !mod.Execute(inResolver, inContext, inInvoker))
                {
                    bSuccess = false;
                }
            }

            return(bSuccess);
        }
Example #9
0
        /// <summary>
        /// Attempts to evaluate if all conditions described by the given string are true.
        /// </summary>
        static public bool TryEvaluate(this IVariantResolver inResolver, object inContext, StringSlice inEvalData, IMethodCache inInvoker = null)
        {
            if (inEvalData.IsWhitespace)
            {
                return(true);
            }

            StringSlice.ISplitter splitter = QuoteAwareSplitter ?? (QuoteAwareSplitter = new StringUtils.ArgsList.Splitter(false));
            VariantComparison     comp;

            foreach (var group in inEvalData.EnumeratedSplit(splitter, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!VariantComparison.TryParse(group, out comp) || !comp.Evaluate(inResolver, inContext, inInvoker))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        /// <summary>
        /// Attempts to resolve the value.
        /// </summary>
        public bool TryResolve(IVariantResolver inResolver, object inContext, out Variant outValue, IMethodCache inInvoker = null)
        {
            switch (Type)
            {
            case Mode.TableKey:
            {
                return(inResolver.TryResolve(inContext, TableKey, out outValue));
            }

            case Mode.Variant:
            {
                outValue = Value;
                return(true);
            }

            case Mode.Method:
            {
                if (inInvoker == null)
                {
                    throw new ArgumentNullException("inInvoker", "No IMethodCache provided - cannot invoke a method call operand");
                }

                object obj;
                if (!inInvoker.TryStaticInvoke(MethodCall, inContext, out obj))
                {
                    Log.Error("[VariantOperand] Unable to execute {0}", MethodCall);
                    outValue = default(Variant);
                    return(false);
                }

                if (!Variant.TryConvertFrom(obj, out outValue))
                {
                    Log.Error("[VariantOperand] Unable to convert result of {0} ({1}) to Variant", MethodCall, obj);
                    outValue = default(Variant);
                    return(false);
                }

                return(true);
            }

            default:
                throw new InvalidOperationException("Unknown operand type " + Type.ToString());
            }
        }