Ejemplo n.º 1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings()
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    var persister = new ModuleSettingPersister<MyModuleSettingsInfo>();
                    var typedSettings = persister.Load(this.Settings);

                    this.ddlSettingStatus.Items.AddRange(Enum.GetValues(typeof(Status))
                                                             .OfType<Status>()
                                                             .Select(arg => new ListItem(this.LocalizeString("Status_" + arg.ToString().ToLowerInvariant()), arg.ToString()))
                                                             .ToArray());

                    this.chkSettingInitialize.Checked = typedSettings.Initialize.GetValueOrDefault(false);
                    this.ddlSettingStatus.SelectedValue = typedSettings.Status.ToString();
                    this.txtCssClass.Text = typedSettings.CssClass;
                    this.txtSettingMaximumRetries.Text = typedSettings.MaximumRetries.ToString(CultureInfo.CurrentUICulture);
                    this.txtSettingUserName.Text = typedSettings.UserName;
                }
            }
            catch (Exception exception)
            {
                Exceptions.ProcessModuleLoadException(this, exception);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var persister = new ModuleSettingPersister<MyModuleSettingsInfo>();
                var typedModuleSettings = persister.Load(this.Settings);

                // ReSharper disable once AssignmentInConditionalExpression
                if (this.pnlSettings.Visible = typedModuleSettings.IsInitialized)
                {
                    this.lblModuleInitializedMessage.Text = this.LocalizeString("ModuleInitializedMessage");

                    this.lblSettingCssClassValue.Text = typedModuleSettings.CssClass;
                    if (typedModuleSettings.Initialize.HasValue)
                    {
                        this.chkSettingInitialize.Checked = typedModuleSettings.Initialize.Value;
                    }
                    else
                    {
                        this.chkSettingInitialize.Enabled = false;
                    }

                    this.lblSettingMaximumRetriesValue.Text = typedModuleSettings.MaximumRetries.ToString(CultureInfo.CurrentUICulture);
                    this.lblSettingStatusValue.Text = typedModuleSettings.Status.ToString();
                    this.lblSettingUserNameValue.Text = typedModuleSettings.UserName;
                }
                else
                {
                    this.lblModuleInitializedMessage.Text = this.LocalizeString("ModuleNotInitializedMessage");
                }
            }
            catch (Exception exception)
            {
                Exceptions.ProcessModuleLoadException(this, exception);
            }
        }
Ejemplo n.º 3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateSettings saves the modified settings to the Database
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void UpdateSettings()
        {
            try
            {
                var persister = new ModuleSettingPersister<MyModuleSettingsInfo>();

                // Option 1: Recommended practice. Will load the defaults as well!
                var typedModuleSettings = persister.Load(this.Settings);

                // Option 2: Not recommended since it misses the default values!
                // var typedModuleSettings = new MyModuleSettingsInfo();

                // Retrieve the settings from the form
                typedModuleSettings.Initialize = this.chkSettingInitialize.Checked;
                typedModuleSettings.CssClass = this.txtCssClass.Text;

                var maximumRetries = 0;
                typedModuleSettings.MaximumRetries = int.TryParse(this.txtSettingMaximumRetries.Text, NumberStyles.Integer, CultureInfo.CurrentUICulture, out maximumRetries) ? maximumRetries : 0;

                var status = Status.Unknown;
                typedModuleSettings.Status = Enum.TryParse(this.ddlSettingStatus.SelectedValue, true, out status) ? status : Status.Unknown;
                typedModuleSettings.UserName = this.txtSettingUserName.Text;

                persister.Save(typedModuleSettings, this.ModuleContext.ModuleId, this.ModuleContext.TabModuleId);
                // Obviously the statement below works as well...
                // persister.Save(typedModuleSettings, this.ModuleId, this.TabModuleId);
            }
            catch (Exception exception)
            {
                Exceptions.ProcessModuleLoadException(this, exception);
            }
        }