ServiceStack.ContentFormat.ToFeature C# (CSharp) Méthode

ToFeature() public static méthode

public static ToFeature ( this contentType ) : Feature
contentType this
Résultat Feature
        public static Feature ToFeature(this string contentType)
        {
            if (contentType == null)
                return Feature.None;

            var realContentType = GetRealContentType(contentType);
            switch (realContentType)
            {
                case MimeTypes.Json:
                case MimeTypes.JsonText:
                    return Feature.Json;

                case MimeTypes.Xml:
                case MimeTypes.XmlText:
                    return Feature.Xml;

                case MimeTypes.Html:
                    return Feature.Html;

                case MimeTypes.Jsv:
                case MimeTypes.JsvText:
                    return Feature.Jsv;

                case MimeTypes.Csv:
                    return Feature.Csv;

                case MimeTypes.Soap11:
                    return Feature.Soap11;

                case MimeTypes.Soap12:
                    return Feature.Soap12;

                case MimeTypes.ProtoBuf:
                    return Feature.ProtoBuf;

                case MimeTypes.MsgPack:
                    return Feature.MsgPack;

                case MimeTypes.Wire:
                    return Feature.Wire;
            }

            return Feature.CustomFormat;
        }

Usage Example

Exemple #1
0
        private static IHttpHandler GetHandlerForPathParts(string[] pathParts)
        {
            var pathController = string.Intern(pathParts[0].ToLower());

            if (pathParts.Length == 1)
            {
                if (pathController == "soap11")
                {
                    return(new Soap11MessageSyncReplyHttpHandler());
                }
                if (pathController == "soap12")
                {
                    return(new Soap12MessageSyncReplyHttpHandler());
                }

                return(null);
            }

            var pathAction  = string.Intern(pathParts[1].ToLower());
            var requestName = pathParts.Length > 2 ? pathParts[2] : null;
            var isReply     = pathAction == "syncreply" || pathAction == "reply";
            var isOneWay    = pathAction == "asynconeway" || pathAction == "oneway";

            switch (pathController)
            {
            case "json":
                if (isReply)
                {
                    return new JsonSyncReplyHandler {
                               RequestName = requestName
                    }
                }
                ;
                if (isOneWay)
                {
                    return new JsonAsyncOneWayHandler {
                               RequestName = requestName
                    }
                }
                ;
                break;

            case "xml":
                if (isReply)
                {
                    return new XmlSyncReplyHandler {
                               RequestName = requestName
                    }
                }
                ;
                if (isOneWay)
                {
                    return new XmlAsyncOneWayHandler {
                               RequestName = requestName
                    }
                }
                ;
                break;

            case "jsv":
                if (isReply)
                {
                    return new JsvSyncReplyHandler {
                               RequestName = requestName
                    }
                }
                ;
                if (isOneWay)
                {
                    return new JsvAsyncOneWayHandler {
                               RequestName = requestName
                    }
                }
                ;
                break;

            default:
                string contentType;
                if (EndpointHost.ContentTypes.ContentTypeFormats.TryGetValue(pathController, out contentType))
                {
                    var feature = ContentFormat.ToFeature(contentType);

                    if (feature == Feature.None)
                    {
                        feature = Feature.CustomFormat;
                    }

                    if (isReply)
                    {
                        return new GenericHandler(contentType, EndpointAttributes.Reply, feature)
                               {
                                   RequestName = requestName
                               }
                    }
                    ;
                    if (isOneWay)
                    {
                        return new GenericHandler(contentType, EndpointAttributes.OneWay, feature)
                               {
                                   RequestName = requestName
                               }
                    }
                    ;
                }
                break;
            }

            return(null);
        }
    }
}