Ejemplo n.º 1
0
        /// <summary>
        /// Returns the response category as one of three values
        ///   FileTools.TEXT
        ///   FileTools.IMAGE
        ///   FileTools.OTHER
        ///
        /// First tests the response object.
        ///
        /// If response.ContentType determines that the value is
        /// TEXT or IMAGE then that value is returned.
        ///
        /// Otherwise, uri.FileExtension is tested using
        ///   FileTools.GetFileCategory
        ///
        /// If that determines the answer then that is returned.
        ///
        /// Otherwise, FileTools.OTHER is returned.
        ///
        /// Assumption: The response is the result of requesting
        /// the uri.
        /// </summary>
        /// <param name="uri">The uri to request</param>
        /// <param name="response">The response to the request</param>
        public static int ResponseCategory
            (UriPlus uri, HttpWebResponse response)
        {
            int category = FileTools.OTHER;

            // First test response.ContentType

            if (response != null)
            {
                string contentType = response.ContentType;

                if (!StringTools.IsTrivial(contentType))
                {
                    if (contentType.StartsWith("text"))
                    {
                        category = FileTools.TEXT;
                    }
                    else if (contentType.StartsWith("image"))
                    {
                        category = FileTools.IMAGE;
                    }
                    else if (contentType.Contains("javascript"))
                    {
                        category = FileTools.TEXT;
                    }
                    else if (contentType.Contains("json"))
                    {
                        category = FileTools.TEXT;
                    }
                    else if (contentType.Contains("htm"))
                    {
                        category = FileTools.TEXT;
                    }
                    else if (contentType.StartsWith("application/xml"))
                    {
                        category = FileTools.TEXT;
                    }
                }
            }

            // Only test uri.FileExtension if category did not change

            if (category == FileTools.OTHER)
            {
                if (uri != null)
                {
                    string extension = uri.FileExtension;

                    if (!StringTools.IsTrivial(extension))
                    {
                        category = FileTools.GetFileCategory(extension);
                    }
                }
            }

            return(category);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This method is obsolete because its uri parameter is
 /// no longer unused.
 /// 
 /// This method is retained for backward compatibility.
 /// 
 /// Returns the response category as one of three values
 ///   FileTools.TEXT
 ///   FileTools.IMAGE
 ///   FileTools.OTHER
 /// 
 /// Tests the response object.
 /// 
 /// If response.ContentType determines that the value is
 /// TEXT or IMAGE then that value is returned.
 /// 
 /// Otherwise, OTHER is returned.
 /// </summary>
 /// <param name="uri">The uri to request</param>
 /// <param name="response">The response to the request</param>
 public static int ResponseCategory(UriPlus uri, HttpWebResponse response)
 {
     return ResponseCategory(response);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the response category as one of three values
        ///   FileTools.TEXT
        ///   FileTools.IMAGE
        ///   FileTools.OTHER
        /// 
        /// First tests the response object.
        /// 
        /// If response.ContentType determines that the value is
        /// TEXT or IMAGE then that value is returned.
        /// 
        /// Otherwise, uri.FileExtension is tested using
        ///   FileTools.GetFileCategory
        /// 
        /// If that determines the answer then that is returned.
        /// 
        /// Otherwise, FileTools.OTHER is returned.
        /// 
        /// Assumption: The response is the result of requesting
        /// the uri.
        /// </summary>
        /// <param name="uri">The uri to request</param>
        /// <param name="response">The response to the request</param>
        public static int ResponseCategory
            (UriPlus uri, HttpWebResponse response)
        {
            int category = FileTools.OTHER;

            // First test response.ContentType

            if (response != null)
            {
                string contentType = response.ContentType;

                if (!StringTools.IsTrivial(contentType))
                {
                    if (contentType.StartsWith("text"))
                        category = FileTools.TEXT;
                    else if (contentType.StartsWith("image"))
                        category = FileTools.IMAGE;
                    else if (contentType.Contains("javascript"))
                        category = FileTools.TEXT;
                    else if (contentType.Contains("json"))
                        category = FileTools.TEXT;
                    else if (contentType.Contains("htm"))
                        category = FileTools.TEXT;
                    else if (contentType.StartsWith("application/xml"))
                        category = FileTools.TEXT;
                }
            }

            // Only test uri.FileExtension if category did not change

            if (category == FileTools.OTHER)
            {
                if (uri != null)
                {
                    string extension = uri.FileExtension;

                    if (!StringTools.IsTrivial(extension))
                    {
                        category = FileTools.GetFileCategory(extension);
                    }
                }
            }

            return category;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// This method is obsolete because its uri parameter is
 /// no longer unused.
 ///
 /// This method is retained for backward compatibility.
 ///
 /// Returns the response category as one of three values
 ///   FileTools.TEXT
 ///   FileTools.IMAGE
 ///   FileTools.OTHER
 ///
 /// Tests the response object.
 ///
 /// If response.ContentType determines that the value is
 /// TEXT or IMAGE then that value is returned.
 ///
 /// Otherwise, OTHER is returned.
 /// </summary>
 /// <param name="uri">The uri to request</param>
 /// <param name="response">The response to the request</param>
 public static int ResponseCategory
     (UriPlus uri, HttpWebResponse response)
 {
     return(ResponseCategory(response));
 }