/// <summary> /// Loads the system configuration from the database /// </summary> public void LoadConfiguration() { try { DataTable config = database.GetTable("config"); string[] keys = { "configKey", "configValue" }; if (config.Rows.Count < 1) { configurationStore.Add("diceSides", diceSides.ToString()); configurationStore.Add("fatesHandSetting", fatesHandSetting.ToString()); configurationStore.Add("fatesHandTimer", fatesHandTimer.ToString()); //Get the enumerator for the dictionary. var entries = (IDictionaryEnumerator)configurationStore.GetEnumerator(); //Iterate over the key/value pairs and populate the key/value arrays. while (entries.MoveNext()) { string[] values = { entries.Key.ToString(), entries.Value.ToString() }; database.InsertRecord("config", keys, values); } } else { foreach (DataRow row in config.Rows) { configurationStore.Add(row["configKey"].ToString(), row["configValue"].ToString()); } } } catch (Exception e) { throw new DataException("Cannot Load Configuration!", e); } }
/// <summary> /// Persists the changes to the character model objet to the /// database. /// </summary> /// <returns>True on success or false on failure.</returns> public bool Save() { bool success = false; //Create a dictionary object var characterData = new Dictionary <string, string>(); //Populate the object with key/value pairs. characterData.Add("name", characterName); characterData.Add("isnpc", "" + isNPC); characterData.Add("callsign", characterCallsign); characterData.Add("species", characterSpecies); characterData.Add("gender", characterGender); characterData.Add("height", characterHeight); characterData.Add("weight", characterWeight); characterData.Add("age", "" + characterAge.ToString()); characterData.Add("affiliation", characterAffiliation); characterData.Add("rank", characterRank); characterData.Add("karma", characterKarma.ToString()); characterData.Add("experience", characterExperience.ToString()); characterData.Add("background", characterBackground); characterData.Add("advantages", characterAdvantages); characterData.Add("notes", characterNotes); characterData.Add("inventory", characterInventory); //If the character id is not lread set to a valid value if (characterId == -1) { //New character, so insert the record. characterId = database.InsertRecord("characters", characterData); success |= characterId > -1; } else { //Existing character, update the record. success = database.UpdateRecord("characters", characterData, "cid", "" + characterId); } //Set the volatility flag on this model to false SetVolatility(false); return(success); }