本文整理汇总了C#中Nancy.Responses.Negotiation.MediaRange类的典型用法代码示例。如果您正苦于以下问题:C# MediaRange类的具体用法?C# MediaRange怎么用?C# MediaRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaRange类属于Nancy.Responses.Negotiation命名空间,在下文中一共展示了MediaRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 ProcessorMatch result that determines the priority of the processor</returns>
public override ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (model as PomonaResponse == null)
return new ProcessorMatch
{
ModelResult = MatchResult.NoMatch,
RequestedContentTypeResult = MatchResult.DontCare
};
//if (IsTextHtmlContentType(requestedMediaRange))
// return new ProcessorMatch
// {
// ModelResult = MatchResult.ExactMatch,
// RequestedContentTypeResult = MatchResult.ExactMatch
// };
if (IsExactCsvContentType(requestedMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例2: 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 ProcessorMatch result that determines the priority of the processor</returns>
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (model is FeatureCollection)
{ // the model is a feature collection, only then can this GeoJson processor be used.
if (IsExactJsonContentType(requestedMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
if (IsWildcardJsonContentType(requestedMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.ExactMatch,
RequestedContentTypeResult = MatchResult.NonExactMatch
};
}
}
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例3: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (IsExactSirenContentType(requestedMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.ExactMatch
};
}
if (IsWildcardSirenContentType(requestedMediaRange))
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NonExactMatch
};
}
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.NoMatch
};
}
示例4: 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());
}
示例5: 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
};
}
示例6: Deserialize
/// <summary>
/// Deserialize the request body to a model
/// </summary>
/// <param name="mediaRange">Content type to deserialize</param>
/// <param name="bodyStream">Request body stream</param>
/// <param name="context">Current context</param>
/// <returns>Model instance</returns>
public object Deserialize(MediaRange mediaRange, Stream bodyStream, BindingContext context)
{
if (bodyStream.CanSeek)
{
bodyStream.Position = 0;
}
var deserializedObject =
this.serializer.Deserialize(new StreamReader(bodyStream), context.DestinationType);
var properties =
context.DestinationType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Select(p => new BindingMemberInfo(p));
var fields =
context.DestinationType.GetFields(BindingFlags.Public | BindingFlags.Instance)
.Select(f => new BindingMemberInfo(f));
if (properties.Concat(fields).Except(context.ValidModelBindingMembers).Any())
{
return CreateObjectWithBlacklistExcluded(context, deserializedObject);
}
return deserializedObject;
}
示例7: Process
public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
var format =
SparqlResultsFormat.AllFormats.FirstOrDefault(f => f.MediaTypes.Any(m => requestedMediaRange.Matches(m)));
var queryModel = model as SparqlQueryProcessingModel;
return new SparqlQueryResponse(queryModel, context.Request.Headers.IfModifiedSince, format);
}
示例8: Process
public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
return new JsonResponse(BuildHypermedia(model, context), serializer)
{
ContentType = "application/hal+json"
};
}
示例9: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
if (IsSomeXmlType(requestedMediaRange) || IsTextHhtml(requestedMediaRange))
return new ProcessorMatch {RequestedContentTypeResult = MatchResult.ExactMatch, ModelResult = MatchResult.DontCare};
else
return new ProcessorMatch {ModelResult = MatchResult.NoMatch, RequestedContentTypeResult = MatchResult.NoMatch};
}
示例10: GetErrorMessage
private static string GetErrorMessage(IEnumerable<ISerializer> matches, MediaRange mediaRange)
{
var details =
string.Join("\n", matches.Select(x => string.Concat(" - ", x.GetType().FullName)));
return string.Format("Multiple ISerializer implementations matched the '{0}' media range.\nThe following serializers matched \n\n{1}", mediaRange, details);
}
示例11: Deserialize
/// <summary>
/// Deserialize the request body to a model
/// </summary>
/// <param name="mediaRange">Content type to deserialize</param>
/// <param name="bodyStream">Request body stream</param>
/// <param name="context">Current context</param>
/// <returns>Model instance</returns>
public object Deserialize(MediaRange mediaRange, Stream bodyStream, BindingContext context)
{
var serializer = new JavaScriptSerializer(
null,
false,
this.configuration.MaxJsonLength,
this.configuration.MaxRecursions,
this.configuration.RetainCasing,
this.configuration.UseISO8601DateFormat,
this.configuration.Converters,
this.configuration.PrimitiveConverters);
serializer.RegisterConverters(this.configuration.Converters, this.configuration.PrimitiveConverters);
bodyStream.Position = 0;
string bodyText;
using (var bodyReader = new StreamReader(bodyStream))
{
bodyText = bodyReader.ReadToEnd();
}
var genericDeserializeMethod = this.deserializeMethod.MakeGenericMethod(context.DestinationType);
var deserializedObject = genericDeserializeMethod.Invoke(serializer, new object[] { bodyText });
return deserializedObject;
}
示例12: CanProcess
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
return new ProcessorMatch
{
ModelResult = MatchResult.DontCare,
RequestedContentTypeResult = MatchResult.DontCare
};
}
示例13: Should_strip_whitespace_when_calling_tostring
public void Should_strip_whitespace_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy ; a=1; b=2");
// Then
range.ToString().ShouldEqual("application/vnd.nancy;a=1;b=2");
}
示例14: Should_include_parameters_when_calling_tostring
public void Should_include_parameters_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy;a=1;b=2");
// Then
range.ToString().ShouldEqual("application/vnd.nancy;a=1;b=2");
}
示例15: Should_handle_no_parameters_when_calling_tostring
public void Should_handle_no_parameters_when_calling_tostring()
{
// Given
var range = new MediaRange("application/vnd.nancy");
// Then
range.ToString().ShouldEqual("application/vnd.nancy");
}