Exemplo n.º 1
0
 /// <summary>
 /// Modifies a float value in the cache and marks it for being synced on the next cycle.
 /// </summary>
 /// <param name="key">The string key for the property</param>
 /// <param name="newVal">The value to replace the old value with</param>
 public static bool ModifyDouble(string key, double newVal)
 {
     if (!DefaultPropertyManager.DefaultDoubleProperties.ContainsKey(key))
         return false;
     if (CachedDoubleSettings.ContainsKey(key))
         CachedDoubleSettings[key].Modify(newVal);
     else
         CachedDoubleSettings[key] = new ConfigurationEntry<double>(true, newVal, DefaultPropertyManager.DefaultDoubleProperties[key].Description);
     return true;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Modifies a string value in the cache and marks it for being synced on the next cycle
 /// </summary>
 /// <param name="key">The string key for the property</param>
 /// <param name="newVal">The value to replace the old value with</param>
 public static void ModifyString(string key, string newVal)
 {
     if (CachedStringSettings.ContainsKey(key))
     {
         CachedStringSettings[key].Modify(newVal);
     }
     else
     {
         CachedStringSettings[key] = new ConfigurationEntry <string>(true, newVal);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Modifies a float value in the cache and marks it for being synced on the next cycle.
 /// </summary>
 /// <param name="key">The string key for the property</param>
 /// <param name="newVal">The value to replace the old value with</param>
 public static void ModifyDouble(string key, double newVal)
 {
     if (CachedDoubleSettings.ContainsKey(key))
     {
         CachedDoubleSettings[key].Modify(newVal);
     }
     else
     {
         CachedDoubleSettings[key] = new ConfigurationEntry <double>(true, newVal);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Modifies a boolean value in the cache and marks it for being synced on the next cycle.
 /// </summary>
 /// <param name="key">The string key for the property</param>
 /// <param name="newVal">The value to replace the old value with</param>
 public static void ModifyBool(string key, bool newVal)
 {
     if (CachedBooleanSettings.ContainsKey(key))
     {
         CachedBooleanSettings[key].Modify(newVal);
     }
     else
     {
         CachedBooleanSettings[key] = new ConfigurationEntry <bool>(true, newVal);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Modifies a string value in the cache and marks it for being synced on the next cycle
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="newVal">The value to replace the old value with</param>
        /// <returns>true if the property was modified, false if no property exists with the given key</returns>
        public static bool ModifyString(string key, string newVal)
        {
            if (!DefaultPropertyManager.DefaultStringProperties.ContainsKey(key))
                return false;

            if (CachedStringSettings.ContainsKey(key))
                CachedStringSettings[key].Modify(newVal);
            else
                CachedStringSettings[key] = new ConfigurationEntry<string>(true, newVal, DefaultPropertyManager.DefaultStringProperties[key].Description);
            return true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Modifies a boolean value in the cache and marks it for being synced on the next cycle.
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="newVal">The value to replace the old value with</param>
        /// <returns>true if the property was modified, false if no property exists with the given key</returns>
        public static bool ModifyBool(string key, bool newVal)
        {
            if (!DefaultPropertyManager.DefaultBooleanProperties.ContainsKey(key))
                return false;

            if (CachedBooleanSettings.ContainsKey(key))
                CachedBooleanSettings[key].Modify(newVal);
            else
                CachedBooleanSettings[key] = new ConfigurationEntry<bool>(true, newVal, DefaultPropertyManager.DefaultBooleanProperties[key].Description);

            return true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Retreives a string property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallback value will be cached.</param>
        /// <returns>A string value representing the property</returns>
        public static Property<string> GetString(string key, string fallback = "", bool cacheFallback = true)
        {
            if (CachedStringSettings.ContainsKey(key))
                return new Property<string>(CachedStringSettings[key].Item, CachedStringSettings[key].Description);

            var dbValue = DatabaseManager.ShardConfig.GetString(key);

            bool useFallback = dbValue?.Value == null;

            var value = dbValue?.Value ?? fallback;

            if (!useFallback || cacheFallback)
                CachedStringSettings[key] = new ConfigurationEntry<string>(useFallback, value, dbValue?.Description);

            return new Property<string>(value, dbValue?.Description);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Modifies an integer value in the cache and marks it for being synced on the next cycle.
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="newVal">The value to replace the old value with</param>
        /// <returns>true if the property was modified, false if no property exists with the given key</returns>
        public static bool ModifyLong(string key, long newVal)
        {
            if (!DefaultPropertyManager.DefaultLongProperties.ContainsKey(key))
            {
                return(false);
            }

            if (CachedLongSettings.ContainsKey(key))
            {
                CachedLongSettings[key].Modify(newVal);
            }
            else
            {
                CachedLongSettings[key] = new ConfigurationEntry <long>(true, newVal, DefaultPropertyManager.DefaultLongProperties[key].Description);
            }
            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Retrieves a boolean property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallback property should be cached.</param>
        /// <returns>A boolean value representing the property</returns>
        public static Property<bool> GetBool(string key, bool fallback = false, bool cacheFallback = true)
        {
            // first, check the cache. If the key exists in the cache, grab it regardless of its modified value
            // then, check the database. if the key exists in the database, grab it and cache it
            // finally, set it to a default of false.
            if (CachedBooleanSettings.ContainsKey(key))
                return new Property<bool>(CachedBooleanSettings[key].Item, CachedBooleanSettings[key].Description);

            var dbValue = DatabaseManager.ShardConfig.GetBool(key);

            bool useFallback = dbValue?.Value == null;

            var value = dbValue?.Value ?? fallback;

            if (!useFallback || cacheFallback)
                CachedBooleanSettings[key] = new ConfigurationEntry<bool>(useFallback, value, dbValue?.Description);

            return new Property<bool>(value, dbValue?.Description);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Retrieves a float property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallpack property should be cached</param>
        /// <returns>A float value representing the property</returns>
        public static Property <double> GetDouble(string key, double fallback = 0.0f, bool cacheFallback = true)
        {
            if (CachedDoubleSettings.ContainsKey(key))
            {
                return(new Property <double>(CachedDoubleSettings[key].Item, CachedDoubleSettings[key].Description));
            }

            var dbValue = DatabaseManager.ShardConfig.GetDouble(key);

            bool useFallback = dbValue?.Value == null;

            var value = dbValue?.Value ?? fallback;

            if (!useFallback || cacheFallback)
            {
                CachedDoubleSettings[key] = new ConfigurationEntry <double>(useFallback, value, dbValue?.Description);
            }

            return(new Property <double>(value, dbValue?.Description));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Retreives an integer property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallback property should be cached</param>
        /// <returns>An integer value representing the property</returns>
        public static Property <long> GetLong(string key, long fallback = 0, bool cacheFallback = true)
        {
            if (CachedLongSettings.ContainsKey(key))
            {
                return(new Property <long>(CachedLongSettings[key].Item, CachedLongSettings[key].Description));
            }

            var dbValue = DatabaseManager.ShardConfig.GetLong(key);

            bool useFallback = dbValue?.Value == null;

            var intVal = dbValue?.Value ?? fallback;

            if (!useFallback || cacheFallback)
            {
                CachedLongSettings[key] = new ConfigurationEntry <long>(useFallback, intVal, dbValue.Description);
            }

            return(new Property <long>(intVal, dbValue.Description));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Retreives a string property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallback value will be cached.</param>
        /// <returns>A string value representing the property</returns>
        public static Property <string> GetString(string key, string fallback = "", bool cacheFallback = true)
        {
            if (CachedStringSettings.ContainsKey(key))
            {
                return(new Property <string>(CachedStringSettings[key].Item, CachedStringSettings[key].Description));
            }

            var dbValue     = DatabaseManager.Shard.Config.GetString(key);
            var useFallback = false;

            if (dbValue == null || dbValue?.Value == null)
            {
                useFallback = true;
            }

            var stringVal = dbValue?.Value ?? fallback;

            if (!useFallback || (useFallback && cacheFallback))
            {
                CachedStringSettings[key] = new ConfigurationEntry <string>(useFallback, stringVal, dbValue.Description);
            }
            return(new Property <string>(stringVal, dbValue.Description));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves a float property from the cache or database
        /// </summary>
        /// <param name="key">The string key for the property</param>
        /// <param name="fallback">The value to return if the property cannot be found.</param>
        /// <param name="cacheFallback">Whether or not the fallpack property should be cached</param>
        /// <returns>A float value representing the property</returns>
        public static Property <double> GetDouble(string key, double fallback = 0.0f, bool cacheFallback = true)
        {
            if (CachedDoubleSettings.ContainsKey(key))
            {
                return(new Property <double>(CachedDoubleSettings[key].Item, CachedDoubleSettings[key].Description));
            }

            var dbValue     = DatabaseManager.Shard.Config.GetLong(key);
            var useFallback = false;

            if (dbValue == null || dbValue?.Value == null)
            {
                useFallback = true;
            }

            var floatVal = dbValue?.Value ?? fallback;

            if (!useFallback || (useFallback && cacheFallback))
            {
                CachedDoubleSettings[key] = new ConfigurationEntry <double>(useFallback, floatVal, dbValue.Description);
            }
            return(new Property <double>(CachedDoubleSettings[key].Item, CachedDoubleSettings[key].Description));
        }