本文整理汇总了C#中Nancy.Responses.Negotiation.MediaRange.Matches方法的典型用法代码示例。如果您正苦于以下问题:C# MediaRange.Matches方法的具体用法?C# MediaRange.Matches怎么用?C# MediaRange.Matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Responses.Negotiation.MediaRange
的用法示例。
在下文中一共展示了MediaRange.Matches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (model is SparqlQueryProcessingModel)
{
var processingModel = model as SparqlQueryProcessingModel;
if (processingModel.SparqlRequest.Format != null)
{
var sparqlFormat =
processingModel.SparqlRequest.Format.Select(SparqlResultsFormat.GetResultsFormat)
.FirstOrDefault();
var graphFormat =
processingModel.SparqlRequest.Format.Select(RdfFormat.GetResultsFormat)
.FirstOrDefault();
processingModel.OverrideSparqlFormat = sparqlFormat;
processingModel.OverrideGraphFormat = graphFormat;
if (sparqlFormat != null || graphFormat != null)
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
}
if ((processingModel.ResultModel == SerializableModel.SparqlResultSet) &&
(SparqlResultsFormat.AllMediaTypes.Any(m => requestedMediaRange.Matches(MediaRange.FromString(m)))))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
if ((processingModel.ResultModel == SerializableModel.RdfGraph) &&
(RdfFormat.AllMediaTypes.Any(m => requestedMediaRange.Matches(MediaRange.FromString(m)))))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.NoMatch,
RequestedContentTypeResult = MatchResult.DontCare
};
}
示例2: Process
public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var queryModel = model as SparqlQueryProcessingModel;
var format = queryModel.OverrideSparqlFormat ??
SparqlResultsFormat.AllFormats.FirstOrDefault(
f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m)));
var graphFormat =
queryModel.OverrideGraphFormat ??
RdfFormat.AllFormats.FirstOrDefault(f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m)));
return new SparqlQueryResponse(queryModel, context.Request.Headers.IfModifiedSince, format, graphFormat);
}
示例3: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var graphListModel = model as GraphListModel;
if (graphListModel != null)
{
if (requestedMediaRange.Matches(JsonMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.NoMatch,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例4: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (requestedMediaRange.Matches("application/csv") || requestedMediaRange.Matches("text/csv"))
{
return new ProcessorMatch()
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例5: CanProcess
/// <summary>
/// Determines whether the the processor can handle a given content type and model.
/// </summary>
/// <param name="requestedMediaRange">Content type requested by the client.</param>
/// <param name="model">The model for the given media range.</param>
/// <param name="context">The nancy context.</param>
/// <returns>A <see cref="ProcessorMatch"/> result that determines the priority of the processor.</returns>
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var matchingContentType =
requestedMediaRange.Matches("text/html");
return matchingContentType
? new ProcessorMatch { ModelResult = MatchResult.DontCare, RequestedContentTypeResult = MatchResult.ExactMatch }
: new ProcessorMatch();
}
示例6: IsExactSirenContentType
private static bool IsExactSirenContentType(MediaRange requestedContentType)
{
if (requestedContentType.Type.IsWildcard && requestedContentType.Subtype.IsWildcard)
{
return true;
}
return requestedContentType.Matches("application/vnd.siren+json");
}
示例7: IsExactPdfContentType
private static bool IsExactPdfContentType(MediaRange requestedContentType)
{
if (requestedContentType.Type.IsWildcard && requestedContentType.Subtype.IsWildcard)
{
return true;
}
return requestedContentType.Matches("application/pdf");
}
示例8: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (requestedMediaRange.Matches(MediaRange.FromString("text/plain")) && model is Quip)
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch { ModelResult = MatchResult.DontCare, RequestedContentTypeResult = MatchResult.NoMatch };
}
示例9: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (requestedMediaRange.Matches("text/csv") && model is IEnumerable)
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例10: CanProcess
/// <summary>
/// Determines whether the the processor can handle a given content type and model.
/// </summary>
/// <param name="requestedMediaRange">Content type requested by the client.</param>
/// <param name="model">The model for the given media range.</param>
/// <param name="context">The nancy context.</param>
/// <returns>A <see cref="ProcessorMatch"/> result that determines the priority of the processor.</returns>
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (IsWildcardProtobufContentType(requestedMediaRange) || requestedMediaRange.Matches(Constants.ProtoBufContentType))
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例11: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (model is SparqlQueryProcessingModel)
{
if (SparqlResultsFormat.AllMediaTypes.Any(m => requestedMediaRange.Matches(m)))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.NoMatch,
RequestedContentTypeResult = MatchResult.DontCare
};
}
示例12: IsTextHtmlContentType
protected bool IsTextHtmlContentType(MediaRange requestedMediaRange)
{
return requestedMediaRange.Matches("text/html");
}
示例13: GetModelForMediaRange
/// <summary>
/// Gets the correct model for the given media range
/// </summary>
/// <param name="mediaRange">The <see cref="MediaRange"/> to get the model for.</param>
/// <returns>The model for the provided <paramref name="mediaRange"/> if it has been mapped, otherwise the <see cref="DefaultModel"/> will be returned.</returns>
public dynamic GetModelForMediaRange(MediaRange mediaRange)
{
var matching = this.MediaRangeModelMappings.Any(m => mediaRange.Matches(m.Key));
return matching ?
this.MediaRangeModelMappings.First(m => mediaRange.Matches(m.Key)).Value.Invoke() :
this.DefaultModel;
}
示例14: IsExactJsonContentType
private static bool IsExactJsonContentType(MediaRange requestedContentType)
{
if (requestedContentType.Type.IsWildcard && requestedContentType.Subtype.IsWildcard)
return true;
return requestedContentType.Matches("application/json") || requestedContentType.Matches("text/json");
}
示例15: Process
public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var processingModel = model as SparqlQueryProcessingModel;
if (processingModel != null)
{
var format = (processingModel.OverrideResultsFormat ??
SparqlResultsFormat.AllFormats.FirstOrDefault(
f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m)))) ??
SparqlResultsFormat.Xml;
var graphFormat =
(processingModel.OverrideGraphFormat ??
RdfFormat.AllFormats.FirstOrDefault(f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m)))) ??
RdfFormat.RdfXml;
return new SparqlQueryResponse(processingModel, context.Request.Headers.IfModifiedSince, format, graphFormat);
}
var graphList = model as GraphListModel;
if (graphList != null)
{
var format =
SparqlResultsFormat.AllFormats.FirstOrDefault(
f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m))) ?? SparqlResultsFormat.Xml;
return new TextResponse(
graphList.AsString(format), format.MediaTypes[0]);
}
throw new ArgumentException("Unexpected model type: " + model.GetType());
}