Beispiel #1
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            this.DataBind();

            // load Board Setting collection information...
            var settingCollection = new BoardSettingCollection(this.Get <BoardSettings>());

            // handle checked fields...
            settingCollection.SettingsBool.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                if (control is CheckBox box && settingCollection.SettingsBool[name].CanRead)
                {
                    // get the value from the property...
                    box.Checked = (bool)Convert.ChangeType(
                        settingCollection.SettingsBool[name].GetValue(this.Get <BoardSettings>(), null),
                        typeof(bool));
                }
            });

            // handle string fields...
            settingCollection.SettingsString.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsString[name].CanRead:
                    // get the value from the property...
                    box.Text = (string)Convert.ChangeType(
                        settingCollection.SettingsString[name].GetValue(this.Get <BoardSettings>(), null),
                        typeof(string));
                    break;

                case DropDownList list when settingCollection.SettingsString[name].CanRead:
                    {
                        var listItem = list.Items.FindByValue(
                            settingCollection.SettingsString[name].GetValue(
                                this.Get <BoardSettings>(),
                                null).ToString());

                        if (listItem != null)
                        {
                            listItem.Selected = true;
                        }

                        break;
                    }
                }
            });

            // handle int fields...
            settingCollection.SettingsInt.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsInt[name].CanRead:
                    {
                        if (!name.Equals("ServerTimeCorrection"))
                        {
                            box.TextMode = TextBoxMode.Number;
                        }

                        // get the value from the property...
                        box.Text = settingCollection.SettingsInt[name]
                                   .GetValue(this.Get <BoardSettings>(), null).ToString();
                        break;
                    }

                case DropDownList list when settingCollection.SettingsInt[name].CanRead:
                    {
                        var listItem = list.Items.FindByValue(
                            settingCollection.SettingsInt[name].GetValue(this.Get <BoardSettings>(), null)
                            .ToString());

                        if (listItem != null)
                        {
                            listItem.Selected = true;
                        }

                        break;
                    }
                }
            });

            // handle double fields...
            settingCollection.SettingsDouble.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsDouble[name].CanRead:
                    box.CssClass = "form-control";

                    // get the value from the property...
                    box.Text = settingCollection.SettingsDouble[name]
                               .GetValue(this.Get <BoardSettings>(), null).ToString();
                    break;

                case DropDownList list when settingCollection.SettingsDouble[name].CanRead:
                    {
                        var listItem = list.Items.FindByValue(
                            settingCollection.SettingsDouble[name].GetValue(
                                this.Get <BoardSettings>(),
                                null).ToString());

                        if (listItem != null)
                        {
                            listItem.Selected = true;
                        }

                        break;
                    }
                }
            });

            // special field handling...
            this.AvatarSize.Text = this.Get <BoardSettings>().AvatarSize != 0
                                       ? this.Get <BoardSettings>().AvatarSize.ToString()
                                       : string.Empty;
            this.MaxFileSize.Text = this.Get <BoardSettings>().MaxFileSize != 0
                                        ? this.Get <BoardSettings>().MaxFileSize.ToString()
                                        : string.Empty;

            this.AlbumImagesSizeMax.Text = this.Get <BoardSettings>().AlbumImagesSizeMax != 0
                                               ? this.Get <BoardSettings>().AlbumImagesSizeMax.ToString()
                                               : string.Empty;

            this.SQLVersion.Text = this.HtmlEncode(this.Get <IDbFunction>().GetSQLVersion());

            this.AppCores.Text  = SystemInfo.Processors;
            this.AppMemory.Text =
                $"{SystemInfo.AllocatedMemory.ToType<long>() / 1000000} MB of {SystemInfo.MappedMemory.ToType<long>() / 1000000} MB";
            this.AppOSName.Text  = SystemInfo.VersionString;
            this.AppRuntime.Text = $"{SystemInfo.RuntimeName} {SystemInfo.RuntimeString}";
        }
Beispiel #2
0
        /// <summary>
        /// Saves the Host Settings
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            // write all the settings back to the settings class

            // load Board Setting collection information...
            var settingCollection = new BoardSettingCollection(this.Get <BoardSettings>());

            // handle checked fields...
            settingCollection.SettingsBool.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                if (control is CheckBox box && settingCollection.SettingsBool[name].CanWrite)
                {
                    settingCollection.SettingsBool[name].SetValue(
                        this.Get <BoardSettings>(),
                        box.Checked,
                        null);
                }
            });

            // handle string fields...
            settingCollection.SettingsString.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsString[name].CanWrite:
                    settingCollection.SettingsString[name].SetValue(
                        this.Get <BoardSettings>(),
                        box.Text.Trim(),
                        null);
                    break;

                case DropDownList list when settingCollection.SettingsString[name].CanWrite:
                    settingCollection.SettingsString[name].SetValue(
                        this.Get <BoardSettings>(),
                        Convert.ToString(list.SelectedItem.Value),
                        null);
                    break;
                }
            });

            // handle int fields...
            settingCollection.SettingsInt.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsInt[name].CanWrite:
                    {
                        var value = box.Text.Trim();
                        int i;

                        if (value.IsNotSet())
                        {
                            i = 0;
                        }
                        else
                        {
                            int.TryParse(value, out i);
                        }

                        settingCollection.SettingsInt[name].SetValue(this.Get <BoardSettings>(), i, null);
                        break;
                    }

                case DropDownList list when settingCollection.SettingsInt[name].CanWrite:
                    settingCollection.SettingsInt[name].SetValue(
                        this.Get <BoardSettings>(),
                        list.SelectedItem.Value.ToType <int>(),
                        null);
                    break;
                }
            });

            // handle double fields...
            settingCollection.SettingsDouble.Keys.ForEach(
                name =>
            {
                var control = this.HostSettingsTabs.FindControlRecursive(name);

                switch (control)
                {
                case TextBox box when settingCollection.SettingsDouble[name].CanWrite:
                    {
                        var value = box.Text.Trim();
                        double i;

                        if (value.IsNotSet())
                        {
                            i = 0;
                        }
                        else
                        {
                            double.TryParse(value, out i);
                        }

                        settingCollection.SettingsDouble[name].SetValue(
                            this.Get <BoardSettings>(),
                            i,
                            null);
                        break;
                    }

                case DropDownList list when settingCollection.SettingsDouble[name].CanWrite:
                    settingCollection.SettingsDouble[name].SetValue(
                        this.Get <BoardSettings>(),
                        Convert.ToDouble(list.SelectedItem.Value),
                        null);
                    break;
                }
            });

            // save the settings to the database
            ((LoadBoardSettings)this.Get <BoardSettings>()).SaveRegistry();

            // reload all settings from the DB
            this.PageContext.BoardSettings = null;

            BuildLink.Redirect(ForumPages.Admin_Admin);
        }