Beispiel #1
0
        /// <summary>
        /// Removes a specified config.
        /// </summary>
        /// <param name="configChange">The config change object.</param>
        /// <returns>
        /// How many changes have been processed by this method.
        /// </returns>
        /// <exception cref="System.Exception">Trying to delete a config that does not exist in RiME Config.</exception>
        public static int RemoveConfig(ConfigChangeModel configChange)
        {
            RiMEConfigModel rimeConfig = RiMEConfigDAL.GetConfig((int)configChange.ConfigObjectType, configChange.Key.ToString());

            if (rimeConfig != null)
            {
                return(RiMEConfigDAL.RemoveConfig(configChange));
            }
            else
            {
                throw new Exception("Trying to delete a config that does not exist in RiME Config. \r\nThis Config Info:\r\n{0}".FormatWith(configChange.ToSerializedXmlString()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates a specified config.
        /// </summary>
        /// <param name="configChange">The config change object.</param>
        /// <returns>How many changes have been processed by this method.</returns>
        /// <exception cref="System.Exception">Trying to update a config that does not exist in RiME Config.</exception>
        public static int UpdateConfig(ConfigChangeModel configChange)
        {
            RiMEConfigModel rimeConfig = RiMEConfigDAL.GetConfig((int)configChange.ConfigObjectType, configChange.Key.ToString());

            if (rimeConfig != null)
            {
                string oldValue = rimeConfig.Value;
                return(RiMEConfigDAL.UpdateConfig(configChange, RiMEConfigBLL.GetNewValueToStoreInDB(oldValue, configChange.NewConfig)));
            }
            else
            {
                throw new Exception("Trying to update a config that does not exist in RiME Config. \r\nThis Config Info:\r\n{0}".FormatWith(configChange.ToSerializedXmlString()));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets a list of config objects that are all in the specified type.
        /// </summary>
        /// <param name="configObjectType">A integer value represents the type of the config object.</param>
        /// <returns>A list of config objects.</returns>
        public static List <RiMEConfigModel> GetConfig(int configObjectType)
        {
            List <RiMEConfigModel> result = new List <RiMEConfigModel>();
            string    sql = "SELECT iConfigObjectType, vcKey, nvcValue, dtUpdatedTime FROM RiMEConfig.dbo.Config WHERE iConfigObjectType = @configObjectType";
            DataTable dt  = SqlServerHelper.Query(sql, new SqlParameter("configObjectType", configObjectType));

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                RiMEConfigModel model = new RiMEConfigModel()
                {
                    ConfigObjectType = dt.Rows[i][0].ToInt(), Key = dt.Rows[i][1].ToString(), Value = dt.Rows[i][2].ToString(), UpdatedTime = dt.Rows[i][3].ToDateTime()
                };
                result.Add(model);
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Gets a config by its key and configObjectType.
        /// </summary>
        /// <param name="configObjectType">The integer value that represents the type of the config object.</param>
        /// <param name="key">The key.</param>
        /// <returns>The config object</returns>
        public static RiMEConfigModel GetConfig(int configObjectType, string key)
        {
            string    sql = "SELECT iConfigObjectType, vcKey, nvcValue, dtUpdatedTime FROM RiMEConfig.dbo.Config WHERE iConfigObjectType = @configObjectType AND vcKey = @key";
            DataTable dt  = SqlServerHelper.Query(sql, new SqlParameter("configObjectType", configObjectType), new SqlParameter("key", key));

            if (dt.Rows.Count > 0)
            {
                RiMEConfigModel model = new RiMEConfigModel()
                {
                    ConfigObjectType = dt.Rows[0][0].ToInt(), Key = dt.Rows[0][1].ToString(), Value = dt.Rows[0][2].ToString(), UpdatedTime = dt.Rows[0][3].ToDateTime()
                };
                return(model);
            }
            else
            {
                return(null);
            }
        }