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


C# Negotiation.MediaRange类代码示例

本文整理汇总了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
                };
        }
开发者ID:BeeWarloc,项目名称:Pomona,代码行数:38,代码来源:PomonaCsvResponseProcessor.cs

示例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
            };
        }
开发者ID:nagyistoce,项目名称:OsmSharp-routing-api,代码行数:35,代码来源:GeoJsonResponseProcessor.cs

示例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
            };
        }
开发者ID:madhon,项目名称:NancyHelloWorld,代码行数:26,代码来源:SirenResponseProcessor.cs

示例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());
        }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:27,代码来源:SparqlProcessor.cs

示例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
     };
 }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:25,代码来源:GraphListProcessor.cs

示例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;
        }
开发者ID:markashleybell,项目名称:gtdpad,代码行数:32,代码来源:JsonNetBodyDeserializer.cs

示例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);
 }
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:7,代码来源:SparqlProcessor.cs

示例8: Process

 public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
 {
     return new JsonResponse(BuildHypermedia(model, context), serializer)
                {
                    ContentType = "application/hal+json"
                };
 }
开发者ID:MrScruffy04,项目名称:Nancy.Hal,代码行数:7,代码来源:HalJsonResponseProcessor.cs

示例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};
 }
开发者ID:horsdal,项目名称:Restbucks-on-Nancy,代码行数:7,代码来源:XmlResponseProcessor.cs

示例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);
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:7,代码来源:DefaultSerializerFactory.cs

示例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;
        }
开发者ID:afwilliams,项目名称:Nancy,代码行数:34,代码来源:JsonBodyDeserializer.cs

示例12: CanProcess

 public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
 {
     return new ProcessorMatch
     {
         ModelResult = MatchResult.DontCare,
         RequestedContentTypeResult = MatchResult.DontCare
     };
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:8,代码来源:JsonLdProcessor.cs

示例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");
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:8,代码来源:MediaRangeFixture.cs

示例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");
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:8,代码来源:MediaRangeFixture.cs

示例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");
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:8,代码来源:MediaRangeFixture.cs


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