Ejemplo n.º 1
0
        /// <summary>
        /// Reads a gadget instance setting from the database
        /// </summary>
        /// <param name="key">The key of the (key,value) pair that should be read. if this key doesn't exist
        /// in the gadget instance settings, operation will fail.</param>
        /// <param name="publicSetting">Set this parameter to True if the (key,value) pair is a public setting,
        /// otherwise set it to False</param>
        /// <param name="settingValue">The value of the (key,value) pair that is read from gadget instance settings</param>
        /// <returns>On success returns True, otherwise returns False</returns>
        public string GetSetting(string key, bool publicSetting)
        {
            GadgetInstanceSetting setting = _context.GadgetInstanceSettings.Where(r => r.Key == key && r.Public == publicSetting).SingleOrDefault();

            if (setting == null)
            {
                throw new InvalidKeyException(key);
            }

            return(setting.Value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets a (key,value) pair in the gadget instance settings.
        /// </summary>
        /// <param name="key">The key of the key-value pair. if this key exists in the gadget instanse settings,
        /// its value will updated, otherwise a new (key,value) pair will be inserted in the gadget instance settings.</param>
        /// <param name="value">new value of the (key,value) pair</param>
        /// <param name="publicSetting">Set this parameter to True if the (key,value) pair is a public setting,
        /// otherwise set it to False</param>
        /// <returns>On success returns True, otherwise returns False</returns>
        public void SetSetting(KeyValuePair <string, string>[] keyValuePairs, bool publicSetting)
        {
            GadgetInstanceSetting gis;

            for (int i = 0; i < keyValuePairs.Length; i++)
            {
                gis = new GadgetInstanceSetting(keyValuePairs[i].Key, keyValuePairs[i].Value);

                _context.GadgetInstanceSettings.Attach(gis);
            }

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates a (key,value) pair in the gadget instance settings
        /// </summary>
        /// <param name="key">The key of the key-value pair. this key should exist in the gadget instance settings,
        /// otherwise update operation will fail</param>
        /// <param name="newValue">new value for the (key,value) pair</param>
        /// <param name="publicSetting">Set this parameter to True if the (key,value) pair is a public setting,
        /// otherwise set it to False</param>
        /// <returns>On success returns True, otherwise returns False</returns>
        public void UpdateSetting(string key, string newValue, bool publicSetting)
        {
            GadgetInstanceSetting setting = _context.GadgetInstanceSettings.Where(r => r.Key == key && r.Public == publicSetting).SingleOrDefault();

            if (setting == null)
            {
                throw new InvalidKeyException(key);
            }

            // set values
            setting.Value = newValue;

            // update changes
            _context.SaveChanges();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets a (key,value) pair in the gadget instance settings.
        /// </summary>
        /// <param name="key">The key of the key-value pair. if this key exists in the gadget instanse settings,
        /// its value will updated, otherwise a new (key,value) pair will be inserted in the gadget instance settings.</param>
        /// <param name="value">new value of the (key,value) pair</param>
        /// <param name="publicSetting">Set this parameter to True if the (key,value) pair is a public setting,
        /// otherwise set it to False</param>
        /// <returns>On success returns True, otherwise returns False</returns>
        public void SetSetting(string key, string value, bool publicSetting)
        {
            GadgetInstanceSetting setting = _context.GadgetInstanceSettings.FirstOrDefault(
                gis => (gis.GadgetInstance.Id == _giid && gis.Key == key && gis.Public == publicSetting));

            if (setting != null)
            {
                setting.Value = value;
            }
            else
            {
                _context.GadgetInstances.Single(gi => gi.Id == _giid).Settings.Add(new GadgetInstanceSetting(key, value));
            }

            _context.SaveChanges();
        }