/// <summary> /// Prioritizes the response processors and tries to negotiate a response. /// </summary> /// <param name="compatibleHeaders">The compatible headers.</param> /// <param name="negotiationContext">The negotiation context.</param> /// <param name="context">The context.</param> /// <returns>Response.</returns> private static Response NegotiateResponse( IEnumerable <CompatibleHeader> compatibleHeaders, NegotiationContext negotiationContext, NancyContext context) { foreach (var compatibleHeader in compatibleHeaders) { var prioritizedProcessors = compatibleHeader.Processors .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("[DefaultResponseNegotiator] Invoking processor: {0}\n", processorType)); var mediaRangeModel = negotiationContext.GetModelForMediaRange(compatibleHeader.MediaRange); var response = prioritizedProcessor.Item1.Process(compatibleHeader.MediaRange, mediaRangeModel, context); if (response != null) { return(response); } } } return(null); }
private IEnumerable <CompatibleHeader> GetCompatibleHeaders( IEnumerable <Tuple <string, decimal> > coercedAcceptHeaders, NegotiationContext negotiationContext, NancyContext context) { var acceptHeaders = GetCompatibleHeaders(coercedAcceptHeaders, negotiationContext); foreach (var header in acceptHeaders) { var mediaRangeModel = negotiationContext.GetModelForMediaRange(header.Item1); IEnumerable <Tuple <IResponseProcessor, ProcessorMatch> > compatibleProcessors = this.GetCompatibleProcessorsByHeader(header.Item1, mediaRangeModel, context); if (compatibleProcessors.Any()) { yield return(new CompatibleHeader(header.Item1, compatibleProcessors)); } } }
private IEnumerable<CompatibleHeader> GetCompatibleHeaders( IEnumerable<Tuple<string, decimal>> coercedAcceptHeaders, NegotiationContext negotiationContext, NancyContext context) { var acceptHeaders = GetCompatibleHeaders(coercedAcceptHeaders, negotiationContext); foreach (var header in acceptHeaders) { var mediaRangeModel = negotiationContext.GetModelForMediaRange(header.Item1); IEnumerable<Tuple<IResponseProcessor, ProcessorMatch>> compatibleProcessors = this.GetCompatibleProcessorsByHeader(header.Item1, mediaRangeModel, context); if (compatibleProcessors.Any()) { yield return new CompatibleHeader(header.Item1, compatibleProcessors); } } }
/// <summary> /// Prioritizes the response processors and tries to negotiate a response. /// </summary> /// <param name="compatibleHeaders">The compatible headers.</param> /// <param name="negotiationContext">The negotiation context.</param> /// <param name="context">The context.</param> /// <returns>Response.</returns> private static Response NegotiateResponse( IEnumerable<CompatibleHeader> compatibleHeaders, NegotiationContext negotiationContext, NancyContext context) { foreach (var compatibleHeader in compatibleHeaders) { var prioritizedProcessors = compatibleHeader.Processors .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("[DefaultResponseNegotiator] Invoking processor: {0}\n", processorType)); var mediaRangeModel = negotiationContext.GetModelForMediaRange(compatibleHeader.MediaRange); var response = prioritizedProcessor.Item1.Process(compatibleHeader.MediaRange, mediaRangeModel, context); if (response != null) { return response; } } } return null; }