コード例 #1
0
ファイル: AddSetting.aspx.cs プロジェクト: sffogg/Xenosynth
        protected void ButtonAddSetting_OnClick(object sender, EventArgs e)
        {
            if (Page.IsValid) {
                ConfigurationSetting setting = new ConfigurationSetting(
                    TextBoxKey.Text,
                    TextBoxCategory.Text,
                    TextBoxName.Text,
                    TextBoxDescription.Text,
                    Type.GetType(TextBoxType.Text, true, true),
                    TextBoxValue.Text
                    );

                XenosynthContext.Current.Configuration.Add(setting);

                Response.Redirect("Settings.aspx?Category=" + setting.Category);
            }
        }
コード例 #2
0
 public void GetValue(ConfigurationSetting setting)
 {
     //if (setting.ValueType == typeof(System.Boolean)) {
     //    CheckBox CheckBoxValue = (CheckBox)FindControl(setting.Key);
     //    setting.Value = CheckBoxValue.Checked;
     //} else if (setting.ValueType.IsEnum) {
     //    DropDownList DropDownListValue = (DropDownList)FindControl(setting.Key);
     //    setting.Value = Enum.Parse(setting.ValueType, DropDownListValue.SelectedValue);
     //} else {
     if (setting.ValueType.IsEnum) {
         TextBox TextBoxValue = (TextBox)FindControl(setting.Key);
         setting.Value = Enum.Parse(setting.ValueType, TextBoxValue.Text);
     } else {
         TextBox TextBoxValue = (TextBox)FindControl(setting.Key);
         setting.Value = Convert.ChangeType(TextBoxValue.Text, setting.ValueType);
     }
     //}
 }
コード例 #3
0
 private void SetValue(ConfigurationSetting setting)
 {
     if (setting.Value != null) {
         TextBox textBox = (TextBox)FindControl(setting.Key);
         textBox.Text = setting.Value.ToString();
     }
 }
コード例 #4
0
ファイル: Configuration.cs プロジェクト: sffogg/Xenosynth
 private void RemoveFromCache(ConfigurationSetting setting)
 {
     settingsCache.Remove(setting.Key);
     setting.Change -= new EventHandler(OnSettingChange);
 }
コード例 #5
0
ファイル: Configuration.cs プロジェクト: sffogg/Xenosynth
 private void AddToCache(ConfigurationSetting setting)
 {
     settingsCache.Add(setting.Key, setting);
     setting.Change += new EventHandler(OnSettingChange);
 }
コード例 #6
0
ファイル: Configuration.cs プロジェクト: sffogg/Xenosynth
        /// <summary>
        /// Adds a <see cref="ConfigurationSetting"/> to the system configuration. 
        /// </summary>
        /// <param name="setting">
        /// A <see cref="ConfigurationSetting"/>
        /// </param>
        public void Add(ConfigurationSetting setting)
        {
            if (this.Contains(setting.Key)) {
                throw new ApplicationException("A setting with key '" + setting.Key + "' already exists.");
            }

            string sql = "INSERT " + TableName + " ([Key], Category, Name, Description, Type, Value) Values (@Key, @Category, @Name, @Description, @Type, @Value)";

            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add("@Key", setting.Key);
            cmd.Parameters.Add("@Name", setting.Value);
            cmd.Parameters.Add("@Category", setting.Category);
            cmd.Parameters.Add("@Description", setting.Description);
            cmd.Parameters.Add("@Type", setting.ValueType.AssemblyQualifiedName);
            cmd.Parameters.Add("@Value", ConvertToString(setting.Value));

            try {
                conn.Open();
                cmd.ExecuteNonQuery();
            } finally {
                if (conn.State == ConnectionState.Open) {
                    conn.Close();
                }
            }

            AddToCache(setting);
        }