예제 #1
0
        //*********************************************************************
        //
        // GetModuleSettings Method  <a name="GetModuleSettings"></a>
        //
        // The GetModuleSettings Method returns a hashtable of custom,
        // module-specific settings from the configuration file.  This method is
        // used by some user control modules (Xml, Image, etc) to access misc
        // settings.
        //
        // Other relevant sources:
        //    + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
        //	  + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
        //
        //*********************************************************************
        public static Hashtable GetModuleSettings(int moduleId)
        {
            // Create a new Hashtable
            Hashtable _settingsHT = new Hashtable();

            // Obtain SiteSettings from Current Context
            SiteConfiguration siteSettings = (SiteConfiguration)HttpContext.Current.Items["SiteSettings"];

            // Find the appropriate Module in the Module table
            SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(moduleId);

            // Find the first (only) settings element
            if (moduleRow.GetSettingsRows().Length > 0)
            {
                SiteConfiguration.SettingsRow settingsRow = moduleRow.GetSettingsRows()[0];

                if (settingsRow != null)
                {
                    // Find the child setting elements and add to the hashtable
                    foreach (SiteConfiguration.SettingRow sRow in settingsRow.GetSettingRows())
                    {
                        _settingsHT[sRow.Name] = sRow.Setting_Text;
                    }
                }
            }

            return(_settingsHT);
        }
예제 #2
0
        //*********************************************************************
        //
        // UpdateModuleSetting Method  <a name="UpdateModuleSetting"></a>
        //
        // The UpdateModuleSetting Method updates a single module setting
        // in the configuration file.  If the value passed in is String.Empty,
        // the Setting element is deleted if it exists.  If not, either a
        // matching Setting element is updated, or a new Setting element is
        // created.
        //
        // Other relevant sources:
        //    + <a href="#SaveSiteSettings" style="color:green">SaveSiteSettings() method</a>
        //	  + <a href="PortalCfg.xml" style="color:green">PortalCfg.xml</a>
        //
        //*********************************************************************
        public void UpdateModuleSetting(int moduleId, String key, String val)
        {
            // Obtain SiteSettings from Current Context
            SiteConfiguration siteSettings = (SiteConfiguration)HttpContext.Current.Items["SiteSettings"];

            // Find the appropriate Module in the Module table
            SiteConfiguration.ModuleRow moduleRow = siteSettings.Module.FindByModuleId(moduleId);

            // Find the first (only) settings element
            SiteConfiguration.SettingsRow settingsRow;

            if (moduleRow.GetSettingsRows().Length > 0)
            {
                settingsRow = moduleRow.GetSettingsRows()[0];
            }
            else
            {
                // Add new settings element
                settingsRow = siteSettings.Settings.NewSettingsRow();

                // Set the parent relationship
                settingsRow.ModuleRow = moduleRow;

                siteSettings.Settings.AddSettingsRow(settingsRow);
            }

            // Find the child setting elements
            SiteConfiguration.SettingRow settingRow;

            SiteConfiguration.SettingRow[] settingRows = settingsRow.GetSettingRows();

            if (settingRows.Length == 0)
            {
                // If there are no Setting elements at all, add one with the new name and value,
                // but only if the value is not empty
                if (val != String.Empty)
                {
                    settingRow = siteSettings.Setting.NewSettingRow();

                    // Set the parent relationship and data
                    settingRow.SettingsRow  = settingsRow;
                    settingRow.Name         = key;
                    settingRow.Setting_Text = val;

                    siteSettings.Setting.AddSettingRow(settingRow);
                }
            }
            else
            {
                // Update existing setting element if it matches
                bool  found = false;
                Int32 i;

                // Find which row matches the input parameter "key" and update the
                // value.  If the value is String.Empty, however, delete the row.
                for (i = 0; i < settingRows.Length; i++)
                {
                    if (settingRows[i].Name == key)
                    {
                        if (val == String.Empty)
                        {
                            // Delete the row
                            siteSettings.Setting.RemoveSettingRow(settingRows[i]);
                        }
                        else
                        {
                            // Update the value
                            settingRows[i].Setting_Text = val;
                        }

                        found = true;
                    }
                }

                if (found == false)
                {
                    // Setting elements exist, however, there is no matching Setting element.
                    // Add one with new name and value, but only if the value is not empty
                    if (val != String.Empty)
                    {
                        settingRow = siteSettings.Setting.NewSettingRow();

                        // Set the parent relationship and data
                        settingRow.SettingsRow  = settingsRow;
                        settingRow.Name         = key;
                        settingRow.Setting_Text = val;

                        siteSettings.Setting.AddSettingRow(settingRow);
                    }
                }
            }

            // Save the changes
            SaveSiteSettings();
        }