Ejemplo n.º 1
0
        public async Task SaveNewConfiguration(IMappedConfiguration changedConfiguration)
        {
            using var session = this._sessionFactory.Create();
            var existingConfiguration = session.Get <ConfigurationItem>()
                                        .FirstOrDefault(x => x.ServerId == changedConfiguration.ServerId && x.Name == changedConfiguration.Name);
            var baseFormatConfigurationItem = this._configurationMapperService.MapIntoBaseFormat(changedConfiguration);

            if (existingConfiguration == null)
            {
                await session.AddAsync(baseFormatConfigurationItem);
            }
            else
            {
                existingConfiguration.SetValue(baseFormatConfigurationItem.Value);
                await session.AddOrUpdateAsync(existingConfiguration);
            }
        }
 public ConfigurationItem MapIntoBaseFormat(IMappedConfiguration mappedConfiguration)
 {
     return new ConfigurationItem(((dynamic) mappedConfiguration).Value, mappedConfiguration.ServerId, mappedConfiguration.Name);
 }
Ejemplo n.º 3
0
        private IConfigurationChangesHandler <IMappedConfiguration> GetConfigurationChangesHandler(IMappedConfiguration newMappedConfiguration)
        {
            var configurationChangesHandlers = this._componentContext.ComponentRegistry.Registrations
                                               .Where(x => typeof(IConfigurationChangesHandler).IsAssignableFrom(x.Activator.LimitType));
            var handlerForThisType = configurationChangesHandlers.FirstOrDefault(x => x.Activator.LimitType.Name.StartsWith(newMappedConfiguration.Name));

            if (handlerForThisType == null)
            {
                return(null);
            }
            return(this._componentContext.Resolve(handlerForThisType.Activator.LimitType) as IConfigurationChangesHandler <IMappedConfiguration>);
        }