public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { HttpContentHeaders contentHeaders = content == null ? null : content.Headers; MediaTypeHeaderValue contentType = contentHeaders == null ? null : contentHeaders.ContentType; return(TraceWriter.TraceBeginEndAsync( Request, TraceCategories.FormattingCategory, TraceLevel.Info, InnerFormatter.GetType().Name, WriteToStreamAsyncMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceWriteToStreamMessage, FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture), type.Name, contentType == null ? SRResources.TraceNoneObjectMessage : contentType.ToString()); }, execute: () => InnerFormatter.WriteToStreamAsync(type, value, writeStream, content, transportContext), endTrace: null, errorTrace: null)); }
Task <HttpResponseMessage> IActionFilter.ExecuteActionFilterAsync( HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation ) { return(TraceWriter.TraceBeginEndAsync <HttpResponseMessage>( actionContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info, InnerActionFilter.GetType().Name, ExecuteActionFilterAsyncMethodName, beginTrace: null, execute: () => InnerActionFilter.ExecuteActionFilterAsync( actionContext, cancellationToken, continuation ), endTrace: (tr, response) => { if (response != null) { tr.Status = response.StatusCode; } }, errorTrace: null )); }
public override Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { HttpContentHeaders contentHeaders = content == null ? null : content.Headers; MediaTypeHeaderValue contentType = contentHeaders == null ? null : contentHeaders.ContentType; return(TraceWriter.TraceBeginEndAsync <object>( Request, TraceCategories.FormattingCategory, TraceLevel.Info, InnerFormatter.GetType().Name, ReadFromStreamAsyncMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceReadFromStreamMessage, type.Name, contentType == null ? SRResources.TraceNoneObjectMessage : contentType.ToString()); }, execute: () => InnerFormatter.ReadFromStreamAsync(type, readStream, content, formatterLogger), endTrace: (tr, value) => { tr.Message = Error.Format( SRResources.TraceReadFromStreamValueMessage, FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture)); }, errorTrace: null)); }
public Task ExecuteExceptionFilterAsync( HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken ) { return(TraceWriter.TraceBeginEndAsync( actionExecutedContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info, InnerExceptionFilter.GetType().Name, ExecuteExceptionFilterAsyncMethodName, beginTrace: (tr) => { tr.Exception = actionExecutedContext.Exception; }, execute: () => InnerExceptionFilter.ExecuteExceptionFilterAsync( actionExecutedContext, cancellationToken ), endTrace: (tr) => { tr.Exception = actionExecutedContext.Exception; }, errorTrace: null )); }
public Task AuthenticateAsync( HttpAuthenticationContext context, CancellationToken cancellationToken ) { IPrincipal originalPrincipal = null; return(TraceWriter.TraceBeginEndAsync( request: context != null ? context.Request : null, category: TraceCategories.FiltersCategory, level: TraceLevel.Info, operatorName: _innerFilter.GetType().Name, operationName: AuthenticateAsyncMethodName, beginTrace: (tr) => { if (context != null) { originalPrincipal = context.Principal; } }, execute: () => _innerFilter.AuthenticateAsync(context, cancellationToken), endTrace: (tr) => { if (context != null) { if (context.ErrorResult != null) { tr.Message = String.Format( CultureInfo.CurrentCulture, SRResources.AuthenticationFilterErrorResult, context.ErrorResult ); } else if (context.Principal != originalPrincipal) { if (context.Principal == null || context.Principal.Identity == null) { tr.Message = SRResources.AuthenticationFilterSetPrincipalToUnknownIdentity; } else { tr.Message = String.Format( CultureInfo.CurrentCulture, SRResources.AuthenticationFilterSetPrincipalToKnownIdentity, context.Principal.Identity.Name, context.Principal.Identity.AuthenticationType ); } } else { tr.Message = SRResources.AuthenticationFilterDidNothing; } } }, errorTrace: null )); }
public override Task ExecuteBindingAsync( ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken ) { return(TraceWriter.TraceBeginEndAsync( actionContext.Request, TraceCategories.ModelBindingCategory, TraceLevel.Info, InnerBinding.GetType().Name, ExecuteBindingAsyncMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceBeginParameterBind, InnerBinding.Descriptor.ParameterName ); }, execute: () => InnerBinding.ExecuteBindingAsync( metadataProvider, actionContext, cancellationToken ), endTrace: (tr) => { string parameterName = InnerBinding.Descriptor.ParameterName; // Model binding error for this parameter shows the error if ( !actionContext.ModelState.IsValid && actionContext.ModelState.ContainsKey(parameterName) ) { tr.Message = Error.Format( SRResources.TraceModelStateInvalidMessage, FormattingUtilities.ModelStateToString(actionContext.ModelState) ); } else { tr.Message = actionContext.ActionArguments.ContainsKey(parameterName) ? Error.Format( SRResources.TraceEndParameterBind, parameterName, FormattingUtilities.ValueToString( actionContext.ActionArguments[parameterName], CultureInfo.CurrentCulture ) ) : Error.Format(SRResources.TraceEndParameterBindNoBind, parameterName); } }, errorTrace: null )); }
public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) { return(TraceWriter.TraceBeginEndAsync( request: context != null ? context.Request : null, category: TraceCategories.FiltersCategory, level: TraceLevel.Info, operatorName: _innerFilter.GetType().Name, operationName: ChallengeAsyncMethodName, beginTrace: null, execute: () => _innerFilter.ChallengeAsync(context, cancellationToken), endTrace: null, errorTrace: null)); }
private Task <object> ReadFromStreamAsyncCore(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken?cancellationToken) { HttpContentHeaders contentHeaders = content == null ? null : content.Headers; MediaTypeHeaderValue contentType = contentHeaders == null ? null : contentHeaders.ContentType; IFormatterLogger formatterLoggerTraceWrapper = (formatterLogger == null) ? null : new FormatterLoggerTraceWrapper(formatterLogger, TraceWriter, Request, InnerFormatter.GetType().Name, ReadFromStreamAsyncMethodName); return(TraceWriter.TraceBeginEndAsync <object>( Request, TraceCategories.FormattingCategory, TraceLevel.Info, InnerFormatter.GetType().Name, ReadFromStreamAsyncMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceReadFromStreamMessage, type.Name, contentType == null ? SRResources.TraceNoneObjectMessage : contentType.ToString()); }, execute: () => { if (cancellationToken.HasValue) { return InnerFormatter.ReadFromStreamAsync(type, readStream, content, formatterLoggerTraceWrapper, cancellationToken.Value); } else { return InnerFormatter.ReadFromStreamAsync(type, readStream, content, formatterLoggerTraceWrapper); } }, endTrace: (tr, value) => { tr.Message = Error.Format( SRResources.TraceReadFromStreamValueMessage, FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture)); }, errorTrace: null)); }