Пример #1
0
        private void Handle(ApplicationEvent @event)
        {
            if (ConfigItems.ContainsKey(@event.GetValue("Key")))
            {
                if (ConfigItems[@event.GetValue("Key")] != @event.GetValue("Value"))
                {
                    throw new Exception($"Misconfiguration in [{GetType().Name}]: Config with key [{@event.GetValue("Key")}] already defined with different value to [{@event.GetValue("Value")}].");
                }
                return;
            }

            ConfigItems.Add(@event.GetValue("Key"), @event.GetValue("Value"));
            ConfigItems = ConfigItems.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
        }
Пример #2
0
        private void SetConfigItem(UserConfigItem configItem)
        {
            // determine if the config item already exists
            UserConfigItem cfgItem = ConfigItems.FirstOrDefault(s => s.ConfigKey == configItem.ConfigKey);

            // Create or update
            if (cfgItem == null)
            {
                cfgItem = new UserConfigItem()
                {
                    ConfigKey   = configItem.ConfigKey,
                    ConfigValue = configItem.ConfigValue
                };

                // Add element to the list
                ConfigItems.Add(cfgItem);
            }
            else
            {
                // Update exiting element in list
                cfgItem.ConfigValue = configItem.ConfigValue;
            }
        }