예제 #1
0
        /// <summary>
        /// Compiles the input linqExpression into a Linq expression tree
        /// </summary>
        /// <param name="linqExpression">The linqExpression.</param>
        /// <returns></returns>
        public Func <object, object, object> CompileFunction(LinqExpressionToRun linqExpression)
        {
            if (linqExpression.Unique) //don't bother caching
            {
                _counterFunctionCacheUnique.Increment();
                return(_handler.CompileFunction(linqExpression));
            }

            var key    = GenerateKey(linqExpression);
            var result = (Func <object, object, object>)_cache[key];

            if (result != null)
            {
                _counterFunctionCacheHit.Increment(key);
                return(result);
            }

            result = _handler.CompileFunction(linqExpression);
            if (!_cache.Exists(key))
            {
                _counterFunctionCacheMiss.Increment(key);
                _cache.Add(key, result);
                _cache.Expire(key, _itemPolicy.SlidingExpiration);
            }

            return(result);
        }
 /// <summary>
 /// Compiles the input linqExpression into a Linq expression tree
 /// </summary>
 /// <param name="linqExpression">The linqExpression.</param>
 /// <returns></returns>
 public Func <object, object, object> CompileFunction(LinqExpressionToRun linqExpression)
 {
     using (_compileFunctionTimer.NewContext())
     {
         return(_handler.CompileFunction(linqExpression));
     }
 }
        /// <inheritdoc />
        public void HandleExecution(IReceivedMessage <MessageExpression> receivedMessage, IWorkerNotification workerNotification)
        {
            ThrowIfDisposed();
            Guard.NotNull(() => receivedMessage, receivedMessage);
            Guard.NotNull(() => workerNotification, workerNotification);

            switch (receivedMessage.Body.PayLoad)
            {
            case MessageExpressionPayloads.Action:
                HandleAction(receivedMessage, workerNotification);
                break;

            case MessageExpressionPayloads.ActionRaw:
                HandleRawAction(receivedMessage, workerNotification);
                break;

            case MessageExpressionPayloads.Function:
                HandleFunction(receivedMessage, workerNotification);
                break;

            case MessageExpressionPayloads.ActionText:
                var targetMethod =
                    _linqCompiler.CompileAction(
                        _compositeSerialization.InternalSerializer.ConvertBytesTo <LinqExpressionToRun>(
                            receivedMessage.Body.SerializedExpression));

                try
                {
                    HandleAction(targetMethod, receivedMessage, workerNotification);
                }
                catch (Exception error)     //throw the real exception if needed
                {
                    if (error.Message == "Exception has been thrown by the target of an invocation." &&
                        error.InnerException != null)
                    {
                        throw error.InnerException;
                    }
                    throw;
                }

                break;

            case MessageExpressionPayloads.FunctionText:
                var targetFunction =
                    _linqCompiler.CompileFunction(
                        _compositeSerialization.InternalSerializer.ConvertBytesTo <LinqExpressionToRun>(
                            receivedMessage.Body.SerializedExpression));

                try
                {
                    HandleFunction(targetFunction, receivedMessage, workerNotification);
                }
                catch (Exception error)     //throw the real exception if needed
                {
                    if (error.Message == "Exception has been thrown by the target of an invocation." &&
                        error.InnerException != null)
                    {
                        throw error.InnerException;
                    }
                    throw;
                }

                break;

            default:
                throw new DotNetWorkQueueException($"The method type of {receivedMessage.Body.PayLoad} is not implemented");
            }
        }