/// <summary> Stores the language-specific html skin object to the cache  </summary>
        /// <param name="Skin_Code"> Code for this html display skin </param>
        /// <param name="Language_Code"> Current language code for the user interface ( skins are language-specific)</param>
        /// <param name="StoreObject"> Language-specific HTML Skin object </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        public void Store_Skin(string Skin_Code, string Language_Code, Web_Skin_Object StoreObject, Custom_Tracer Tracer)
        {
            // If the cache is disabled, just return before even tracing
            if ((settings.Disabled) || (StoreObject == null))
            {
                return;
            }

            // Determine the key
            string key = "SKIN|" + Skin_Code.ToLower() + "|";

            if (Language_Code.Length > 0)
            {
                key = key + Language_Code;
            }

            // Log
            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager.Store_Skin", "Adding object '" + key + "' to the local cache with expiration of 1 minute");
            }

            // Add to the cache with five minute expiration
            HttpContext.Current.Cache.Insert(key, StoreObject, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));
        }
Ejemplo n.º 2
0
        /// <summary> Get the language-specific web skin, by skin code and language </summary>
        /// <param name="SkinCode"> Code for the web skin </param>
        /// <param name="RequestedLanguage"> Requested language for the web skin code </param>
        /// <param name="DefaultLanguage"> Default UI language for the instance </param>
        /// <param name="Cache_On_Build"> Flag indicates whether to use the cache </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        /// <returns> Language-specific web skin object </returns>
        public Web_Skin_Object Get_LanguageSpecific_Web_Skin(string SkinCode, Web_Language_Enum RequestedLanguage, Web_Language_Enum DefaultLanguage, bool Cache_On_Build, Custom_Tracer Tracer)
        {
            // If no interface yet, look in the cache
            if ((SkinCode != "new") && (Cache_On_Build))
            {
                Web_Skin_Object htmlSkin = CachedDataManager.WebSkins.Retrieve_Skin(SkinCode, Web_Language_Enum_Converter.Enum_To_Code(RequestedLanguage), Tracer);
                if (htmlSkin != null)
                {
                    if (Tracer != null)
                    {
                        Tracer.Add_Trace("SobekEngineClient_WebSkinEndpoints.Get_LanguageSpecific_Web_Skin", "Web skin '" + SkinCode + "' found in cache");
                    }
                    return(htmlSkin);
                }
            }

            // If still not interface, build one
            Web_Skin_Object new_skin = WebSkinServices.get_web_skin(SkinCode, RequestedLanguage, DefaultLanguage, Tracer);

            // Look in the web skin row and see if it should be kept around, rather than momentarily cached
            if ((new_skin != null) && (String.IsNullOrEmpty(new_skin.Exception)))
            {
                if (Cache_On_Build)
                {
                    // Momentarily cache this web skin object
                    CachedDataManager.WebSkins.Store_Skin(SkinCode, Web_Language_Enum_Converter.Enum_To_Code(RequestedLanguage), new_skin, Tracer);
                }
            }

            return(new_skin);
        }
Ejemplo n.º 3
0
        /// <summary> Get the banner image for this aggregation, possibly returning the web skin banner if it overrides
        /// the aggregation banner  </summary>
        /// <param name="ThisWebSkin"> Web skin object, which may override the banner from this aggregation </param>
        /// <returns> String for the banner to use for this aggregation </returns>
        public string Get_Banner_Image(Web_Skin_Object ThisWebSkin)
        {
            // Does the web skin exist and override the banner?  For non-institutional agggregations
            // use the web skin banner HTML instead of the aggregation's banner
            if ((ThisWebSkin != null) && (ThisWebSkin.Override_Banner.HasValue) && (ThisWebSkin.Override_Banner.Value) && (Type.ToLower().IndexOf("institution") < 0))
            {
                return(!String.IsNullOrEmpty(ThisWebSkin.Banner_HTML) ? ThisWebSkin.Banner_HTML : String.Empty);
            }

            return(BannerImage);
        }
Ejemplo n.º 4
0
        /// <summary> Constructor for a new instance of the RequestCache class </summary>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Results_Statistics"> Information about the entire set of results for a search or browse </param>
        /// <param name="Paged_Results"> Single page of results for a search or browse, within the entire set </param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Current_User"> Currently logged on user </param>
        /// <param name="Public_Folder"> Object contains the information about the public folder to display </param>
        /// <param name="Top_Collection"> Item aggregation for the top-level collection, which is used in a number of places, for example
        /// showing the correct banner, even when it is not the "current" aggregation </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param>
        public RequestCache(Navigation_Object Current_Mode,
                            Search_Results_Statistics Results_Statistics,
                            List <iSearch_Title_Result> Paged_Results,
                            Web_Skin_Object HTML_Skin,
                            User_Object Current_User,
                            Public_User_Folder Public_Folder,
                            Item_Aggregation Top_Collection,
                            Custom_Tracer Tracer)
        {
            this.Current_Mode       = Current_Mode;
            this.Results_Statistics = Results_Statistics;
            this.Paged_Results      = Paged_Results;
            this.HTML_Skin          = HTML_Skin;
            this.Current_User       = Current_User;
            this.Public_Folder      = Public_Folder;
            this.Top_Collection     = Top_Collection;
            this.Tracer             = Tracer;

            Flags = new RequestCache_RequestFlags();
        }
Ejemplo n.º 5
0
        /// <summary> [HELPER] Gets the language-specific web skin, by web skin code and language code </summary>
        /// <param name="SkinCode"> Web skin code </param>
        /// <param name="RequestedLanguage"> Web language </param>
        /// <param name="DefaultLanguage"> Default language, in case the requested web language does nto exist </param>
        /// <param name="Tracer"></param>
        /// <returns> A build language-specific web skin </returns>
        /// <remarks> This may be public now, but this will be converted into a protected helped class with
        /// the release of SobekCM 5.0 </remarks>
        public static Web_Skin_Object get_web_skin(string SkinCode, Web_Language_Enum RequestedLanguage, Web_Language_Enum DefaultLanguage, Custom_Tracer Tracer)
        {
            Complete_Web_Skin_Object completeSkin = get_complete_web_skin(SkinCode, Tracer);

            if (completeSkin == null)
            {
                Tracer.Add_Trace("WebSkinServices.get_web_skin", "Complete skin retrieved was NULL, so returning NULL");
                return(null);
            }

            // Look in the cache for this first
            Web_Skin_Object cacheObject = CachedDataManager.WebSkins.Retrieve_Skin(SkinCode, Web_Language_Enum_Converter.Enum_To_Code(RequestedLanguage), Tracer);

            if (cacheObject != null)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("WebSkinServices.get_web_skin", "Web skin found in the memory cache");
                }
                return(cacheObject);
            }

            // Try to get this language-specifi web skin
            Web_Skin_Object returnValue = Web_Skin_Utilities.Build_Skin(completeSkin, Web_Language_Enum_Converter.Enum_To_Code(RequestedLanguage), Tracer);

            // If this web skin has a value (an no exception) store in the cache
            if ((returnValue != null) && (String.IsNullOrEmpty(returnValue.Exception)))
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("WebSkinServices.get_web_skin", "Store the web skin in the memory cache");
                }
                CachedDataManager.WebSkins.Store_Skin(SkinCode, Web_Language_Enum_Converter.Enum_To_Code(RequestedLanguage), returnValue, Tracer);
            }

            // Return the object
            return(returnValue);
        }
        /// <summary> Adds the banner to the response stream from either the html web skin
        /// or from the current item aggreagtion object, depending on flags in the web skin object </summary>
        /// <param name="Output"> Stream to which to write the HTML for the banner </param>
        /// <param name="Banner_Division_Name"> Name for the wrapper division around the banner </param>
        /// <param name="Hierarchy_Object"> Current item aggregation object to display </param>
        /// <param name="HTML_Skin"> HTML Web skin which controls the overall appearance of this digital library </param>
        /// <param name="Web_Page_Title"> Web page title to add behind the banner image </param>
        /// <param name="CurrentMode"> Mode / navigation information for the current request</param>
        /// <remarks> This is called by several html subwriters that otherwise tell this class to suppress writing the banner </remarks>
        public static void Add_Banner(TextWriter Output, string Banner_Division_Name, string Web_Page_Title, Navigation_Object CurrentMode, Web_Skin_Object HTML_Skin, Item_Aggregation Hierarchy_Object)
        {
            Output.WriteLine("<!-- abstractHtmlSubwriter.Add_Banner - Write the main collection, interface, or institution banner -->");

            if ((HTML_Skin != null) && (HTML_Skin.Override_Banner.HasValue) && (HTML_Skin.Override_Banner.Value))
            {
                if (!String.IsNullOrEmpty(HTML_Skin.Banner_HTML))
                {
                    Output.WriteLine(HTML_Skin.Banner_HTML);
                }
            }
            else
            {
                string url_options = UrlWriterHelper.URL_Options(CurrentMode);
                if (url_options.Length > 0)
                {
                    url_options = "?" + url_options;
                }

                if ((Hierarchy_Object != null) && (Hierarchy_Object.Code != "all"))
                {
                    Output.WriteLine("<section id=\"sbkAhs_BannerDiv\" role=\"banner\" title=\"" + Hierarchy_Object.ShortName + "\">");
                    Output.WriteLine("  <h1 class=\"hidden-element\">" + Web_Page_Title + "</h1>");
                    Output.WriteLine("  <a alt=\"" + Hierarchy_Object.ShortName + "\" href=\"" + CurrentMode.Base_URL + Hierarchy_Object.Code + url_options + "\"><img id=\"mainBanner\" src=\"" + CurrentMode.Base_URL + Hierarchy_Object.Get_Banner_Image(HTML_Skin) + "\"  alt=\"" + Hierarchy_Object.ShortName + "\" /></a>");
                    Output.WriteLine("</section>");
                }
                else
                {
                    if ((Hierarchy_Object != null) && (Hierarchy_Object.Get_Banner_Image(HTML_Skin).Length > 0))
                    {
                        Output.WriteLine("<section id=\"sbkAhs_BannerDiv\" role=\"banner\" title=\"" + Hierarchy_Object.ShortName + "\">");
                        Output.WriteLine("  <h1 class=\"hidden-element\">" + Web_Page_Title + "</h1>");
                        Output.WriteLine("  <a alt=\"" + Hierarchy_Object.ShortName + "\" href=\"" + CurrentMode.Base_URL + url_options + "\"><img id=\"mainBanner\" src=\"" + CurrentMode.Base_URL + Hierarchy_Object.Get_Banner_Image(HTML_Skin) + "\"  alt=\"" + Hierarchy_Object.ShortName + "\" /></a>");
                        Output.WriteLine("</section>");
                    }
                    else
                    {
                        string skin_url = CurrentMode.Base_Design_URL + "skins/" + CurrentMode.Skin + "/";
                        Output.WriteLine("<section id=\"sbkAhs_BannerDiv\" role=\"banner\"><h1 class=\"hidden-element\">" + Web_Page_Title + "</h1><a href=\"" + CurrentMode.Base_URL + url_options + "\"><img id=\"mainBanner\" src=\"" + skin_url + "default.jpg\" alt=\"\" /></a></section>");
                    }
                }
            }

            Output.WriteLine();
        }
        /// <summary> Builds a language-specific <see cref="Web_Skin_Object"/> when needed by a user's request </summary>
        /// <param name="CompleteSkin"> Complete web skin object </param>
        /// <param name="Language_Code"> Code for the language, which determines which HTML to use </param>
        /// <param name="Tracer"></param>
        /// <returns> Completely built HTML interface object </returns>
        /// <remarks> The datarow for this method is retrieved from the database by calling the <see cref="Database.Engine_Database.Get_All_Web_Skins"/> method during
        /// application startup and is then stored in the <see cref="Web_Skin_Collection"/> class until needed. </remarks>
        public static Web_Skin_Object Build_Skin(Complete_Web_Skin_Object CompleteSkin, string Language_Code, Custom_Tracer Tracer)
        {
            // Look for the language
            Web_Language_Enum language          = Web_Language_Enum_Converter.Code_To_Enum(Language_Code);
            Web_Language_Enum original_language = language;

            if (!CompleteSkin.SourceFiles.ContainsKey(language))
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Language requested ( " + Web_Language_Enum_Converter.Enum_To_Name(language) + " ) not in language list");
                }

                language = Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language;
                if ((original_language == language) || (!CompleteSkin.SourceFiles.ContainsKey(language)))
                {
                    if ((Tracer != null) && (original_language != language))
                    {
                        Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Default UI language ( " + Web_Language_Enum_Converter.Enum_To_Name(language) + " ) not in language list");
                    }

                    language = Web_Language_Enum.DEFAULT;
                    if (!CompleteSkin.SourceFiles.ContainsKey(language))
                    {
                        if (Tracer != null)
                        {
                            Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "DEFAULT language not in language list");
                        }

                        language = Web_Language_Enum.English;

                        if (!CompleteSkin.SourceFiles.ContainsKey(language))
                        {
                            if (Tracer != null)
                            {
                                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "English language also not in language list");
                            }

                            if (CompleteSkin.SourceFiles.Count > 0)
                            {
                                language = CompleteSkin.SourceFiles.Keys.First();
                            }
                            else
                            {
                                if (Tracer != null)
                                {
                                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Apparently there are NO source files.. returning NULL");
                                }
                                language = Web_Language_Enum.UNDEFINED;
                            }
                        }
                    }
                }
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Will build language-specific web skin for '" + Web_Language_Enum_Converter.Enum_To_Name(language) + "'");
            }

            // Now, look in the cache for this
            if (language != Web_Language_Enum.UNDEFINED)
            {
                Web_Skin_Object cacheObject = CachedDataManager.WebSkins.Retrieve_Skin(CompleteSkin.Skin_Code, Web_Language_Enum_Converter.Enum_To_Code(language), null);
                if (cacheObject != null)
                {
                    if (Tracer != null)
                    {
                        Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Web skin found in the memory cache");
                    }

                    return(cacheObject);
                }
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Web skin not found in the memory cache, so building it now");
            }

            // Build this then
            Web_Skin_Object returnValue = new Web_Skin_Object(CompleteSkin.Skin_Code, CompleteSkin.Base_Skin_Code);

            if (!String.IsNullOrEmpty(CompleteSkin.CSS_Style))
            {
                returnValue.CSS_Style = "design/skins/" + CompleteSkin.Skin_Code + "/" + CompleteSkin.CSS_Style;
            }
            if (!String.IsNullOrEmpty(CompleteSkin.Javascript_File))
            {
                returnValue.Javascript = "design/skins/" + CompleteSkin.Skin_Code + "/" + CompleteSkin.Javascript_File;
            }

            // Set the language code
            if (language == Web_Language_Enum.DEFAULT)
            {
                returnValue.Language_Code = Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language);
            }
            else if (language == Web_Language_Enum.UNDEFINED)
            {
                returnValue.Language_Code = Web_Language_Enum_Converter.Enum_To_Code(language);
            }

            // Set some optional (nullable) flags
            if (CompleteSkin.Override_Banner)
            {
                returnValue.Override_Banner = true;
            }
            if (CompleteSkin.Suppress_Top_Navigation)
            {
                returnValue.Suppress_Top_Navigation = true;
            }

            // If no suitable language was found, probably an error (no source files at all)
            if (language == Web_Language_Enum.UNDEFINED)
            {
                if (!String.IsNullOrEmpty(CompleteSkin.Exception))
                {
                    returnValue.Exception = CompleteSkin.Exception;
                }
                else
                {
                    returnValue.Exception = "No valid source files found";
                }

                // Also set the headers and footers to the exception
                returnValue.Header_HTML      = returnValue.Exception;
                returnValue.Footer_HTML      = returnValue.Exception;
                returnValue.Header_Item_HTML = returnValue.Exception;
                returnValue.Footer_Item_HTML = returnValue.Exception;

                return(returnValue);
            }

            // Get the source file
            Complete_Web_Skin_Source_Files sourceFiles = CompleteSkin.SourceFiles[language];

            // Build the banner
            if ((returnValue.Override_Banner.HasValue) && (returnValue.Override_Banner.Value))
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Skin overrides the banner, so build the banner HTML");
                }

                // Find the LANGUAGE-SPECIFIC high-bandwidth banner image
                if (!String.IsNullOrEmpty(sourceFiles.Banner))
                {
                    if (!String.IsNullOrEmpty(CompleteSkin.Banner_Link))
                    {
                        returnValue.Banner_HTML = "<a href=\"" + CompleteSkin.Banner_Link + "\"><img border=\"0\" src=\"<%BASEURL%>skins/" + CompleteSkin.Skin_Code + "/" + sourceFiles.Banner + "\" alt=\"MISSING BANNER\" /></a>";
                    }
                    else
                    {
                        returnValue.Banner_HTML = "<img border=\"0\" src=\"<%BASEURL%>skins/" + CompleteSkin.Skin_Code + "/" + sourceFiles.Banner + "\" alt=\"MISSING BANNER\" />";
                    }
                }
            }

            // Now, set the header and footer html
            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Determine the header footer source HTML files");
            }
            string this_header      = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Header_Source_File);
            string this_footer      = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Footer_Source_File);
            string this_item_header = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Header_Item_Source_File);
            string this_item_footer = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Footer_Item_Source_File);

            // If the item specific stuff doesn't exist, use the regular
            if (!File.Exists(this_item_header))
            {
                this_item_header = this_header;
            }
            if (!File.Exists(this_item_footer))
            {
                this_item_footer = this_footer;
            }

            // Now, assign all of these
            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Get the HTML source for all the headers and footers");
            }
            returnValue.Set_Header_Footer_Source(this_header, this_footer, this_item_header, this_item_footer);

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Returning the fully built web skin");
            }
            return(returnValue);
        }
Ejemplo n.º 8
0
        /// <summary> Constructor for a new instance of the Html_MainWriter class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        public Html_MainWriter(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            // Add a trace
            RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", "");

            // Check the IE hack CSS is loaded
            if (HttpContext.Current.Application["NonIE_Hack_CSS"] == null)
            {
                string css_file = HttpContext.Current.Server.MapPath("default/SobekCM_NonIE.css");
                if (File.Exists(css_file))
                {
                    try
                    {
                        StreamReader reader = new StreamReader(css_file);
                        HttpContext.Current.Application["NonIE_Hack_CSS"] = reader.ReadToEnd().Trim();
                        reader.Close();
                    }
                    catch (Exception)
                    {
                        HttpContext.Current.Application["NonIE_Hack_CSS"] = "/* ERROR READING FILE: default/SobekCM_NonIE.css */";
                        throw;
                    }
                }
                else
                {
                    HttpContext.Current.Application["NonIE_Hack_CSS"] = String.Empty;
                }
            }

            // Handle basic events which may be fired by the internal header
            if (HttpContext.Current.Request.Form["internal_header_action"] != null)
            {
                // Pull the action value
                string internalHeaderAction = HttpContext.Current.Request.Form["internal_header_action"].Trim();

                // Was this to hide or show the header?
                if ((internalHeaderAction == "hide") || (internalHeaderAction == "show"))
                {
                    // Pull the current visibility from the session
                    bool shown = !((HttpContext.Current.Session["internal_header"] != null) && (HttpContext.Current.Session["internal_header"].ToString() == "hidden"));
                    if ((internalHeaderAction == "hide") && (shown))
                    {
                        HttpContext.Current.Session["internal_header"] = "hidden";
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                        return;
                    }
                    if ((internalHeaderAction == "show") && (!shown))
                    {
                        HttpContext.Current.Session["internal_header"] = "shown";
                        UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                        return;
                    }
                }
            }

            try
            {
                // Create the html sub writer now
                switch (RequestSpecificValues.Current_Mode.Mode)
                {
                case Display_Mode_Enum.Internal:
                    subwriter = new Internal_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Statistics:
                    subwriter = new Statistics_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Preferences:
                    subwriter = new Preferences_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Empty:
                    subwriter = new Empty_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Error:
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                    // Send the email now
                    if (RequestSpecificValues.Current_Mode.Caught_Exception != null)
                    {
                        if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Error_Message))
                        {
                            RequestSpecificValues.Current_Mode.Error_Message = "Unknown exception caught";
                        }
                        Email_Information(RequestSpecificValues.Current_Mode.Error_Message, RequestSpecificValues.Current_Mode.Caught_Exception, RequestSpecificValues.Tracer, false);
                    }
                    break;

                case Display_Mode_Enum.Legacy_URL:
                    subwriter = new LegacyUrl_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Item_Print:
                    subwriter = new Print_Item_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Contact:
                    StringBuilder builder = new StringBuilder();
                    builder.Append("\n\nSUBMISSION INFORMATION\n");
                    builder.Append("\tDate:\t\t\t\t" + DateTime.Now.ToString() + "\n");
                    string lastMode = String.Empty;
                    try
                    {
                        if (HttpContext.Current.Session["Last_Mode"] != null)
                        {
                            lastMode = HttpContext.Current.Session["Last_Mode"].ToString();
                        }
                        builder.Append("\tIP Address:\t\t\t" + HttpContext.Current.Request.UserHostAddress + "\n");
                        builder.Append("\tHost Name:\t\t\t" + HttpContext.Current.Request.UserHostName + "\n");
                        builder.Append("\tBrowser:\t\t\t" + HttpContext.Current.Request.Browser.Browser + "\n");
                        builder.Append("\tBrowser Platform:\t\t" + HttpContext.Current.Request.Browser.Platform + "\n");
                        builder.Append("\tBrowser Version:\t\t" + HttpContext.Current.Request.Browser.Version + "\n");
                        builder.Append("\tBrowser Language:\t\t");
                        bool     first     = true;
                        string[] languages = HttpContext.Current.Request.UserLanguages;
                        if (languages != null)
                        {
                            foreach (string thisLanguage in languages)
                            {
                                if (first)
                                {
                                    builder.Append(thisLanguage);
                                    first = false;
                                }
                                else
                                {
                                    builder.Append(", " + thisLanguage);
                                }
                            }
                        }

                        builder.Append("\n\nHISTORY\n");
                        if (HttpContext.Current.Session["LastSearch"] != null)
                        {
                            builder.Append("\tLast Search:\t\t" + HttpContext.Current.Session["LastSearch"] + "\n");
                        }
                        if (HttpContext.Current.Session["LastResults"] != null)
                        {
                            builder.Append("\tLast Results:\t\t" + HttpContext.Current.Session["LastResults"] + "\n");
                        }
                        if (HttpContext.Current.Session["Last_Mode"] != null)
                        {
                            builder.Append("\tLast Mode:\t\t\t" + HttpContext.Current.Session["Last_Mode"] + "\n");
                        }
                        builder.Append("\tURL:\t\t\t\t" + HttpContext.Current.Items["Original_URL"]);
                    }
                    catch
                    {
                    }
                    subwriter = new Contact_HtmlSubwriter(lastMode, builder.ToString(), RequestSpecificValues);
                    break;


                case Display_Mode_Enum.Contact_Sent:
                    subwriter = new Contact_HtmlSubwriter(String.Empty, String.Empty, RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Simple_HTML_CMS:
                    subwriter = new Web_Content_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.My_Sobek:
                    subwriter = new MySobek_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Administrative:
                    subwriter = new Admin_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Results:
                    subwriter = new Search_Results_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Public_Folder:
                    subwriter = new Public_Folder_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Search:
                case Display_Mode_Enum.Aggregation:
                    subwriter = new Aggregation_HtmlSubwriter(RequestSpecificValues);
                    break;

                case Display_Mode_Enum.Item_Display:
                    if ((!RequestSpecificValues.Current_Mode.Invalid_Item.HasValue || !RequestSpecificValues.Current_Mode.Invalid_Item.Value))
                    {
                        // Create the item viewer writer
                        subwriter = new Item_HtmlSubwriter(RequestSpecificValues);
                    }
                    else
                    {
                        // Create the invalid item html subwrite and write the HTML
                        subwriter = new Error_HtmlSubwriter(true, RequestSpecificValues);
                    }
                    break;
                }

                // Might be redirected
                if (RequestSpecificValues.Current_Mode.Request_Completed)
                {
                    return;
                }

                // Now, look for error or the web content, which is also often
                // used for resource missing type errors
                switch (RequestSpecificValues.Current_Mode.Mode)
                {
                case Display_Mode_Enum.Error:
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                    // Send the email now
                    if (RequestSpecificValues.Current_Mode.Caught_Exception != null)
                    {
                        if (String.IsNullOrEmpty(RequestSpecificValues.Current_Mode.Error_Message))
                        {
                            RequestSpecificValues.Current_Mode.Error_Message = "Unknown exception caught";
                        }
                        Email_Information(RequestSpecificValues.Current_Mode.Error_Message, RequestSpecificValues.Current_Mode.Caught_Exception, RequestSpecificValues.Tracer, false);
                    }
                    break;

                case Display_Mode_Enum.Simple_HTML_CMS:
                    subwriter = new Web_Content_HtmlSubwriter(RequestSpecificValues);
                    break;
                }

                // Now, pull the web skin
                SobekCM_Assistant assistant = new SobekCM_Assistant();

                // Try to get the web skin from the cache or skin collection, otherwise build it
                Web_Skin_Object htmlSkin = assistant.Get_HTML_Skin(RequestSpecificValues.Current_Mode.Skin, RequestSpecificValues.Current_Mode, UI_ApplicationCache_Gateway.Web_Skin_Collection, true, RequestSpecificValues.Tracer);

                // If the skin was somehow overriden, default back to the default skin
                string defaultSkin = RequestSpecificValues.Current_Mode.Base_Skin;
                if ((htmlSkin == null) && (!String.IsNullOrEmpty(defaultSkin)))
                {
                    if (String.Compare(RequestSpecificValues.Current_Mode.Skin, defaultSkin, StringComparison.InvariantCultureIgnoreCase) != 0)
                    {
                        RequestSpecificValues.Current_Mode.Skin = defaultSkin;
                        htmlSkin = assistant.Get_HTML_Skin(defaultSkin, RequestSpecificValues.Current_Mode, UI_ApplicationCache_Gateway.Web_Skin_Collection, true, RequestSpecificValues.Tracer);
                    }
                }

                // If there was no web skin returned, forward user to URL with no web skin.
                // This happens if the web skin code is invalid.  If a robot, just return a bad request
                // value though.
                if (htmlSkin == null)
                {
                    HttpContext.Current.Response.StatusCode = 404;
                    HttpContext.Current.Response.Output.WriteLine("404 - INVALID URL");
                    HttpContext.Current.Response.Output.WriteLine("Web skin indicated is invalid, default web skin invalid - line 1029");
                    HttpContext.Current.Response.Output.WriteLine(RequestSpecificValues.Tracer.Text_Trace);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    RequestSpecificValues.Current_Mode.Request_Completed = true;

                    return;
                }

                RequestSpecificValues.HTML_Skin = htmlSkin;
            }
            catch (Exception ee)
            {
                // Send to the dashboard
                if ((HttpContext.Current.Request.UserHostAddress == "127.0.0.1") || (HttpContext.Current.Request.UserHostAddress == HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]) || (HttpContext.Current.Request.Url.ToString().IndexOf("localhost") >= 0))
                {
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", "Exception caught!", Custom_Trace_Type_Enum.Error);
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", ee.Message, Custom_Trace_Type_Enum.Error);
                    RequestSpecificValues.Tracer.Add_Trace("Html_MainWriter.Constructor", ee.StackTrace, Custom_Trace_Type_Enum.Error);

                    // Wrap this into the SobekCM Exception
                    SobekCM_Traced_Exception newException = new SobekCM_Traced_Exception("Exception caught while building the mode-specific HTML Subwriter", ee, RequestSpecificValues.Tracer);

                    // Save this to the session state, and then forward to the dashboard
                    HttpContext.Current.Session["Last_Exception"] = newException;
                    HttpContext.Current.Response.Redirect("dashboard.aspx", false);
                    RequestSpecificValues.Current_Mode.Request_Completed = true;
                }
                else
                {
                    subwriter = new Error_HtmlSubwriter(false, RequestSpecificValues);
                }
            }
        }