Beispiel #1
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;
            }
        }
Beispiel #2
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 #3
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()));
            }
        }