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


C# MediaRange.Matches方法代码示例

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

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

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

示例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
                };
        }
开发者ID:joebuschmann,项目名称:Nancy.Serialization.Csv,代码行数:17,代码来源:CsvProcessor.cs

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

示例6: IsExactSirenContentType

        private static bool IsExactSirenContentType(MediaRange requestedContentType)
        {
            if (requestedContentType.Type.IsWildcard && requestedContentType.Subtype.IsWildcard)
            {
                return true;
            }

            return requestedContentType.Matches("application/vnd.siren+json");
        }
开发者ID:madhon,项目名称:NancyHelloWorld,代码行数:9,代码来源:SirenResponseProcessor.cs

示例7: IsExactPdfContentType

        private static bool IsExactPdfContentType(MediaRange requestedContentType)
        {
            if (requestedContentType.Type.IsWildcard && requestedContentType.Subtype.IsWildcard)
            {
                return true;
            }

            return requestedContentType.Matches("application/pdf");
        }
开发者ID:chrissie1,项目名称:NancyVB,代码行数:9,代码来源:PdfProcessor.cs

示例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 };
        }
开发者ID:hyrmn,项目名称:NancyIntro,代码行数:13,代码来源:TextProcessor.cs

示例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
            };
        }
开发者ID:apxnowhere,项目名称:Encore,代码行数:17,代码来源:CsvResponseProcessor.cs

示例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
            };
        }
开发者ID:NancyFx,项目名称:Nancy.Serialization.ProtBuf,代码行数:24,代码来源:ProtoBufProcessor.cs

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

示例12: IsTextHtmlContentType

 protected bool IsTextHtmlContentType(MediaRange requestedMediaRange)
 {
     return requestedMediaRange.Matches("text/html");
 }
开发者ID:Pomona,项目名称:Pomona,代码行数:4,代码来源:PomonaResponseProcessorBase.cs

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

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

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


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