Exemplo n.º 1
0
 public ConfigurationFlag(string key, ConfigurationFlagTypes type, string defaultValue, string description, int rangeMin = 0, int rangeMax = 0, IList<IConfigurationFlagSelectValue> selectValues = null)
 {
     this.Key = key;
     this.Type = type;
     this.DefaultValue = defaultValue;
     this.Description = description;
     this.RangeMin = rangeMin;
     this.RangeMax = rangeMax;
     this.SelectValues = selectValues;
 }
Exemplo n.º 2
0
 public dynamic this[IGameInfo gameInfo, string key, ConfigurationFlagTypes type]
 {
     get
     {
         return this.GetValue(gameInfo, key, type);
     }
     set
     {
         this.SetValue(gameInfo, key, value, type);
     }
 }
Exemplo n.º 3
0
 public void SetDefaultValue(string key, object value, ConfigurationFlagTypes type)
 {
     this.SetValue(key, value, type, "default");
 }
Exemplo n.º 4
0
 public dynamic GetValue(IGameInfo gameInfo, string key, ConfigurationFlagTypes type)
 {
     return this.GetValue(key, type, gameInfo.UUID, this.GetDefaultValue(key, type));
 }
Exemplo n.º 5
0
 public dynamic GetDefaultValue(string key, ConfigurationFlagTypes type)
 {
     return this.GetValue(key, type, "default", this.emulatorBridge.ConfigurationFlags[key].DefaultValue);
 }
Exemplo n.º 6
0
 private void SetValue(string key, object value, ConfigurationFlagTypes type, string prefix)
 {
     SQLiteConnection flagDb = this.GetConnection();
     flagDb.Open();
     using (var sqliteCommand = new SQLiteCommand(@"INSERT OR REPLACE INTO flags VALUES(
                                   @flagKey,
                                   @flagValue)", flagDb))
     {
         sqliteCommand.Parameters.AddWithValue("@flagKey", $"{prefix}-{key}");
         sqliteCommand.Parameters.AddWithValue("@flagValue", value.ToString());
         sqliteCommand.ExecuteNonQuery();
     }
     flagDb.Close();
 }
Exemplo n.º 7
0
        private dynamic GetValue(string key, ConfigurationFlagTypes type, string prefix, object fallback)
        {
            SQLiteConnection dbConnection = this.GetConnection();
            dbConnection.Open();
            string value = string.Empty;
            using (var sqlCommand = new SQLiteCommand(@"SELECT `flagValue` FROM `flags` WHERE `flagKey` == @searchQuery"
               , dbConnection))
            {
                sqlCommand.Parameters.AddWithValue("@searchQuery", $"{prefix}-{key}");

                    try
                    {
                        value = (string)sqlCommand.ExecuteScalar();
                    }
                    catch (AccessViolationException)
                    {
                        System.Threading.Thread.Sleep(500); //le concurrency hack :(
                        value = (string)sqlCommand.ExecuteScalar();
                    }
            }
            dbConnection.Close();
            value = value ?? fallback.ToString();
            switch (type)
            {
                case ConfigurationFlagTypes.SELECT_FLAG:
                    return int.Parse(value);
                case ConfigurationFlagTypes.INTEGER_FLAG:
                    return int.Parse(value);
                case ConfigurationFlagTypes.BOOLEAN_FLAG:
                    return bool.Parse(value);
                default:
                    return value;
            }
        }
Exemplo n.º 8
0
 public void SetValue(IGameInfo gameInfo, string key, object value, ConfigurationFlagTypes type)
 {
     this.SetValue(key, value, type, gameInfo.UUID);
 }