Esempio 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);
        }
Esempio 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;
            }
        }
Esempio n. 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()));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Props the change group.
        /// </summary>
        /// <param name="xmlFilePath">The Change Group XML file path.</param>
        /// <param name="xmlns">The xml namespace.</param>
        /// <returns>How many changes have been processed by this method.</returns>
        public static int PropChangeGroup(string xmlFilePath, string xmlns = "urn:schemas.microsoft.com/Commerce/Types/RiAS/2011/04")
        {
            XDocument  xdoc          = XDocument.Load(xmlFilePath);
            XNamespace ns            = xmlns;
            var        configChanges = from change in xdoc.Descendants(ns + "ConfigChange")
                                       select new
            {
                ConfigObjectType = change.Element(ns + "ConfigObjectType").Value,
                ConfigVerb       = change.Element(ns + "ConfigVerb").Value,
                Key       = change.Element(ns + "Key").Value,
                NewConfig = change.Element(ns + "NewConfig") != null?change.Element(ns + "NewConfig").InnerXmlString() : ""
            };
            int count = 0;

            foreach (var configChange in configChanges)
            {
                Log.Info("Propping this config object:\r\n{0}\r\n", configChange.ToXml());
                count += RiMEConfigBLL.PropChange(configChange.CastToConfigChangeModel());
                Log.Info("Propped count: {0}".FormatWith(count));
            }

            return(count);
        }