void UpdatePageDefinitionsLocalPropertySettings(PageTypePropertyDefinition propertyDefinition, PageTypeDefinition pageTypeDefinition, PropertySettingsContainer container) { List<PropertySettingsUpdater> settingsUpdaters = GetPropertySettingsUpdaters(pageTypeDefinition, propertyDefinition); settingsUpdaters.ForEach(updater => { var wrapper = container.GetSetting(updater.SettingsType); if (wrapper == null) { wrapper = new PropertySettingsWrapper(); container.Settings[updater.SettingsType.FullName] = wrapper; //TODO: Add spec validating that exception is thrown with the below uncommented (An item with the same key has already been added.) //container.Settings.Add(updater.SettingsType.FullName, wrapper); } bool settingsAlreadyExists = true; if (wrapper.PropertySettings == null) { wrapper.PropertySettings = ((IPropertySettings)Activator.CreateInstance(updater.SettingsType)).GetDefaultValues(); settingsAlreadyExists = false; } if (settingsAlreadyExists && !updater.OverWriteExisting) return; int hashBeforeUpdate = updater.GetSettingsHashCode(wrapper.PropertySettings); updater.UpdateSettings(wrapper.PropertySettings); int hashAfterUpdate = updater.GetSettingsHashCode(wrapper.PropertySettings); if (hashBeforeUpdate != hashAfterUpdate || !settingsAlreadyExists) { propertySettingsRepository.Save(container); } }); }
public void Save(PropertySettingsContainer propertySetting) { var record = new PropertySettingsContainer(propertySetting.Id); Mapper.Map(propertySetting, record); containers[propertySetting.Id] = record; numberOfSavesPerGuidCounter.IncrementNumberOfSaves(propertySetting.Id); }
public bool TryGetContainer(Guid id, out PropertySettingsContainer propertySettingsContainer) { propertySettingsContainer = null; if (!containers.ContainsKey(id)) return false; propertySettingsContainer = new PropertySettingsContainer(id); Mapper.Map(containers[id], propertySettingsContainer); return true; }
protected internal virtual void UpdatePropertySettings(PageTypeDefinition pageTypeDefinition, PageTypePropertyDefinition propertyDefinition, PageDefinition pageDefinition) { var prop = pageTypeDefinition.Type.GetProperties().Where(p => p.Name == propertyDefinition.Name).FirstOrDefault (); var attributes = prop.GetCustomAttributes(typeof(PropertySettingsAttribute), true); foreach (var attribute in attributes) { PropertySettingsContainer container; if (pageDefinition.SettingsID == Guid.Empty) { pageDefinition.SettingsID = Guid.NewGuid(); PageDefinitionFactory.Save(pageDefinition); container = new PropertySettingsContainer(pageDefinition.SettingsID); } else { if (!_propertySettingsRepository.TryGetContainer(pageDefinition.SettingsID, out container)) { container = new PropertySettingsContainer(pageDefinition.SettingsID); } } var settingsAttribute = (PropertySettingsAttribute)attribute; var wrapper = container.GetSetting(settingsAttribute.SettingType); if (wrapper == null) { wrapper = new PropertySettingsWrapper(); container.Settings.Add(settingsAttribute.SettingType.FullName, wrapper); } bool settingsAlreadyExists = true; if (wrapper.PropertySettings == null) { wrapper.PropertySettings = (IPropertySettings)Activator.CreateInstance(settingsAttribute.SettingType); settingsAlreadyExists = false; } if (settingsAlreadyExists && !settingsAttribute.OverWriteExistingSettings) { return; } if (settingsAttribute.UpdateSettings(wrapper.PropertySettings) || !settingsAlreadyExists) { _propertySettingsRepository.Save(container); } } }
public bool TryGetContainer(Guid id, out PropertySettingsContainer propertySettingsContainer) { propertySettingsContainer = null; if (!containers.ContainsKey(id)) { return(false); } propertySettingsContainer = new PropertySettingsContainer(id); Mapper.Map(containers[id], propertySettingsContainer); return(true); }
protected internal virtual void UpdatePropertySettings(PageTypeDefinition pageTypeDefinition, PageTypePropertyDefinition propertyDefinition, PageDefinition pageDefinition) { var prop = pageTypeDefinition.Type.GetProperties().Where(p => p.Name == propertyDefinition.Name).FirstOrDefault (); var attributes = prop.GetCustomAttributes(typeof(PropertySettingsAttribute), true); foreach (var attribute in attributes) { PropertySettingsContainer container; if (pageDefinition.SettingsID == Guid.Empty) { pageDefinition.SettingsID = Guid.NewGuid(); PageDefinitionFactory.Save(pageDefinition); container = new PropertySettingsContainer(pageDefinition.SettingsID); } else { if (!_propertySettingsRepository.TryGetContainer(pageDefinition.SettingsID, out container)) { container = new PropertySettingsContainer(pageDefinition.SettingsID); } } var settingsAttribute = (PropertySettingsAttribute) attribute; var wrapper = container.GetSetting(settingsAttribute.SettingType); if (wrapper == null) { wrapper = new PropertySettingsWrapper(); container.Settings.Add(settingsAttribute.SettingType.FullName, wrapper); } bool settingsAlreadyExists = true; if (wrapper.PropertySettings == null) { wrapper.PropertySettings = (IPropertySettings) Activator.CreateInstance(settingsAttribute.SettingType); settingsAlreadyExists = false; } if(settingsAlreadyExists && !settingsAttribute.OverWriteExistingSettings) return; if(settingsAttribute.UpdateSettings(wrapper.PropertySettings) || !settingsAlreadyExists) _propertySettingsRepository.Save(container); } }
void UpdatePageDefinitionsGlobalPropertySettings(PageTypePropertyDefinition propertyDefinition, PageTypeDefinition pageTypeDefinition, PropertySettingsContainer container) { object[] attributes = GetPropertyAttributes(propertyDefinition, pageTypeDefinition); var useGlobalSettingsAttribute = attributes.OfType<UseGlobalSettingsAttribute>().FirstOrDefault(); if (useGlobalSettingsAttribute != null) { //TODO: Should validate not null and valid type at startup var globalSettingsUpdater = globalPropertySettingsLocator.GetGlobalPropertySettingsUpdaters().Where(u => u.WrappedInstanceType == useGlobalSettingsAttribute.Type).First(); var wrapper = propertySettingsRepository.GetGlobals(globalSettingsUpdater.SettingsType) .Where(w => globalSettingsUpdater.Match(w)) .First(); container.Settings[globalSettingsUpdater.SettingsType.FullName] = wrapper; //TODO: Add spec validating that exception is thrown with the below uncommented (An item with the same key has already been added.) //container.Settings.Add(globalSettingsUpdater.SettingsType.FullName, wrapper); propertySettingsRepository.Save(container); } }
private PropertySettingsContainer GetPropertySettingsContainer(PageDefinition pageDefinition) { PropertySettingsContainer container; if (pageDefinition.SettingsID == Guid.Empty) { pageDefinition.SettingsID = Guid.NewGuid(); pageDefinitionRepository.Save(pageDefinition); container = new PropertySettingsContainer(pageDefinition.SettingsID); } else { if (!_propertySettingsRepositoryMethod().TryGetContainer(pageDefinition.SettingsID, out container)) { container = new PropertySettingsContainer(pageDefinition.SettingsID); } } return(container); }
private PropertySettingsContainer GetPropertySettingsContainer(PageDefinition pageDefinition) { PropertySettingsContainer container; if (pageDefinition.SettingsID == Guid.Empty) { pageDefinition.SettingsID = Guid.NewGuid(); PageDefinitionFactory.Save(pageDefinition); container = new PropertySettingsContainer(pageDefinition.SettingsID); } else { if (!_propertySettingsRepository.TryGetContainer(pageDefinition.SettingsID, out container)) { container = new PropertySettingsContainer(pageDefinition.SettingsID); } } return container; }
public void Delete(PropertySettingsContainer propertySetting) { throw new NotImplementedException(); }
private void AddToUpdatedCacheKeys(PropertySettingsContainer container) { string cacheKey = string.Format(CultureInfo.InvariantCulture, "EP:{0}", new object[] { typeof(PropertySettingsRepository).FullName }); cacheKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", new object[] { cacheKey, container.Id }); updatedPropertySettingsCacheKeys.Add(cacheKey); }