예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TraceRecord"/> class.
 /// </summary>
 /// <param name="request">
 /// The request.
 /// </param>
 /// <param name="category">
 /// The category.
 /// </param>
 /// <param name="level">
 /// The level.
 /// </param>
 public TraceRecord(HandlerRequest request, string category, TraceLevel level)
 {
     this.Timestamp = DateTime.UtcNow;
     this.Request = request;
     this.RequestId = request != null ? request.Id : Guid.Empty;
     this.Category = category;
     this.Level = level;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HandlerRequest"/> class. 
 /// The request will be a child request of the <paramref name="parentRequest"/>.
 /// </summary> 
 /// <param name="configuration">The configuration.</param>
 /// <param name="command">The command.</param>
 /// <param name="parentRequest">The parent request. </param>
 public CommandHandlerRequest(ProcessorConfiguration configuration, ICommand command, HandlerRequest parentRequest)
     : base(configuration, parentRequest)
 {
     if (command == null)
     {
         throw Error.ArgumentNull("command");
     }
     
     this.Command = command;
     this.MessageType = command.GetType();
     this.ModelState = new ModelStateDictionary();
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HandlerRequest"/> class. 
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="event">The event.</param>
        /// <param name="parentRequest">The parent request. </param>
        public EventHandlerRequest(ProcessorConfiguration configuration, IEvent @event, HandlerRequest parentRequest)
            : base(configuration, parentRequest)
        {
            if (@event == null)
            {
                throw Error.ArgumentNull("event");
            }

            // Events cannot be called without a parent request
            if (parentRequest == null)
            {
                throw Error.ArgumentNull("parentRequest");
            }

            this.Event = @event;
            this.MessageType = @event.GetType();
        }
        public void WhenInvokingFilterWithoutExceptionThenTransactionCompletes()
        {
            // Arrange
            TransactionFilterAttribute filter = new TransactionFilterAttribute();
            HandlerRequest request = new HandlerRequest(this.config, null);
            CommandHandlerContext executingContext = new CommandHandlerContext();

            CommandHandlerExecutedContext executedContext = new CommandHandlerExecutedContext(executingContext, null);
            executingContext.Response = new HandlerResponse(null);

            // Act
            filter.OnCommandExecuting(executingContext);
            Transaction transaction = Transaction.Current.Clone();
            filter.OnCommandExecuted(executedContext);

            // Assert 
            Assert.Equal(TransactionStatus.Committed, transaction.TransactionInformation.Status);
        }
예제 #5
0
        /// <summary>
        /// Writes a trace to <see cref="System.Diagnostics.Trace"/> if the
        /// <paramref name="level"/> is greater than or equal <see cref="MinimumLevel"/>.
        /// </summary>
        /// <param name="request">The <see cref="HandlerRequest"/> associated with this trace. 
        /// It may be <c>null</c> but the resulting trace will contain no correlation ID.</param>
        /// <param name="category">The category for the trace. This can be any user-defined
        /// value. It is not interpreted by this implementation but is written to the trace.</param>
        /// <param name="level">The <see cref="TraceLevel"/> of this trace. If it is less than
        /// <see cref="MinimumLevel"/>, this trace request will be ignored.</param>
        /// <param name="traceAction">The user callback to invoke to fill in a <see cref="TraceRecord"/>
        /// with additional information to add to the trace.</param>
        public virtual void Trace(HandlerRequest request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            if (category == null)
            {
                throw Error.ArgumentNull("category");
            }

            if (traceAction == null)
            {
                throw Error.ArgumentNull("traceAction");
            }

            if (level < TraceLevel.Off || level > TraceLevel.Fatal)
            {
                throw Error.ArgumentOutOfRange("level", level, Resources.TraceLevelOutOfRange);
            }

            if (this.MinimumLevel == TraceLevel.Off || level < this.MinimumLevel)
            {
                return;
            }

            if (request != null)
            {
            }

            TraceRecord traceRecord = new TraceRecord(request, category, level);
            traceAction(traceRecord);
            string message = this.Format(traceRecord);
            if (!string.IsNullOrEmpty(message))
            {
                // Level may have changed in Translate above
                this.TraceMessage(traceRecord.Level, message);
            }
        }
예제 #6
0
 /// <summary>
 /// Writes a <see cref="TraceRecord"/> at <see cref="TraceLevel.Fatal"/> with the given <paramref name="exception"/>.
 /// </summary>
 /// <param name="traceWriter">
 /// The <see cref="ITraceWriter"/>.
 /// </param>
 /// <param name="request">
 /// The <see cref="HandlerRequest"/> with which to correlate the request.
 ///     It may be null, but if so will not be correlated with any request.
 /// </param>
 /// <param name="category">
 /// The category for the trace.
 /// </param>
 /// <param name="exception">
 /// The exception to trace.
 /// </param>
 public static void Fatal(this ITraceWriter traceWriter, HandlerRequest request, string category, Exception exception)
 {
     Trace(traceWriter, request, category, TraceLevel.Fatal, exception);
 }
예제 #7
0
 /// <summary>
 /// Writes a <see cref="TraceRecord"/> at <see cref="TraceLevel.Fatal"/> with the given message.
 /// </summary>
 /// <param name="traceWriter">
 /// The <see cref="ITraceWriter"/>.
 /// </param>
 /// <param name="request">
 /// The <see cref="HandlerRequest"/> with which to correlate the request.
 ///     It may be null, but if so will not be correlated with any request.
 /// </param>
 /// <param name="category">
 /// The category for the trace.
 /// </param>
 /// <param name="messageFormat">
 /// The string to use to format a message.  It may not be null.
 /// </param>
 /// <param name="messageArguments">
 /// Optional list of arguments for the <paramref name="messageFormat"/>.
 /// </param>
 public static void Fatal(this ITraceWriter traceWriter, HandlerRequest request, string category, string messageFormat, params object[] messageArguments)
 {
     Trace(traceWriter, request, category, TraceLevel.Fatal, messageFormat, messageArguments);
 }
예제 #8
0
 /// <summary>
 /// Writes a <see cref="TraceRecord"/> at <see cref="TraceLevel.Error"/> with the given message and exception.
 /// </summary>
 /// <param name="traceWriter">
 /// The <see cref="ITraceWriter"/>.
 /// </param>
 /// <param name="request">
 /// The <see cref="HandlerRequest"/> with which to correlate the request.
 ///     It may be null, but if so will not be correlated with any request.
 /// </param>
 /// <param name="category">
 /// The category for the trace.
 /// </param>
 /// <param name="exception">
 /// The exception to trace.
 /// </param>
 /// <param name="messageFormat">
 /// The string to use to format a message.  It may not be null.
 /// </param>
 /// <param name="messageArguments">
 /// Optional list of arguments for the <paramref name="messageFormat"/>.
 /// </param>
 public static void Error(this ITraceWriter traceWriter, HandlerRequest request, string category, Exception exception, string messageFormat, params object[] messageArguments)
 {
     Trace(traceWriter, request, category, TraceLevel.Error, exception, messageFormat, messageArguments);
 }
예제 #9
0
 private static void TraceError(this ITraceWriter traceWriter, Exception exception, HandlerRequest request, string category, string operatorName, string operationName, Action <TraceRecord> errorTrace)
 {
     Contract.Requires(traceWriter != null);
     traceWriter.Trace(
         request,
         category,
         TraceLevel.Error,
         traceRecord =>
     {
         traceRecord.Kind      = TraceKind.End;
         traceRecord.Operator  = operatorName;
         traceRecord.Operation = operationName;
         traceRecord.Exception = exception;
         if (errorTrace != null)
         {
             errorTrace(traceRecord);
         }
     });
 }