コード例 #1
0
 internal void Write_In_Configuration_XML_File(StreamWriter Writer)
 {
     Writer.WriteLine("    <hi:highlight>");
     Writer.WriteLine("      <hi:source>" + Image + "</hi:source>");
     if (Link.Length > 0)
     {
         Writer.WriteLine("      <hi:link>" + Link + "</hi:link>");
     }
     foreach (KeyValuePair <Web_Language_Enum, string> thisTooltip in tooltips)
     {
         if (thisTooltip.Key == Web_Language_Enum.UNDEFINED)
         {
             Writer.WriteLine("      <hi:tooltip>" + thisTooltip.Value + "</hi:tooltip>");
         }
         else
         {
             Writer.WriteLine("      <hi:tooltip lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisTooltip.Key) + "\">" + thisTooltip.Value + "</hi:tooltip>");
         }
     }
     foreach (KeyValuePair <Web_Language_Enum, string> thisText in text)
     {
         if (thisText.Key == Web_Language_Enum.UNDEFINED)
         {
             Writer.WriteLine("      <hi:text>" + thisText.Value + "</hi:text>");
         }
         else
         {
             Writer.WriteLine("      <hi:text lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisText.Key) + "\">" + thisText.Value + "</hi:text>");
         }
     }
     Writer.WriteLine("    </hi:highlight>");
 }
 internal void Write_Translations(StreamWriter writer)
 {
     foreach (KeyValuePair <Web_Language_Enum, string> translation in typeTranslations)
     {
         writer.WriteLine("\t\t\t\t\t<Translation language=\"" + Web_Language_Enum_Converter.Enum_To_Code(translation.Key) + "\" text=\"" + Convert_String_To_XML_Safe(translation.Value) + "\" />");
     }
 }
コード例 #3
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);
        }
        /// <summary>
        /// Store_s the content of the aggregation_ HTM l_ based_.
        /// </summary>
        /// <param name="Aggregation_Code">The aggregation_ code.</param>
        /// <param name="Language">The language.</param>
        /// <param name="ChildPageCode">The child page code.</param>
        /// <param name="StoreObject">The store object.</param>
        /// <param name="Tracer">The tracer.</param>
        public void Store_Aggregation_HTML_Based_Content(string Aggregation_Code, Web_Language_Enum Language, string ChildPageCode, HTML_Based_Content StoreObject, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager_AggregationServices.Store_Aggregation_HTML_Based_Content", "Entering Store_Aggregation_HTML_Based_Content method");
            }

            // If the cache is disabled, just return before even tracing
            if (settings.Disabled)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("CachedDataManager_AggregationServices.Store_Aggregation_HTML_Based_Content", "Caching is disabled");
                }
                return;
            }

            // Determine the key
            string key = "AGGR|" + Aggregation_Code.ToUpper() + "|" + Web_Language_Enum_Converter.Enum_To_Code(Language) + "|" + ChildPageCode;

            // Check the number of item aggregationPermissions currently locally cached
            const int LOCAL_EXPIRATION = 15;

            // Locally cache if this doesn't exceed the limit
            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager_AggregationServices.Store_Aggregation_HTML_Based_Content", "Adding object '" + key + "' to the local cache with expiration of " + LOCAL_EXPIRATION + " minute(s)");
            }

            HttpContext.Current.Cache.Insert(key, StoreObject, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(LOCAL_EXPIRATION));
        }
コード例 #5
0
        /// <summary> Constructor for a new instance of the simple aggregation class </summary>
        /// <param name="FullAggregation"> Full (language-specific) aggregation object </param>
        public Simple_Aggregation(Item_Aggregation FullAggregation)
        {
            // Assign the simple properties
            Language        = Web_Language_Enum_Converter.Enum_To_Code(FullAggregation.Language);
            ID              = FullAggregation.ID;
            Code            = FullAggregation.Code;
            Name            = FullAggregation.Name;
            BannerImage     = FullAggregation.BannerImage;
            Last_Item_Added = FullAggregation.Last_Item_Added;

            // Assign search fields
            if ((FullAggregation.Search_Fields != null) && (FullAggregation.Search_Fields.Count > 0))
            {
                Search_Fields = new List <Item_Aggregation_Metadata_Type>();
                foreach (Item_Aggregation_Metadata_Type searchField in FullAggregation.Search_Fields)
                {
                    Search_Fields.Add(new Item_Aggregation_Metadata_Type(searchField.DisplayTerm, searchField.SobekCode));
                }
            }

            // Assign browseable fields
            if ((FullAggregation.Browseable_Fields != null) && (FullAggregation.Browseable_Fields.Count > 0))
            {
                Browseable_Fields = new List <Item_Aggregation_Metadata_Type>();
                foreach (Item_Aggregation_Metadata_Type searchField in FullAggregation.Browseable_Fields)
                {
                    Browseable_Fields.Add(new Item_Aggregation_Metadata_Type(searchField.DisplayTerm, searchField.SobekCode));
                }
            }

            // Assign searches and views
            if ((FullAggregation.Views_And_Searches != null) && (FullAggregation.Views_And_Searches.Count > 0))
            {
                Views_And_Searches = new List <string>();
                foreach (Item_Aggregation_Views_Searches_Enum viewEnum in FullAggregation.Views_And_Searches)
                {
                    Views_And_Searches.Add(viewEnum.ToString("G"));
                }
            }

            // Assign the name and code of each child page
            if ((FullAggregation.Child_Pages != null) && (FullAggregation.Child_Pages.Count > 0))
            {
                Child_Pages = new List <Simple_Aggregation_Child_Page>();
                foreach (Item_Aggregation_Child_Page thisChild in FullAggregation.Child_Pages)
                {
                    Child_Pages.Add(new Simple_Aggregation_Child_Page(thisChild.Code, thisChild.Label));
                }
            }
        }
コード例 #6
0
        protected void Write_Lang_Code()
        {
            // If the was a very basic error, or the request was complete, do nothing here
            if ((pageGlobals.currentMode == null) || (pageGlobals.currentMode.Request_Completed))
            {
                return;
            }

            if (pageGlobals.currentMode.Language == Web_Language_Enum.DEFAULT)
            {
                Response.Output.Write(Web_Language_Enum_Converter.Enum_To_Code(UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language));
            }
            else
            {
                Response.Output.Write(Web_Language_Enum_Converter.Enum_To_Code(pageGlobals.currentMode.Language));
            }
        }
コード例 #7
0
        /// <summary> Gets the item aggregation and search fields for the current item aggregation </summary>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <param name="Aggregation_Object"> [OUT] Fully-built object for the current aggregation object </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        /// <remarks> This attempts to pull the objects from the cache.  If unsuccessful, it builds the objects from the
        /// database and hands off to the <see cref="CachedDataManager" /> to store in the cache. </remarks>
        protected static bool Get_Top_Level_Collection(Navigation_Object Current_Mode, Custom_Tracer Tracer, out Item_Aggregation Aggregation_Object)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("abstractHtmlSubwriter.Get_Top_Level_Collection", String.Empty);
            }

            string languageCode = Web_Language_Enum_Converter.Enum_To_Code(Current_Mode.Language);

            // Get the ALL collection group
            try
            {
                // Try to pull this from the cache
                Aggregation_Object = CachedDataManager.Aggregations.Retrieve_Item_Aggregation("all", Web_Language_Enum_Converter.Code_To_Enum(languageCode), Tracer);
                if (Aggregation_Object != null)
                {
                    return(true);
                }

                // Get the item aggregation from the Sobek Engine Client
                Aggregation_Object = SobekEngineClient.Aggregations.Get_Aggregation("all", Web_Language_Enum_Converter.Code_To_Enum(languageCode), UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language, Tracer);
            }
            catch (Exception ee)
            {
                Aggregation_Object         = null;
                Current_Mode.Error_Message = "Error pulling the item aggregation corresponding to all collection groups : " + ee.Message;
                return(false);
            }

            // If this is null, just stop
            if (Aggregation_Object == null)
            {
                Current_Mode.Error_Message = "Unable to pull the item aggregation corresponding to all collection groups";
                return(false);
            }

            return(true);
        }
コード例 #8
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> Retrieves the item aggregation obejct from the cache  </summary>
        /// <param name="AggregationCode"> Code for the item aggregation to retrieve </param>
        /// <param name="Language"> Current language code (item aggregation instances are currently language-specific)</param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns> Either NULL or the item aggregation object </returns>
        public Item_Aggregation Retrieve_Item_Aggregation(string AggregationCode, Web_Language_Enum Language, Custom_Tracer Tracer)
        {
            // If the cache is disabled, just return before even tracing
            if ((settings.Disabled) || (HttpContext.Current == null))
            {
                return(null);
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager.Retrieve_Item_Aggregation", "");
            }

            // Determine the key
            string languageCode = Web_Language_Enum_Converter.Enum_To_Code(Language);
            string key          = "AGGR|" + AggregationCode.ToUpper() + "|" + languageCode;

            // See if this is in the local cache first
            Item_Aggregation returnValue = HttpContext.Current.Cache.Get(key) as Item_Aggregation;

            if (returnValue != null)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("CachedDataManager.Retrieve_Item_Aggregation", "Found " + AggregationCode + " item aggregation on local cache for " + languageCode);
                }

                return(returnValue);
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager.Retrieve_Item_Aggregation", "Aggregation ( " + AggregationCode + " ) not found in the local cache for " + languageCode);
            }

            // Since everything failed, just return null
            return(null);
        }
        /// <summary> Retrieve the aggregation-level static HTML browse object, including the text itself, from the cache </summary>
        /// <param name="Aggregation_Code"> Aggregation code </param>
        /// <param name="Language"> Requested language version </param>
        /// <param name="ChildPageCode"> Code for the child page in question </param>
        /// <param name="Tracer">The tracer.</param>
        /// <returns> Fully built object with the information about the aggregation-level HTML browse object </returns>
        public HTML_Based_Content Retrieve_Aggregation_HTML_Based_Content(string Aggregation_Code, Web_Language_Enum Language, string ChildPageCode, Custom_Tracer Tracer)
        {
            // If the cache is disabled, just return before even tracing
            if (settings.Disabled)
            {
                return(null);
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager_AggregationServices.Retrieve_Aggregation_HTML_Based_Content", "");
            }

            // Determine the key
            string key = "AGGR|" + Aggregation_Code.ToUpper() + "|" + Web_Language_Enum_Converter.Enum_To_Code(Language) + "|" + ChildPageCode;

            // See if this is in the local cache first
            HTML_Based_Content returnValue = HttpContext.Current.Cache.Get(key) as HTML_Based_Content;

            if (returnValue != null)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("CachedDataManager_AggregationServices.Retrieve_Aggregation_HTML_Based_Content", "Found aggregation HTML based content on local cache");
                }

                return(returnValue);
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager_AggregationServices.Retrieve_Aggregation_HTML_Based_Content", "Aggregation HTML based content not found in either the local cache");
            }

            // Since everything failed, just return null
            return(null);
        }
コード例 #11
0
        /// <summary> Gets the item aggregation and search fields for the current item aggregation </summary>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <param name="Aggregation_Object"> [OUT] Fully-built object for the current aggregation object </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        /// <remarks> This attempts to pull the objects from the cache.  If unsuccessful, it builds the objects from the
        /// database and hands off to the <see cref="CachedDataManager" /> to store in the cache. </remarks>
        protected static bool Get_Collection(Navigation_Object Current_Mode, Custom_Tracer Tracer, out Item_Aggregation Aggregation_Object)
        {
            string languageCode = Web_Language_Enum_Converter.Enum_To_Code(Current_Mode.Language);

            if (Tracer != null)
            {
                Tracer.Add_Trace("abstractHtmlSubwriter.Get_Collection", "Get aggregation (" + Current_Mode.Aggregation + ") or (" + Current_Mode.Default_Aggregation + ") for language (" + languageCode + ")");
            }

            // If there is an aggregation listed, try to get that now
            if ((Current_Mode.Aggregation.Length > 0) && (Current_Mode.Aggregation != "all"))
            {
                // Try to pull the aggregation information
                Aggregation_Object = CachedDataManager.Aggregations.Retrieve_Item_Aggregation(Current_Mode.Aggregation, Web_Language_Enum_Converter.Code_To_Enum(languageCode), Tracer);
                if (Aggregation_Object != null)
                {
                    set_web_skin_from_aggregation(Current_Mode, Aggregation_Object);
                    return(true);
                }

                // Get the item aggregation from the Sobek Engine Client (which checks the local cache as well)
                Aggregation_Object = SobekEngineClient.Aggregations.Get_Aggregation(Current_Mode.Aggregation, Web_Language_Enum_Converter.Code_To_Enum(languageCode), UI_ApplicationCache_Gateway.Settings.System.Default_UI_Language, Tracer);

                // Return if this was valid
                if (Aggregation_Object != null)
                {
                    set_web_skin_from_aggregation(Current_Mode, Aggregation_Object);
                    return(true);
                }

                Current_Mode.Error_Message = "Invalid item aggregation '" + Current_Mode.Aggregation + "' referenced.";
                return(false);
            }

            return(Get_Top_Level_Collection(Current_Mode, Tracer, out Aggregation_Object));
        }
        /// <summary> Stores the item aggregation object to the cache  </summary>
        /// <param name="AggregationCode"> Code for the item aggregation to store </param>
        /// <param name="Language"> Current language code (item aggregation instances are currently language-specific)</param>
        /// <param name="StoreObject"> Item aggregation object to store for later retrieval </param>
        /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering</param>
        public void Store_Item_Aggregation(string AggregationCode, Web_Language_Enum Language, Item_Aggregation StoreObject, Custom_Tracer Tracer)
        {
            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager.Store_Item_Aggregation", "Entering Store_Item_Aggregation method");
            }

            // Don't store nulls
            if (StoreObject == null)
            {
                return;
            }

            // If the cache is disabled, just return before even tracing
            if (settings.Disabled)
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("CachedDataManager.Store_Item_Aggregation", "Caching is disabled");
                }
                return;
            }

            // Determine the key
            string key = "AGGR|" + AggregationCode.ToUpper() + "|" + Web_Language_Enum_Converter.Enum_To_Code(Language);

            const int LOCAL_EXPIRATION = 15;

            // Locally cache if this doesn't exceed the limit
            if (Tracer != null)
            {
                Tracer.Add_Trace("CachedDataManager.Store_Item_Aggregation", "Adding object '" + key + "' to the local cache with expiration of " + LOCAL_EXPIRATION + " minute(s)");
            }

            HttpContext.Current.Cache.Insert(key, StoreObject, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(LOCAL_EXPIRATION));
        }
コード例 #13
0
        internal void Write_In_Configuration_XML_File(System.IO.StreamWriter Writer, string Default_BrowseBy)
        {
            string type = "browse";

            if (browseType == Browse_Info_Type.Info)
            {
                type = "info";
            }

            if (browseType == Browse_Info_Type.Browse_By)
            {
                Writer.WriteLine(String.Compare(Default_BrowseBy, code, true) == 0 ? "  <hi:browse location=\"BROWSEBY\" default=\"DEFAULT\">" : "  <hi:browse location=\"BROWSEBY\">");
            }
            else
            {
                Writer.WriteLine("  <hi:" + type + ">");
            }

            // Is this a database option, (usually browse by)?
            if (source == Source_Type.Database)
            {
                Writer.WriteLine("    <hi:metadata>" + code.ToUpper() + "</hi:metadata>");
            }
            else
            {
                // Write the code for this static html sourced browse/info
                Writer.WriteLine("    <hi:code>" + code.ToLower() + "</hi:code>");

                // Include the titles, or just use the code as the title if no titles given
                Writer.WriteLine("    <hi:titles>");
                if (labelsByLanguage.Count > 0)
                {
                    foreach (KeyValuePair <Web_Language_Enum, string> thisLabel in labelsByLanguage)
                    {
                        if (thisLabel.Key == Web_Language_Enum.DEFAULT)
                        {
                            Writer.WriteLine("    <hi:title>" + thisLabel.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:title>");
                        }
                        else
                        {
                            Writer.WriteLine("    <hi:title lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisLabel.Key) + "\">" + thisLabel.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:title>");
                        }
                    }
                }
                else
                {
                    Writer.WriteLine("    <hi:title>" + code + "</hi:title>");
                }
                Writer.WriteLine("    </hi:titles>");

                // Include the sources as well
                Writer.WriteLine("    <hi:content>");
                foreach (KeyValuePair <Web_Language_Enum, string> thisSource in staticHtmlSourceByLanguage)
                {
                    if (thisSource.Key == Web_Language_Enum.DEFAULT)
                    {
                        Writer.WriteLine("    <hi:body>" + thisSource.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:body>");
                    }
                    else
                    {
                        Writer.WriteLine("    <hi:body lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisSource.Key) + "\">" + thisSource.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:body>");
                    }
                }
                Writer.WriteLine("    </hi:content>");
            }


            Writer.WriteLine("  </hi:" + type + ">");
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        /// <summary> Add a new aggregation to the system </summary>
        /// <param name="NewAggregation"> Information for the new aggregation </param>
        /// <returns> Message indicating success or any errors encountered </returns>
        public static RestResponseMessage add_new_aggregation(New_Aggregation_Arguments NewAggregation)
        {
            // Convert to the integer id for the parent and begin to do checking
            List <string> errors   = new List <string>();
            int           parentid = -1;

            if (NewAggregation.ParentCode.Length > 0)
            {
                Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes[NewAggregation.ParentCode];
                if (parentAggr != null)
                {
                    parentid = parentAggr.ID;
                }
                else
                {
                    errors.Add("Parent code is not valid");
                }
            }
            else
            {
                errors.Add("You must select a PARENT for this new aggregation");
            }

            // Validate the code

            if (NewAggregation.Code.Length > 20)
            {
                errors.Add("New aggregation code must be twenty characters long or less");
            }
            else if (NewAggregation.Code.Length == 0)
            {
                errors.Add("You must enter a CODE for this item aggregation");
            }
            else if (Engine_ApplicationCache_Gateway.Codes[NewAggregation.Code.ToUpper()] != null)
            {
                errors.Add("New code must be unique... <i>" + NewAggregation.Code + "</i> already exists");
            }
            else if (Engine_ApplicationCache_Gateway.Settings.Static.Reserved_Keywords.Contains(NewAggregation.Code.ToLower()))
            {
                errors.Add("That code is a system-reserved keyword.  Try a different code.");
            }
            else
            {
                bool alphaNumericTest = NewAggregation.Code.All(C => Char.IsLetterOrDigit(C) || C == '_' || C == '-');
                if (!alphaNumericTest)
                {
                    errors.Add("New aggregation code must be only letters and numbers");
                    NewAggregation.Code = NewAggregation.Code.Replace("\"", "");
                }
            }

            // Was there a type and name
            if (NewAggregation.Type.Length == 0)
            {
                errors.Add("You must select a TYPE for this new aggregation");
            }
            if (NewAggregation.Description.Length == 0)
            {
                errors.Add("You must enter a DESCRIPTION for this new aggregation");
            }
            if (NewAggregation.Name.Length == 0)
            {
                errors.Add("You must enter a NAME for this new aggregation");
            }
            else
            {
                if (NewAggregation.ShortName.Length == 0)
                {
                    NewAggregation.ShortName = NewAggregation.Name;
                }
            }

            // Check for the thematic heading
            int thematicHeadingId = -1;

            if (!String.IsNullOrEmpty(NewAggregation.Thematic_Heading))
            {
                // Look for the matching thematic heading
                foreach (Thematic_Heading thisHeading in Engine_ApplicationCache_Gateway.Thematic_Headings)
                {
                    if (String.Compare(thisHeading.Text, NewAggregation.Thematic_Heading, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        thematicHeadingId = thisHeading.ID;
                        break;
                    }
                }

                // If there was no match, the thematic heading was invalid, unless it was new
                if (thematicHeadingId < 0)
                {
                    if ((!NewAggregation.NewThematicHeading.HasValue) || (!NewAggregation.NewThematicHeading.Value))
                    {
                        errors.Add("Invalid thematic heading indicated");
                    }
                    else if (errors.Count == 0)
                    {
                        // Add the thematic heading first
                        if ((thematicHeadingId < 0) && (NewAggregation.NewThematicHeading.HasValue) && (NewAggregation.NewThematicHeading.Value))
                        {
                            thematicHeadingId = Engine_Database.Edit_Thematic_Heading(-1, 10, NewAggregation.Thematic_Heading, null);
                        }
                    }
                }
            }

            if (errors.Count > 0)
            {
                // Create the error message
                StringBuilder actionMessage = new StringBuilder("ERROR: Invalid entry for new item aggregation.<br />");
                foreach (string error in errors)
                {
                    actionMessage.Append("<br />" + error);
                }

                return(new RestResponseMessage(ErrorRestTypeEnum.InputError, actionMessage.ToString()));
            }



            string language = Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language);

            // Try to save the new item aggregation
            if (!Engine_Database.Save_Item_Aggregation(NewAggregation.Code, NewAggregation.Name, NewAggregation.ShortName, NewAggregation.Description, thematicHeadingId, NewAggregation.Type, NewAggregation.Active, NewAggregation.Hidden, NewAggregation.External_Link, parentid, NewAggregation.User, language, null))
            {
                return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR saving the new item aggregation to the database"));
            }
            // Ensure a folder exists for this, otherwise create one
            try
            {
                string folder = Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + NewAggregation.Code.ToLower();
                if (!Directory.Exists(folder))
                {
                    // Create this directory and all the subdirectories
                    Directory.CreateDirectory(folder);
                    Directory.CreateDirectory(folder + "/html");
                    Directory.CreateDirectory(folder + "/images");
                    Directory.CreateDirectory(folder + "/html/home");
                    Directory.CreateDirectory(folder + "/html/custom/home");
                    Directory.CreateDirectory(folder + "/images/buttons");
                    Directory.CreateDirectory(folder + "/images/banners");
                    Directory.CreateDirectory(folder + "/uploads");

                    // Get the parent name
                    string link_to_parent = String.Empty;
                    Item_Aggregation_Related_Aggregations parentAggr = Engine_ApplicationCache_Gateway.Codes.Aggregation_By_ID(parentid);
                    if (parentAggr != null)
                    {
                        if (String.Compare(parentAggr.Code, "all", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            link_to_parent = "<p>&larr; Back to <a href=\"<%BASEURL%>\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine;
                        }
                        else
                        {
                            link_to_parent = "<p>&larr; Back to <a href=\"<%BASEURL%>" + parentAggr.Code + "\" alt=\"Return to parent collection\">" + parentAggr.Name + "</a></p>" + Environment.NewLine;
                        }
                    }

                    // Create a default home text file
                    StreamWriter writer = new StreamWriter(folder + "/html/home/text.html");
                    writer.WriteLine(link_to_parent + "<h3>About " + NewAggregation.Name + "</h3>" + Environment.NewLine + "<p>" + NewAggregation.Description + "</p>" + Environment.NewLine + "<p>To edit this, log on as the aggregation admin and hover over this text to edit it.</p>" + Environment.NewLine);

                    writer.Flush();
                    writer.Close();

                    // Was a button indicated, and does it exist?
                    if ((!String.IsNullOrEmpty(NewAggregation.ButtonFile)) && (File.Exists(NewAggregation.ButtonFile)))
                    {
                        File.Copy(NewAggregation.ButtonFile, folder + "/images/buttons/coll.gif");
                    }
                    else
                    {
                        // Copy the default banner and buttons from images
                        if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png"))
                        {
                            File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.png", folder + "/images/buttons/coll.png");
                        }
                        if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif"))
                        {
                            File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_button.gif", folder + "/images/buttons/coll.gif");
                        }
                    }

                    // Was a banner indicated, and does it exist?
                    string banner_file = String.Empty;
                    if ((!String.IsNullOrEmpty(NewAggregation.BannerFile)) && (File.Exists(NewAggregation.BannerFile)))
                    {
                        banner_file = "images/banners/" + Path.GetFileName(NewAggregation.BannerFile);
                        File.Copy(NewAggregation.BannerFile, folder + "//" + banner_file, true);
                    }
                    else
                    {
                        // Try to create a new custom banner
                        bool custom_banner_created = false;

                        // Create the banner with the name of the collection
                        if (Directory.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images"))
                        {
                            try
                            {
                                string[] banners = Directory.GetFiles(Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_Network + "\\default\\banner_images", "*.jpg");
                                if (banners.Length > 0)
                                {
                                    Random randomizer    = new Random();
                                    string banner_to_use = banners[randomizer.Next(0, banners.Length - 1)];
                                    Bitmap bitmap        = (Bitmap)(Image.FromFile(banner_to_use));

                                    RectangleF rectf = new RectangleF(30, bitmap.Height - 55, bitmap.Width - 40, 40);
                                    Graphics   g     = Graphics.FromImage(bitmap);
                                    g.SmoothingMode     = SmoothingMode.AntiAlias;
                                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                    g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                    g.DrawString(NewAggregation.Name, new Font("Tahoma", 25, FontStyle.Bold), Brushes.Black, rectf);
                                    g.Flush();

                                    string new_file = folder + "/images/banners/coll.jpg";
                                    if (!File.Exists(new_file))
                                    {
                                        bitmap.Save(new_file, ImageFormat.Jpeg);
                                        custom_banner_created = true;
                                        banner_file           = "images/banners/coll.jpg";
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                // Suppress this Error...
                            }
                        }

                        if ((!custom_banner_created) && (!File.Exists(folder + "/images/banners/coll.jpg")))
                        {
                            if (File.Exists(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg"))
                            {
                                banner_file = "images/banners/coll.jpg";
                                File.Copy(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Directory + "design/aggregations/default_banner.jpg", folder + "/images/banners/coll.jpg", true);
                            }
                        }
                    }

                    // Now, try to create the item aggregation and write the configuration file
                    Custom_Tracer             tracer          = new Custom_Tracer();
                    Complete_Item_Aggregation itemAggregation = SobekEngineClient.Aggregations.Get_Complete_Aggregation(NewAggregation.Code, true, tracer);
                    if (banner_file.Length > 0)
                    {
                        itemAggregation.Banner_Dictionary.Clear();
                        itemAggregation.Add_Banner_Image(banner_file, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language);
                    }
                    itemAggregation.Write_Configuration_File(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + itemAggregation.ObjDirectory);

                    // If an email shoudl be sent, do that now
                    if (String.Compare(Engine_ApplicationCache_Gateway.Settings.Email.Send_On_Added_Aggregation, "always", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        string user = String.Empty;
                        if (!String.IsNullOrEmpty(NewAggregation.User))
                        {
                            user = NewAggregation.User;
                        }

                        string body = "New aggregation added to this system:\n\n\tCode:\t" + itemAggregation.Code + "\n\tType:\t" + itemAggregation.Type + "\n\tName:\t" + itemAggregation.Name + "\n\tShort:\t" + itemAggregation.ShortName + "\n\tUser:\t" + user + "\n\n" + Engine_ApplicationCache_Gateway.Settings.Servers.Application_Server_URL + "/" + itemAggregation.Code;
                        Email_Helper.SendEmail(Engine_ApplicationCache_Gateway.Settings.Email.System_Email, "New " + itemAggregation.Type + " - " + itemAggregation.ShortName, body, false, Engine_ApplicationCache_Gateway.Settings.System.System_Name);
                    }
                }
            }
            catch
            {
                // Reload the list of all codes, to include this new one and the new hierarchy
                lock (Engine_ApplicationCache_Gateway.Codes)
                {
                    Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null);
                }

                return(new RestResponseMessage(ErrorRestTypeEnum.Exception, "ERROR completing the new aggregation add"));
            }

            // Reload the list of all codes, to include this new one and the new hierarchy
            lock (Engine_ApplicationCache_Gateway.Codes)
            {
                Engine_Database.Populate_Code_Manager(Engine_ApplicationCache_Gateway.Codes, null);
            }

            // Clear all aggregation information (and thematic heading info) from the cache as well
            CachedDataManager.Aggregations.Clear();

            return(new RestResponseMessage(ErrorRestTypeEnum.Successful, null));
        }
コード例 #16
0
        /// <summary> Saves the information about this item aggregation to the database </summary>
        /// <param name="ItemAggr"> Item aggregation object with all the information to be saved </param>
        /// <param name="Username"> Name of the user performing this save, for the item aggregation milestones</param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <returns>TRUE if successful, otherwise FALSE </returns>
        public static bool Save_To_Database(Complete_Item_Aggregation ItemAggr, string Username, Custom_Tracer Tracer)
        {
            // Build the list of language variants
            List <string> languageVariants = new List <string>
            {
                Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language)
            };

            if (ItemAggr.Home_Page_File_Dictionary != null)
            {
                foreach (Web_Language_Enum language in ItemAggr.Home_Page_File_Dictionary.Keys)
                {
                    string code = Web_Language_Enum_Converter.Enum_To_Code(language);
                    if (!languageVariants.Contains(code))
                    {
                        languageVariants.Add(code);
                    }
                }
            }
            if (ItemAggr.Banner_Dictionary != null)
            {
                foreach (Web_Language_Enum language in ItemAggr.Banner_Dictionary.Keys)
                {
                    string code = Web_Language_Enum_Converter.Enum_To_Code(language);
                    if (!languageVariants.Contains(code))
                    {
                        languageVariants.Add(code);
                    }
                }
            }
            if (ItemAggr.Child_Pages != null)
            {
                foreach (Complete_Item_Aggregation_Child_Page childPage in ItemAggr.Child_Pages)
                {
                    if (childPage.Label_Dictionary != null)
                    {
                        foreach (Web_Language_Enum language in childPage.Label_Dictionary.Keys)
                        {
                            string code2 = Web_Language_Enum_Converter.Enum_To_Code(language);
                            if (!languageVariants.Contains(code2))
                            {
                                languageVariants.Add(code2);
                            }
                        }
                    }
                    if (childPage.Source_Dictionary != null)
                    {
                        foreach (Web_Language_Enum language in childPage.Source_Dictionary.Keys)
                        {
                            string code2 = Web_Language_Enum_Converter.Enum_To_Code(language);
                            if (!languageVariants.Contains(code2))
                            {
                                languageVariants.Add(code2);
                            }
                        }
                    }
                }
            }
            StringBuilder languageVariantsBuilder = new StringBuilder();

            foreach (string language in languageVariants)
            {
                if (language.Length > 0)
                {
                    if (languageVariantsBuilder.Length > 0)
                    {
                        languageVariantsBuilder.Append("|" + language);
                    }
                    else
                    {
                        languageVariantsBuilder.Append(language);
                    }
                }
            }


            return(Engine_Database.Save_Item_Aggregation(ItemAggr.ID, ItemAggr.Code, ItemAggr.Name, ItemAggr.ShortName,
                                                         ItemAggr.Description, ItemAggr.Thematic_Heading, ItemAggr.Type, ItemAggr.Active, ItemAggr.Hidden,
                                                         ItemAggr.Display_Options, 0, ItemAggr.Map_Search_Beta, 0, ItemAggr.Map_Display_Beta,
                                                         ItemAggr.OAI_Enabled, ItemAggr.OAI_Metadata, ItemAggr.Contact_Email, String.Empty, ItemAggr.External_Link, -1, Username,
                                                         languageVariantsBuilder.ToString(), Tracer));
        }
コード例 #17
0
        internal void Write_In_Configuration_XML_File(System.IO.StreamWriter Writer, string Default_BrowseBy)
        {
            switch (Browse_Type)
            {
            case Visibility_Type.METADATA_BROWSE_BY:
                Writer.WriteLine(String.Compare(Default_BrowseBy, Code, StringComparison.OrdinalIgnoreCase) == 0 ? "  <hi:browse visibility=\"BROWSEBY\" default=\"DEFAULT\">" : "  <hi:browse visibility=\"BROWSEBY\">");
                break;

            case Visibility_Type.NONE:
                Writer.WriteLine("  <hi:browse visibility=\"NONE\">");
                break;

            case Visibility_Type.MAIN_MENU:
                Writer.WriteLine(String.IsNullOrEmpty(Parent_Code) ? "  <hi:browse visibility=\"MAIN_MENU\">" : "  <hi:browse visibility=\"MAIN_MENU\" parent=\"" + Parent_Code + "\">");
                break;
            }

            // Is this a database option, (usually browse by)?
            if (Source == Source_Type.Database)
            {
                Writer.WriteLine("    <hi:metadata>" + Code.ToUpper() + "</hi:metadata>");
            }
            else
            {
                // Write the code for this static html sourced browse/info
                Writer.WriteLine("    <hi:code>" + Code.ToLower() + "</hi:code>");

                // Include the titles, or just use the code as the title if no titles given
                Writer.WriteLine("    <hi:titles>");
                if (Label_Dictionary.Count > 0)
                {
                    foreach (KeyValuePair <Web_Language_Enum, string> thisLabel in Label_Dictionary)
                    {
                        if (thisLabel.Key == Web_Language_Enum.DEFAULT)
                        {
                            Writer.WriteLine("    <hi:title>" + thisLabel.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:title>");
                        }
                        else
                        {
                            Writer.WriteLine("    <hi:title lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisLabel.Key) + "\">" + thisLabel.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:title>");
                        }
                    }
                }
                else
                {
                    Writer.WriteLine("    <hi:title>" + Code + "</hi:title>");
                }
                Writer.WriteLine("    </hi:titles>");

                // Include the sources as well
                Writer.WriteLine("    <hi:content>");
                foreach (KeyValuePair <Web_Language_Enum, string> thisSource in Source_Dictionary)
                {
                    if (thisSource.Key == Web_Language_Enum.DEFAULT)
                    {
                        Writer.WriteLine("    <hi:body>" + thisSource.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:body>");
                    }
                    else
                    {
                        Writer.WriteLine("    <hi:body lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisSource.Key) + "\">" + thisSource.Value.Replace("&", "&amp;").Replace("\"", "&quot;") + "</hi:body>");
                    }
                }
                Writer.WriteLine("    </hi:content>");
            }


            Writer.WriteLine("  </hi:browse>");
        }
コード例 #18
0
        /// <summary> Save this configuration to a XML config file </summary>
        /// <param name="FilePath"> File/path for the resulting XML config file </param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Save_To_Config_File(string FilePath)
        {
            bool         returnValue = true;
            StreamWriter writer      = null;

            try
            {
                // Start the output file
                writer = new StreamWriter(FilePath, false, Encoding.UTF8);
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                writer.WriteLine("<SobekCM_Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
                writer.WriteLine("\txmlns=\"http://sobekrepository.org/schemas/sobekcm_config\" ");
                writer.WriteLine("\txsi:schemaLocation=\"http://sobekrepository.org/schemas/sobekcm_config ");
                writer.WriteLine("\t\thttp://sobekrepository.org/schemas/sobekcm_config.xsd\">");
                if (String.IsNullOrEmpty(Name))
                {
                    writer.WriteLine("\t<ContactForm>");
                }
                else
                {
                    writer.WriteLine("\t<ContactForm Name=\"" + Convert_String_To_XML_Safe(Name) + "\">");
                }

                if (FormElements.Count > 0)
                {
                    writer.WriteLine("\t\t<Elements>");

                    // Add the elements
                    foreach (ContactForm_Configuration_Element thisElement in FormElements)
                    {
                        string elementName = String.Empty;
                        switch (thisElement.Element_Type)
                        {
                        case ContactForm_Configuration_Element_Type_Enum.CheckBoxSet:
                            elementName = "CheckBoxSet";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.Email:
                            elementName = "Email";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.ExplanationText:
                            elementName = "ExplanationText";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.HiddenValue:
                            elementName = "HiddenValue";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.RadioSet:
                            elementName = "RadioSet";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.SelectBox:
                            elementName = "SelectBox";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.Subject:
                            elementName = "Subject";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.TextArea:
                            elementName = "TextArea";
                            break;

                        case ContactForm_Configuration_Element_Type_Enum.TextBox:
                            elementName = "TextBox";
                            break;
                        }
                        writer.Write("\t\t\t<" + elementName);
                        if (!String.IsNullOrEmpty(thisElement.Name))
                        {
                            writer.Write(" Name=\"" + thisElement.Name + "\"");
                        }

                        if (!String.IsNullOrEmpty(thisElement.QueryText.DefaultValue))
                        {
                            if (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText)
                            {
                                writer.Write(" Query=\"" + Convert_String_To_XML_Safe(thisElement.QueryText.DefaultValue) + "\"");
                            }
                            else
                            {
                                writer.Write(" Text=\"" + Convert_String_To_XML_Safe(thisElement.QueryText.DefaultValue) + "\"");
                            }
                        }
                        if (!String.IsNullOrEmpty(thisElement.CssClass))
                        {
                            writer.Write(" CssClass=\"" + thisElement.CssClass + "\"");
                        }
                        if (thisElement.UserAttribute != User_Object_Attribute_Mapping_Enum.NONE)
                        {
                            writer.Write(" UserAttribute=\"" + User_Object_Attribute_Mapping_Enum_Converter.ToString(thisElement.UserAttribute) + "\"");
                            if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue))
                            {
                                writer.Write(" AlwaysShow=\"" + thisElement.AlwaysShow.ToString().ToLower() + "\"");
                            }
                        }
                        if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue))
                        {
                            if (thisElement.Required)
                            {
                                writer.Write(" Required=\"true\"");
                            }
                        }

                        if (((thisElement.Options == null) || (thisElement.Options.Count == 0)) && (thisElement.QueryText.Count <= 1))
                        {
                            writer.WriteLine(" />");
                        }
                        else
                        {
                            writer.WriteLine(">");

                            // Add the query in different languages
                            List <Web_Language_Translation_Value> translations = thisElement.QueryText.Values;
                            if (translations.Count > 0)
                            {
                                writer.WriteLine("\t\t\t\t<Translations>");
                                foreach (Web_Language_Translation_Value thisTranslation in translations)
                                {
                                    writer.WriteLine("\t\t\t\t\t<Language Code=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisTranslation.Language) + "\">" + Convert_String_To_XML_Safe(thisTranslation.Value) + "</Language>");
                                }
                                writer.WriteLine("\t\t\t\t</Translations>");
                            }

                            // Add the possible options
                            if ((thisElement.Options != null) && (thisElement.Options.Count > 0))
                            {
                                writer.WriteLine("\t\t\t\t<Options>");
                                foreach (string thisOption in thisElement.Options)
                                {
                                    writer.WriteLine("\t\t\t\t\t<Option>" + Convert_String_To_XML_Safe(thisOption) + "</Option>");
                                }
                                writer.WriteLine("\t\t\t\t</Options>");
                            }


                            writer.WriteLine("\t\t\t</" + elementName + ">");
                        }
                    }

                    writer.WriteLine("\t\t</Elements>");
                }
                writer.WriteLine("\t</ContactForm>");
                writer.WriteLine("</SobekCM_Config>");
                writer.Flush();
                writer.Close();
            }
            catch
            {
                returnValue = false;
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }

            return(returnValue);
        }