当前位置: 首页>>代码示例>>C#>>正文


C# NancyContext.WriteTraceLog方法代码示例

本文整理汇总了C#中NancyContext.WriteTraceLog方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.WriteTraceLog方法的具体用法?C# NancyContext.WriteTraceLog怎么用?C# NancyContext.WriteTraceLog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NancyContext的用法示例。


在下文中一共展示了NancyContext.WriteTraceLog方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NegotiateResponse

        /// <summary>
        /// Negotiates the response based on the given result and context.
        /// </summary>
        /// <param name="routeResult">The route result.</param>
        /// <param name="context">The context.</param>
        /// <returns>A <see cref="Response" />.</returns>
        public Response NegotiateResponse(dynamic routeResult, NancyContext context)
        {
            Response response;
            if (TryCastResultToResponse(routeResult, out response))
            {
                context.WriteTraceLog(sb =>
                    sb.AppendLine("[DefaultResponseNegotiator] Processing as real response"));

                return response;
            }

            context.WriteTraceLog(sb =>
                sb.AppendLine("[DefaultResponseNegotiator] Processing as negotiation"));

            NegotiationContext negotiationContext = GetNegotiationContext(routeResult, context);

            var coercedAcceptHeaders = this.GetCoercedAcceptHeaders(context).ToArray();

            context.WriteTraceLog(sb => GetAccepHeaderTraceLog(context, negotiationContext, coercedAcceptHeaders, sb));

            var compatibleHeaders = this.GetCompatibleHeaders(coercedAcceptHeaders, negotiationContext, context).ToArray();

            if (!compatibleHeaders.Any())
            {
                context.WriteTraceLog(sb =>
                    sb.AppendLine("[DefaultResponseNegotiator] Unable to negotiate response - no headers compatible"));

                return new NotAcceptableResponse();
            }

            return CreateResponse(compatibleHeaders, negotiationContext, context);
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:38,代码来源:DefaultResponseNegotiator.cs

示例2: Invoke

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> instance that represents the result of the invoked route.</returns>
        public async Task<Response> Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context)
        {
            object result;

            try
            {
                result = await route.Invoke(parameters, cancellationToken).ConfigureAwait(false);
            }
            catch(RouteExecutionEarlyExitException earlyExitException)
            {
                context.WriteTraceLog(
                    sb => sb.AppendFormat(
                            "[DefaultRouteInvoker] Caught RouteExecutionEarlyExitException - reason {0}",
                            earlyExitException.Reason));
                return earlyExitException.Response;
            }

            if (!(result is ValueType) && result == null)
            {
                context.WriteTraceLog(
                    sb => sb.AppendLine("[DefaultRouteInvoker] Invocation of route returned null"));

                result = new Response();
            }

            return this.negotiator.NegotiateResponse(result, context);
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:35,代码来源:DefaultRouteInvoker.cs

示例3: Invoke

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> instance that represents the result of the invoked route.</returns>
        public Task<Response> Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context)
        {
            var tcs = new TaskCompletionSource<Response>();

            var result = route.Invoke(parameters, cancellationToken);

            result.WhenCompleted(
                completedTask =>
                {
                    var returnResult = completedTask.Result;
                    if (!(returnResult is ValueType) && returnResult == null)
                    {
                        context.WriteTraceLog(
                            sb => sb.AppendLine("[DefaultRouteInvoker] Invocation of route returned null"));

                        returnResult = new Response();
                    }

                    try
                    {
                        var response = this.negotiator.NegotiateResponse(returnResult, context);

                        tcs.SetResult(response);
                    }
                    catch (Exception e)
                    {
                        tcs.SetException(e);
                    }
                },
                faultedTask =>
                {
                    var earlyExitException = GetEarlyExitException(faultedTask);

                    if (earlyExitException != null)
                    {
                        context.WriteTraceLog(
                            sb =>
                            sb.AppendFormat(
                                "[DefaultRouteInvoker] Caught RouteExecutionEarlyExitException - reason {0}",
                                earlyExitException.Reason));
                        tcs.SetResult(earlyExitException.Response);
                    }
                    else
                    {
                        tcs.SetException(faultedTask.Exception);
                    }
                });

            return tcs.Task;
        }
开发者ID:jbattermann,项目名称:Nancy,代码行数:58,代码来源:DefaultRouteInvoker.cs

示例4: Invoke

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> intance that represents the result of the invoked route.</returns>
        public Response Invoke(Route route, DynamicDictionary parameters, NancyContext context)
        {
            var result = route.Invoke(parameters);

            if (result == null)
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Invocation of route returned null"));
                result = new Response();
            }

            return this.InvokeRouteWithStrategy(result, context);
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:19,代码来源:DefaultRouteInvoker.cs

示例5: Invoke

        /// <summary>
        /// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
        /// </summary>
        /// <param name="route">The route that should be invoked.</param>
        /// <param name="parameters">The parameters that the route should be invoked with.</param>
        /// <param name="context">The context of the route that is being invoked.</param>
        /// <returns>A <see cref="Response"/> intance that represents the result of the invoked route.</returns>
        public Response Invoke(Route route, DynamicDictionary parameters, NancyContext context)
        {
            dynamic result;

            try
            {
                result = route.Invoke(parameters);
            }
            catch (RouteExecutionEarlyExitException earlyExitException)
            {
                context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Caught RouteExecutionEarlyExitException - reason {0}", earlyExitException.Reason));
                result = earlyExitException.Response;
            }

            if (result == null)
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Invocation of route returned null"));
                result = new Response();
            }

            return this.InvokeRouteWithStrategy(result, context);
        }
开发者ID:pauloortins,项目名称:Nancy,代码行数:29,代码来源:DefaultRouteInvoker.cs

示例6: ProcessAsNegotiator

        private Response ProcessAsNegotiator(object routeResult, NancyContext context)
        {
            context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Processing as negotiation"));

            var negotiator =
                GetNegotiator(routeResult, context);

            context.WriteTraceLog(sb =>
            {
                var allowableFormats = negotiator.NegotiationContext
                    .PermissableMediaRanges
                    .Select(mr => mr.ToString())
                    .Aggregate((t1, t2) => t1 + ", " + t2);

                var acceptFormants = context.Request.Headers["accept"]
                                                    .Aggregate((t1, t2) => t1 + ", " + t2);

                sb.AppendFormat("[DefaultRouteInvoker] Accept header: {0}\n", acceptFormants);
                sb.AppendFormat("[DefaultRouteInvoker] Acceptable media ranges: {0}\n", allowableFormats);
            });

            var compatibleHeaders =
                this.GetCompatibleHeaders(context, negotiator);

            if (!compatibleHeaders.Any())
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Unable to negotiate response - no headers compatible"));

                return new NotAcceptableResponse();
            }

            var response =
                NegotiateResponse(compatibleHeaders, routeResult, negotiator, context);

            if (response == null)
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Unable to negotiate response - no processors returned valid response"));

                response = new NotAcceptableResponse();
            }

            if (compatibleHeaders.Count() > 1)
            {
                response.WithHeader("Vary", "Accept");
            }

            AddLinkHeaders(context, compatibleHeaders, response);

            if (!(response is NotAcceptableResponse))
            {
                AddNegotiatedHeaders(negotiator, response);
            }

            return response;
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:55,代码来源:DefaultRouteInvoker.cs

示例7: SafeInvokeResponseProcessor

        private static Response SafeInvokeResponseProcessor(IResponseProcessor responseProcessor, MediaRange mediaRange, object model, NancyContext context)
        {
            try
            {
                return responseProcessor.Process(mediaRange, model, context);
            }
            catch (Exception e)
            {
                context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Processor threw {0} exception: {1}", e.GetType(), e.Message));
            }

            return null;
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:13,代码来源:DefaultRouteInvoker.cs

示例8: ProcessAsRealResponse

        private static Response ProcessAsRealResponse(dynamic routeResult, NancyContext context)
        {
            context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Processing as real response"));

            return (Response)routeResult;
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:6,代码来源:DefaultRouteInvoker.cs

示例9: NegotiateResponse

        private static Response NegotiateResponse(IEnumerable<Tuple<string, IEnumerable<Tuple<IResponseProcessor, ProcessorMatch>>>> compatibleHeaders, object model, Negotiator negotiator, NancyContext context)
        {
            foreach (var compatibleHeader in compatibleHeaders)
            {
                var prioritizedProcessors = compatibleHeader.Item2
                    .OrderByDescending(x => x.Item2.ModelResult)
                    .ThenByDescending(x => x.Item2.RequestedContentTypeResult);

                foreach (var prioritizedProcessor in prioritizedProcessors)
                {
                    var processorType = prioritizedProcessor.Item1.GetType();
                    context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Invoking processor: {0}\n", processorType));

                    var response =
                        SafeInvokeResponseProcessor(prioritizedProcessor.Item1, compatibleHeader.Item1, negotiator.NegotiationContext.GetModelForMediaRange(compatibleHeader.Item1), context);

                    if (response != null)
                    {
                        return response;
                    }
                }
            }

            return null;
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:25,代码来源:DefaultRouteInvoker.cs

示例10: GetNegotiator

        private static Negotiator GetNegotiator(object routeResult, NancyContext context)
        {
            var negotiator = routeResult as Negotiator;

            if (negotiator == null)
            {
                context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Wrapping result of type {0} in negotiator\n", routeResult.GetType()));

                negotiator = new Negotiator(context);
                negotiator.WithModel(routeResult);
            }

            return negotiator;
        }
开发者ID:JelleHissink,项目名称:Nancy,代码行数:14,代码来源:DefaultRouteInvoker.cs

示例11: ProcessAsNegotiator

        private Response ProcessAsNegotiator(object routeResult, NancyContext context)
        {
            context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Processing as negotiation"));

            var negotiator =
                GetNegotiator(routeResult, context);

            var coercedAcceptHeaders = this.GetCoercedAcceptHeaders(context).ToArray();

            context.WriteTraceLog(sb =>
            {
                var allowableFormats = negotiator.NegotiationContext
                    .PermissableMediaRanges
                    .Select(mr => mr.ToString())
                    .Aggregate((t1, t2) => t1 + ", " + t2);

                var originalAccept = context.Request.Headers["accept"].Any()
                                         ? string.Join(", ", context.Request.Headers["accept"])
                                         : "None";

                var coercedAccept = coercedAcceptHeaders.Any() ?
                                        coercedAcceptHeaders.Select(h => h.Item1).Aggregate((t1, t2) => t1 + ", " + t2) :
                                        "None";

                sb.AppendFormat("[DefaultRouteInvoker] Original accept header: {0}\n", originalAccept);
                sb.AppendFormat("[DefaultRouteInvoker] Coerced accept header: {0}\n", coercedAccept);
                sb.AppendFormat("[DefaultRouteInvoker] Acceptable media ranges: {0}\n", allowableFormats);
            });

            var compatibleHeaders = this.GetCompatibleHeaders(coercedAcceptHeaders, context, negotiator);

            if (!compatibleHeaders.Any())
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Unable to negotiate response - no headers compatible"));

                return new NotAcceptableResponse();
            }

            var response =
                NegotiateResponse(compatibleHeaders, routeResult, negotiator, context);

            if (response == null)
            {
                context.WriteTraceLog(sb => sb.AppendLine("[DefaultRouteInvoker] Unable to negotiate response - no processors returned valid response"));

                response = new NotAcceptableResponse();
            }

            response.WithHeader("Vary", "Accept");

            AddLinkHeaders(context, compatibleHeaders, response);

            if (!(response is NotAcceptableResponse))
            {
                AddNegotiatedHeaders(negotiator, response);
            }

            if (negotiator.NegotiationContext.StatusCode.HasValue)
            {
                response.StatusCode = negotiator.NegotiationContext.StatusCode.Value;
            }

            foreach (var cookie in negotiator.NegotiationContext.Cookies)
            {
                response.Cookies.Add(cookie);
            }

            return response;
        }
开发者ID:grammarware,项目名称:fodder,代码行数:69,代码来源:src_Nancy_Routing_DefaultRouteInvoker.cs

示例12: CreateResponse

        /// <summary>
        /// Creates a response from the compatible headers.
        /// </summary>
        /// <param name="compatibleHeaders">The compatible headers.</param>
        /// <param name="negotiationContext">The negotiation context.</param>
        /// <param name="context">The context.</param>
        /// <returns>A <see cref="Response"/>.</returns>
        private static Response CreateResponse(
            IList<CompatibleHeader> compatibleHeaders,
            NegotiationContext negotiationContext,
            NancyContext context)
        {
            var response = NegotiateResponse(compatibleHeaders, negotiationContext, context);

            if (response == null)
            {
                context.WriteTraceLog(sb =>
                    sb.AppendLine("[DefaultResponseNegotiator] Unable to negotiate response - no processors returned valid response"));

                response = new NotAcceptableResponse();
            }

            response.WithHeader("Vary", "Accept");

            AddLinkHeader(compatibleHeaders, response, context.Request.Url);
            SetStatusCode(negotiationContext, response);
            SetReasonPhrase(negotiationContext, response);
            AddCookies(negotiationContext, response);

            if (response is NotAcceptableResponse)
            {
                return response;
            }

            AddContentTypeHeader(negotiationContext, response);
            AddNegotiatedHeaders(negotiationContext, response);

            return response;
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:39,代码来源:DefaultResponseNegotiator.cs


注:本文中的NancyContext.WriteTraceLog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。