Ejemplo n.º 1
0
        protected virtual IDeserializer GetHandler(string contentType)
        {
            IDeserializer deserializer;

            ContentHandlers.TryGetValue(contentType, out deserializer);
            return(deserializer ?? ContentHandlers["*"]);
        }
Ejemplo n.º 2
0
 private IDeserializer GetHandler(string contentType)
 {
     if (contentType == null)
     {
         throw new ArgumentNullException("contentType");
     }
     if (!string.IsNullOrEmpty(contentType) || !ContentHandlers.ContainsKey("*"))
     {
         int num = contentType.IndexOf(';');
         if (num > -1)
         {
             contentType = contentType.Substring(0, num);
         }
         IDeserializer result = null;
         if (ContentHandlers.ContainsKey(contentType))
         {
             result = ContentHandlers[contentType];
         }
         else if (ContentHandlers.ContainsKey("*"))
         {
             result = ContentHandlers["*"];
         }
         return(result);
     }
     return(ContentHandlers["*"]);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve the handler for the specified MIME content type
        /// </summary>
        /// <param name="contentType">MIME content type to retrieve</param>
        /// <returns>IDeserializer instance</returns>
        IDeserializer GetHandler(string contentType)
        {
            if (string.IsNullOrEmpty(contentType) && ContentHandlers.ContainsKey("*"))
            {
                return(ContentHandlers["*"]);
            }

            var semicolonIndex = contentType.IndexOf(';');

            if (semicolonIndex > -1)
            {
                contentType = contentType.Substring(0, semicolonIndex);
            }
            IDeserializer handler = null;

            if (ContentHandlers.ContainsKey(contentType))
            {
                handler = ContentHandlers[contentType];
            }
            else if (ContentHandlers.ContainsKey("*"))
            {
                handler = ContentHandlers["*"];
            }

            return(handler);
        }
Ejemplo n.º 4
0
 public InitUSlack(ContentHandlers contentHandlers,
                   MediaHandlers mediaHandlers,
                   MemberHandlers memberHandlers,
                   UserHandlers userHandlers)
 {
     _contentHandlers = contentHandlers;
     _mediaHandlers   = mediaHandlers;
     _memberHandlers  = memberHandlers;
     _userHandlers    = userHandlers;
 }
Ejemplo n.º 5
0
        static void Main()
        {
            var mapping = new MappingHandlers();
            var content = new ContentHandlers();
            var hooks   = new CommitHooks(mapping);

            mapping.Register();
            content.Register();
            hooks.Register();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Unregisters a content handler
        /// </summary>
        /// <param name="handler">The handler to remove</param>
        /// <returns></returns>
        public override bool Unregister(IContentHandler handler)
        {
#if WINDOWS_APP
            NewContentAttribute[] handlerAttributes = (NewContentAttribute[])(handler.GetType()).GetCustomAttributes(typeof(NewContentAttribute), true);
            _availableNewContent.RemoveAll(handlerAttributes.Contains);
            foreach (NewContentAttribute newContentAttribute in handlerAttributes)
            {
                _dictionary.Remove(newContentAttribute);
            }

            _availableNewContent.Sort((attribute, contentAttribute) => attribute.Priority - contentAttribute.Priority);
            return(ContentHandlers.Remove(handler));
#endif
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Register a content handler with the registry
        /// </summary>
        /// <param name="handler">The content handler</param>
        /// <returns>true, if successful - false, otherwise</returns>
        public override bool Register(IContentHandler handler)
        {
#if WINDOWS_APP
            ContentHandlers.Add(handler);
            NewContentAttribute[] handlerAttributes = (NewContentAttribute[])(handler.GetType()).GetCustomAttributes(typeof(NewContentAttribute), true);
            _availableNewContent.AddRange(handlerAttributes);
            foreach (NewContentAttribute newContentAttribute in handlerAttributes)
            {
                _dictionary.Add(newContentAttribute, handler);
            }

            _availableNewContent.Sort((attribute, contentAttribute) => attribute.Priority - contentAttribute.Priority);
#endif
            return(true);
        }
        private Func <IDeserializer> GetHandler(string contentType)
        {
            if (contentType.IsEmpty() && ContentHandlers.ContainsKey("*"))
            {
                return(ContentHandlers["*"]);
            }

            if (contentType.IsEmpty())
            {
                return(ContentHandlers.First().Value);
            }

            var semicolonIndex = contentType.IndexOf(';');

            if (semicolonIndex > -1)
            {
                contentType = contentType.Substring(0, semicolonIndex);
            }

            Func <IDeserializer> contentHandler;

            if (ContentHandlers.TryGetValue(contentType, out contentHandler))
            {
                return(contentHandler);
            }

            // Avoid unnecessary use of regular expressions in checking for structured syntax suffix by looking for a '+' first
            if (contentType.IndexOf('+') >= 0)
            {
                // https://tools.ietf.org/html/rfc6839#page-4
                var structuredSyntaxSuffixMatch = StructuredSyntaxSuffixRegex.Match(contentType);

                if (structuredSyntaxSuffixMatch.Success)
                {
                    var structuredSyntaxSuffixWildcard = "*" + structuredSyntaxSuffixMatch.Value;
                    Func <IDeserializer> contentHandlerWildcard;
                    if (ContentHandlers.TryGetValue(structuredSyntaxSuffixWildcard, out contentHandlerWildcard))
                    {
                        return(contentHandlerWildcard);
                    }
                }
            }

            return(ContentHandlers.ContainsKey("*") ? ContentHandlers["*"] : null);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Retrieve the handler for the specified MIME content type
        /// </summary>
        /// <param name="contentType">MIME content type to retrieve</param>
        /// <returns>IDeserializer instance</returns>
        private IDeserializer GetHandler(string contentType)
        {
            if (contentType == null)
            {
                throw new ArgumentNullException("contentType");
            }

            if (string.IsNullOrEmpty(contentType) && ContentHandlers.ContainsKey("*"))
            {
                return(ContentHandlers["*"]);
            }

            int semicolonIndex = contentType.IndexOf(';');

            if (semicolonIndex > -1)
            {
                contentType = contentType.Substring(0, semicolonIndex);
            }

            if (ContentHandlers.ContainsKey(contentType))
            {
                return(ContentHandlers[contentType]);
            }

            // Avoid unnecessary use of regular expressions in checking for structured syntax suffix by looking for a '+' first
            if (contentType.IndexOf('+') >= 0)
            {
                // https://tools.ietf.org/html/rfc6839#page-4
                Match structuredSyntaxSuffixMatch = StructuredSyntaxSuffixRegex.Match(contentType);

                if (structuredSyntaxSuffixMatch.Success)
                {
                    string structuredSyntaxSuffixWildcard = "*" + structuredSyntaxSuffixMatch.Value;
                    if (ContentHandlers.ContainsKey(structuredSyntaxSuffixWildcard))
                    {
                        return(ContentHandlers[structuredSyntaxSuffixWildcard]);
                    }
                }
            }

            return(ContentHandlers.ContainsKey("*") ? ContentHandlers["*"] : null);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Retrieve the handler for the specified MIME content type
        /// </summary>
        /// <param name="contentType">MIME content type to retrieve</param>
        /// <returns>IDeserializer instance</returns>
        private IDeserializer GetHandler(string contentType)
        {
            if (contentType == null)
            {
                throw new ArgumentNullException("contentType");
            }

            if (string.IsNullOrEmpty(contentType) && ContentHandlers.ContainsKey("*"))
            {
                return(ContentHandlers["*"]);
            }

            var semicolonIndex = contentType.IndexOf(';');

            if (semicolonIndex > -1)
            {
                contentType = contentType.Substring(0, semicolonIndex);
            }

            if (ContentHandlers.ContainsKey(contentType))
            {
                return(ContentHandlers[contentType]);
            }

            // https://tools.ietf.org/html/rfc6839#page-4
            var structuredSyntaxSuffixMatch = structuredSyntaxSuffixRegex.Match(contentType);

            if (!structuredSyntaxSuffixMatch.Success)
            {
                return(ContentHandlers.ContainsKey("*") ? ContentHandlers["*"] : null);
            }

            var structuredSyntaxSuffixWildcard = "*" + structuredSyntaxSuffixMatch.Value;

            if (ContentHandlers.ContainsKey(structuredSyntaxSuffixWildcard))
            {
                return(ContentHandlers[structuredSyntaxSuffixWildcard]);
            }

            return(ContentHandlers.ContainsKey("*") ? ContentHandlers["*"] : null);
        }
Ejemplo n.º 11
0
 /// <summary>
 ///     Remove all content handlers
 /// </summary>
 public void ClearHandlers()
 {
     ContentHandlers.Clear();
     AcceptTypes.Clear();
     this.RemoveDefaultParameter("Accept");
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     Remove a content handler for the specified MIME content type
 /// </summary>
 /// <param name="contentType">MIME content type to remove</param>
 public void RemoveHandler(string contentType)
 {
     ContentHandlers.Remove(contentType);
     AcceptTypes.Remove(contentType);
     this.RemoveDefaultParameter("Accept");
 }
Ejemplo n.º 13
0
 public IRestClient AddHandler(string contentType, IDeserializer deserializer)
 {
     ContentHandlers.Add(contentType, deserializer);
     return(this);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Remove all content handlers
 /// </summary>
 public void ClearHandlers()
 {
     ContentHandlers.Clear();
     AcceptTypes.Clear();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Remove a content handler for the specified MIME content type
 /// </summary>
 /// <param name="contentType">MIME content type to remove</param>
 public void RemoveHandler(string contentType)
 {
     ContentHandlers.Remove(contentType);
     AcceptTypes.Remove(contentType);
 }
Ejemplo n.º 16
0
 public ApiClientImpl(HttpClient httpClient, CookieContainer cookies, ContentHandlers contentHandlers)
 {
     this.contentHandlers = contentHandlers;
     this.httpClient      = httpClient;
     this.cookies         = cookies;
 }
Ejemplo n.º 17
0
        public bool TryRespond(IHttpContext context, out string[] checkedPaths)
        {
            checkedPaths = new string[] { };
            try
            {
                if (Etags.CheckEtags(context))
                {
                    return(true);
                }
                IRequest  request  = context.Request;
                IResponse response = context.Response;
                string    path     = request.Url.AbsolutePath;

                string ext = Path.GetExtension(path);

                string[] split   = path.DelimitSplit("/");
                byte[]   content = new byte[] { };
                bool     handled = AllRequestHandler.HandleRequest(context, out content);

                if (!handled)
                {
                    if (ContentHandlers.ContainsKey(path.ToLowerInvariant()))
                    {
                        handled = ContentHandlers[path.ToLowerInvariant()].HandleRequest(context, out content);
                    }
                    else if (AppContentLocator.Locate(path, out string locatedPath, out checkedPaths))
                    {
                        handled = true;
                        string foundExt = Path.GetExtension(locatedPath);
                        if (FileCachesByExtension.ContainsKey(foundExt))
                        {
                            FileCache cache = FileCachesByExtension[ext];
                            if (ShouldZip(request))
                            {
                                SetGzipContentEncodingHeader(response);
                                content = cache.GetZippedContent(locatedPath);
                            }
                            else
                            {
                                content = cache.GetContent(locatedPath);
                            }
                        }
                        else
                        {
                            content = File.ReadAllBytes(locatedPath);
                        }
                        Etags.SetLastModified(response, request.Url.ToString(), new FileInfo(locatedPath).LastWriteTime);
                    }
                    else if (string.IsNullOrEmpty(ext) && !ShouldIgnore(path) || (AppRoot.FileExists("~/pages{0}.html"._Format(path), out locatedPath)))
                    {
                        content = RenderLayout(response, path);
                        handled = true;
                    }
                }

                if (handled)
                {
                    SetContentType(response, path);
                    SetContentDisposition(response, path);
                    Etags.Set(response, request.Url.ToString(), content);
                    SetResponseHeaders(response, path);
                    SendResponse(response, content);
                    OnResponded(context);
                }
                else
                {
                    OnNotResponded(context);
                }
                return(handled);
            }
Ejemplo n.º 18
0
 public IRestClient RemoveHandler(string contentType)
 {
     ContentHandlers.Remove(contentType);
     return(this);
 }
Ejemplo n.º 19
0
 public IRestClient ClearHandlers()
 {
     ContentHandlers.Clear();
     return(this);
 }
Ejemplo n.º 20
0
 public InitPlumberHandlers(ContentHandlers contentHandlers)
 {
     _contentHandlers = contentHandlers;
 }