Defines a method to be executed; the linq expression will be compiled when consumed.
The caller must explicitly specify DLL references and using statements.
コード例 #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)
 {
     using (_compileFunctionTimer.NewContext())
     {
         return _handler.CompileFunction(linqExpression);
     }
 }
コード例 #2
0
        /// <summary>
        /// Compiles the input linqExpression into a Linq expression tree
        /// </summary>
        /// <param name="linqExpression">The linqExpression.</param>
        /// <returns></returns>
        public Action<object, object> CompileAction(LinqExpressionToRun linqExpression)
        {
            if (linqExpression.Unique) //don't bother caching
            {
                _counterActionCacheUnique.Increment();
                return _handler.CompileAction(linqExpression);
            }

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

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

            result = _handler.CompileAction(linqExpression);
            if (!_cache.Contains(key))
            {
                _counterActionCacheMiss.Increment(key);
                _cache.Add(key, result, _itemPolicy);
            }

            return result;
        }
コード例 #3
0
 internal ScheduledJob(JobScheduler scheduler,
     string name,
     IJobSchedule schedule,
     IProducerMethodJobQueue queue,
     LinqExpressionToRun expressionToRun,
     IGetTime time,
     string route
    )
 {
     _scheduler = scheduler;
     Name = name;
     Schedule = schedule;
     _queue = queue;
     _expressionToRun = expressionToRun;
     _getTime = time;
     Route = route;
 }
コード例 #4
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)
 {
     Guard.NotNull(() => linqExpression, linqExpression);
     Guard.NotNullOrEmpty(() => linqExpression.Linq, linqExpression.Linq);
     var compiler = _objectPool.GetObject();
     try
     {
         return compiler.CompileFunction(linqExpression);
     }
     catch (Exception error)
     {
         throw new CompileException($"Failed to compile linq expression [{linqExpression.Linq}]", error,
             linqExpression.Linq);
     }
     finally
     {
         _objectPool.ReturnObject(compiler);
     }
 }
コード例 #5
0
 /// <summary>
 /// Sends the specified linqExpression for execution.
 /// </summary>
 /// <param name="linqExpression">The linqExpression.</param>
 /// <param name="timeOut">The time out.</param>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 /// <remarks>Your expression must return a type of object, or the JSON serializer may throw casting errors</remarks>
 public async Task<IReceivedMessage<object>> SendAsync(LinqExpressionToRun linqExpression, TimeSpan timeOut,
     IAdditionalMessageData data = null)
 {
     var message = new MessageExpression(MessageExpressionPayloads.FunctionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression));
     return await _queue.SendAsync(message, timeOut, data).ConfigureAwait(false);
 }
コード例 #6
0
 /// <summary>
 /// Sends the specified linqExpression for execution.
 /// </summary>
 /// <param name="linqExpression">The linqExpression.</param>
 /// <param name="timeOut">The time out.</param>
 /// <param name="data">The data.</param>
 /// <returns></returns>
 /// <remarks>Your expression must return a type of object, or the JSON serializer may throw casting errors</remarks>
 public IReceivedMessage<object> Send(LinqExpressionToRun linqExpression, TimeSpan timeOut, IAdditionalMessageData data = null)
 {
     var message = new MessageExpression(MessageExpressionPayloads.FunctionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression));
     return _queue.Send(message, timeOut, data);
 }
コード例 #7
0
        /// <summary>
        /// Sends the specified action to the specified queue.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="scheduledTime">The scheduled time.</param>
        /// <param name="expressionToRun">The expression to run.</param>
        /// <returns></returns>
        public async Task<IJobQueueOutputMessage> SendAsync(IScheduledJob job, DateTimeOffset scheduledTime, LinqExpressionToRun expressionToRun)
        {
            var data = SendPreChecks(job.Name, scheduledTime);
            if (data != null)
                return data;

            var messageData = new AdditionalMessageData();
            SetMetaDataForJob(job.Name, scheduledTime,
                new DateTimeOffset(GetTimeFactory.Create().GetCurrentUtcDate()), job.Route, messageData);

            var message = await Queue.SendAsync(expressionToRun, messageData).ConfigureAwait(false);
            var result = ProcessResult(job, scheduledTime, message);
            if (result != null) return result;
            //try one more time
            result = ProcessResult(job, scheduledTime,
                await Queue.SendAsync(expressionToRun, messageData).ConfigureAwait(false));
            return result ?? new JobQueueOutputMessage(JobQueuedStatus.Failed);
        }
コード例 #8
0
 /// <summary>
 /// Generates a key for the cache
 /// </summary>
 /// <param name="linqExpression">The linq expression.</param>
 /// <returns></returns>
 private string GenerateKey(LinqExpressionToRun linqExpression)
 {
     var builder = new StringBuilder();
     builder.Append(linqExpression.Linq);
     foreach (var field in linqExpression.References)
     {
         builder.Append(field);
         builder.Append("|");
     }
     foreach (var field in linqExpression.Usings)
     {
         builder.Append(field);
         builder.Append("|");
     }
     return builder.ToString();
 }
コード例 #9
0
 /// <summary>
 /// Sends the specified linqExpression to be executed. Additional message meta data is optional.
 /// </summary>
 /// <param name="linqExpression">The linqExpression to execute.</param>
 /// <param name="data">The optional additional message data.</param>
 /// <returns></returns>
 public async Task<IQueueOutputMessage> SendAsync(LinqExpressionToRun linqExpression, IAdditionalMessageData data = null)
 {
     var message = new MessageExpression(MessageExpressionPayloads.ActionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression));
     return await _queue.SendAsync(message, data).ConfigureAwait(false);
 }
コード例 #10
0
 /// <summary>
 /// Sends the specified linqExpression to be executed. Additional message meta data is optional.
 /// </summary>
 /// <param name="linqExpression">The linqExpression to execute.</param>
 /// <param name="data">The optional additional message data.</param>
 /// <returns></returns>
 public IQueueOutputMessage Send(LinqExpressionToRun linqExpression, IAdditionalMessageData data = null)
 {
     var message = new MessageExpression(MessageExpressionPayloads.ActionText,
         _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression));
     return _queue.Send(message, data);
 }
コード例 #11
0
 /// <summary>
 /// Sends the specified dynamic linqExpression to be executed.
 /// </summary>
 /// <param name="job">The job.</param>
 /// <param name="scheduledTime">The scheduled time.</param>
 /// <param name="linqExpression">The linqExpression to execute.</param>
 /// <returns></returns>
 public async Task<IJobQueueOutputMessage> SendAsync(IScheduledJob job, DateTimeOffset scheduledTime, LinqExpressionToRun linqExpression)
 {
     if(!_started) throw new DotNetWorkQueueException("Start must be called before sending jobs");
     return await _sendJobToQueue.SendAsync(job, scheduledTime, linqExpression).ConfigureAwait(false);
 }
コード例 #12
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)
 {
     _compiler.References = DefaultReferences.Union(linqExpression.References).ToArray();
     _compiler.Usings = DefaultUsings.Union(linqExpression.Usings).ToArray();
     return _compiler.ParseLambdaExpr<Func<object, object, object>>(linqExpression.Linq).Compile();
 }