Exemplo n.º 1
0
        /// <summary>
        /// Props a specified change.
        /// </summary>
        /// <param name="configChange">The config change object.</param>
        /// <returns>How many changes have been processed by this method.</returns>
        /// <exception cref="System.NotImplementedException">Unrecognized Change Config Verb encountered.</exception>
        public static int PropChange(ConfigChangeModel configChange)
        {
            int count = 0;

            if (null != configChange)
            {
                switch (configChange.ConfigVerb)
                {
                case ConfigVerbEnum.Add:
                    count = RiMEConfigBLL.AddConfig(configChange);
                    break;

                case ConfigVerbEnum.Update:
                    count = RiMEConfigBLL.UpdateConfig(configChange);
                    break;

                case ConfigVerbEnum.Remove:
                    count = RiMEConfigBLL.RemoveConfig(configChange);
                    break;

                default:
                    throw new NotImplementedException("Unrecognized Change Config Verb: {0}".FormatWith(configChange.ConfigVerb));
                }
            }
            else
            {
                throw new ArgumentNullException("configChange");
            }

            return(count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds 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">Can't find a proper value format for this new Config Change to store in the RiMEConfig.dbo.Config table. This is because there seems no existed configs that are in the same Config Object Type as this one (has the same value on iConfigObjectType field), so I don't know what should the nvcValue be like for this config.</exception>
        public static int AddConfig(ConfigChangeModel configChange)
        {
            if (configChange.Key <= 0 || RiMEConfigDAL.IsKeyConflicted((int)configChange.ConfigObjectType, configChange.Key.ToString()))
            {
                configChange.Key       = RiMEConfigDAL.GetMaxKeyOfConfig((int)configChange.ConfigObjectType).ToInt() + 1;
                configChange.NewConfig = configChange.NewConfig.Replace("<Id>0</Id>", "<Id>{0}</Id>".FormatWith(configChange.Key));
            }

            if (!RiMEConfigDAL.IsKeyConflicted((int)configChange.ConfigObjectType, configChange.Key.ToString()))
            {
                Log.Info("Adding new config with key {0}".FormatWith(configChange.Key.ToString()));
                List <RiMEConfigModel> configs = RiMEConfigDAL.GetConfig((int)configChange.ConfigObjectType);
                if (configs.Count > 0)
                {
                    return(RiMEConfigDAL.AddConfig(configChange, RiMEConfigBLL.GetNewValueToStoreInDB(configs[0].Value, configChange.NewConfig)));
                }
                else
                {
                    Exception ex = new Exception("Can't find a proper value format for this new Config Change to store in the RiMEConfig.dbo.Config table. This is because there seems no existed configs that are in the same Config Object Type as this one (has the same value on iConfigObjectType field), so I don't know what should the nvcValue be like for this config. \r\nThis Config Info:\r\n{0}".FormatWith(configChange.ToSerializedXmlString()));
                    ExceptionHelper.CentralProcess(ex);
                    throw ex;
                }
            }
            else
            {
                Exception ex = new Exception("Can't find a proper key for this new Config Change. \r\nThis Config Info:\r\n{0}".FormatWith(configChange.ToSerializedXmlString()));
                ExceptionHelper.CentralProcess(ex);
                throw ex;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new config to the [RiMEConfig].[dbo].[Config] table.
        /// </summary>
        /// <param name="newConfig">The new config object.</param>
        /// <param name="newValue">The new value.</param>
        /// <returns>How many rows in [RiMEConfig].[dbo].[Config] table have been affected</returns>
        public static int AddConfig(ConfigChangeModel newConfig, string newValue)
        {
            string sql          = "INSERT INTO RiMEConfig.dbo.Config (iConfigObjectType, vcKey, nvcValue, dtUpdatedTime) VALUES (@configObjectType, @key, @newValue, GETDATE());";
            int    rowsAffected = SqlServerHelper.Execute(sql, new SqlParameter("configObjectType", (int)newConfig.ConfigObjectType),
                                                          new SqlParameter("key", newConfig.Key.ToString()), new SqlParameter("newValue", newValue));

            return(rowsAffected);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates a specified config's value.
        /// </summary>
        /// <param name="newConfig">The config object that needs to be updated.</param>
        /// <param name="newValue">The new value.</param>
        /// <returns>How many rows in the [RiMEConfig].[dbo].[Config] table have been affected.</returns>
        public static int UpdateConfig(ConfigChangeModel newConfig, string newValue)
        {
            string sql          = "UPDATE RiMEConfig.dbo.Config SET nvcValue = @newConfig WHERE iConfigObjectType = @configObjectType AND vcKey = @key";
            int    rowsAffected = SqlServerHelper.Execute(sql,
                                                          new SqlParameter("newConfig", newValue.Replace("'", "''")),
                                                          new SqlParameter("configObjectType", (int)newConfig.ConfigObjectType),
                                                          new SqlParameter("key", newConfig.Key.ToString()));

            return(rowsAffected);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes a config from [RiMEConfig].[dbo].[Config] table.
        /// </summary>
        /// <param name="model">The config object that needs to be removed from [RiMEConfig].[dbo].[Config] table.</param>
        /// <returns>How many rows in [RiMEConfig].[dbo].[Config] table have been affected.</returns>
        public static int RemoveConfig(ConfigChangeModel model)
        {
            string sql          = "DELETE FROM RiMEConfig.dbo.Config WHERE vcKey = @key AND iConfigObjectType = @configObjectType";
            int    rowsAffected = SqlServerHelper.Execute(
                sql,
                new SqlParameter("key", model.Key.ToString()),
                new SqlParameter("configObjectType", (int)model.ConfigObjectType)
                );

            return(rowsAffected);
        }
Exemplo n.º 6
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()));
            }
        }
Exemplo n.º 7
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()));
            }
        }
 public ConfigChangeListenerService(ILoggerFactory loggerFactory, ConfigChangeModel valueModel)
 {
     _ValueModel = valueModel;
     _logger     = loggerFactory.CreateLogger <ConfigChangeListenerService>();
 }