當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。