private void SetSetting(XAttribute attribute, ContentPart contentPart) { var attributeName = attribute.Name.LocalName; var attributeValue = _settingRedactionService.GetSettingValue(contentPart.PartDefinition.Name, attributeName, attribute.Value); try { _realtimeFeedbackService.Info(T("Updating site settings for {0}.{1}. Value being set to {2} ({3} before redactions)", contentPart.PartDefinition.Name, attributeName, attributeValue, attribute.Value)); var property = contentPart.GetType().GetProperty(attributeName); if (property == null) { _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name)); return; } var propertyType = property.PropertyType; if (propertyType == typeof(string)) { property.SetValue(contentPart, attributeValue, null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else if (propertyType == typeof(bool)) { property.SetValue(contentPart, Boolean.Parse(attributeValue), null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else if (propertyType == typeof(int)) { property.SetValue(contentPart, Int32.Parse(attributeValue), null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else { _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because its type is not supported. Settings should be integer, boolean or string.", attributeName, contentPart.PartDefinition.Name)); } } catch (Exception ex) { Logger.Error(ex, "An exception was caught while trying to set the site settings. A failed attempt was made to set '{0}' to '{1}'. Execution of the import step 'RedactedSiteSettings' has continued.", attributeName, attributeValue); } }
private void SetSetting(XAttribute attribute, ContentPart contentPart) { var attributeName = attribute.Name.LocalName; var attributeValue = _settingRedactionService.GetSettingValue(contentPart.PartDefinition.Name, attributeName, attribute.Value); _realtimeFeedbackService.Info(T("Updating site settings for {0}.{1}. Value being set to {2} ({3} before redactions)", contentPart.PartDefinition.Name, attributeName, attributeValue, attribute.Value)); var property = contentPart.GetType().GetProperty(attributeName); if (property == null) { _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name)); return; } var propertyType = property.PropertyType; if (propertyType == typeof(string)) { property.SetValue(contentPart, attributeValue, null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else if (propertyType == typeof(bool)) { property.SetValue(contentPart, Boolean.Parse(attributeValue), null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else if (propertyType == typeof(int)) { property.SetValue(contentPart, Int32.Parse(attributeValue), null); _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue)); } else { _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because its type is not supported. Settings should be integer, boolean or string.", attributeName, contentPart.PartDefinition.Name)); } }