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));
            }
        }
Beispiel #2
0
        public static void Store <TProperty>(this ContentPart contentPart, string name,
                                             TProperty value, bool versioned = false)
        {
            var partName    = contentPart.GetType().Name;
            var infosetPart = contentPart.As <InfosetPart>();

            Store(infosetPart, partName, name, value, versioned);
        }
Beispiel #3
0
        public static TProperty Retrieve <TProperty>(this ContentPart contentPart, string name,
                                                     bool versioned = false)
        {
            var infosetPart = contentPart.As <InfosetPart>();
            var el          = infosetPart == null
                ? null
                : (versioned ? infosetPart.VersionInfoset.Element : infosetPart.Infoset.Element)
                              .Element(contentPart.GetType().Name);

            return(el == null ? default(TProperty) : el.Attr <TProperty>(name));
        }
        protected JObject SerializePart(ContentPart part) {
            var partObject = new JObject();

            // see if we have a Record property...
            var recordPropertyInfo = part.GetType().GetProperty("Record");
            if (recordPropertyInfo != null) {

                // get the value and serialize it...
                object val = recordPropertyInfo.GetValue(part, BindingFlags.GetProperty, null, null, null);
                if (val != null) {
                    var serializer = new JsonSerializer { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
                    JObject recordObject = JObject.FromObject(val,
                    serializer);
                    partObject.Add("Record", recordObject);
                }
            }

            // now add the fields to the json object....
            var fieldsArray = new JArray();

            foreach (var contentField in part.Fields) {
                var fieldObject = SerializeField(contentField);
                fieldsArray.Add(fieldObject);
            }

            partObject.Add("Fields", fieldsArray);

            // add the settings...
            var settingsObject = new JObject();

            foreach ( var key in part.Settings.Keys) {
                settingsObject.Add(new JProperty(key, part.Settings[key]));
            }

            partObject.Add("Settings", settingsObject);

            // add the part settings...
            var partSettingsObject = new JObject();

            foreach (string key in part.TypePartDefinition.Settings.Keys) {
                partSettingsObject.Add(new JProperty(key, part.TypePartDefinition.Settings[key]));
            }

            partObject.Add("TypePartDefinition.Settings", partSettingsObject);

            return partObject;
        }
Beispiel #5
0
        private IEnumerable<XAttribute> ExportSettingsPartAttributes(ContentPart sitePart) {
            foreach (var property in sitePart.GetType().GetProperties().OrderBy(x => x.Name)) {
                var propertyType = property.PropertyType;

                // Supported types (we also know they are not indexed properties).
                if (propertyType == typeof(string) || propertyType == typeof(bool) || propertyType == typeof(int)) {
                    // Exclude read-only properties.
                    if (property.GetSetMethod() != null) {
                        var value = property.GetValue(sitePart, null);
                        if (value == null)
                            continue;

                        yield return new XAttribute(property.Name, value);
                    }
                }
            }
        }
 private static void SetSetting(XAttribute attribute, ContentPart contentPart) {
     var attributeName = attribute.Name.LocalName;
     var attributeValue = attribute.Value;
     var property = contentPart.GetType().GetProperty(attributeName);
     if (property == null) {
         throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name));
     }
     var propertyType = property.PropertyType;
     if (propertyType == typeof(string)) {
         property.SetValue(contentPart, attributeValue, null);
     }
     else if (propertyType == typeof(bool)) {
         property.SetValue(contentPart, Boolean.Parse(attributeValue), null);
     }
     else if (propertyType == typeof(int)) {
         property.SetValue(contentPart, Int32.Parse(attributeValue), null);
     }
     else {
         throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because its type is not supported. Settings should be integer,boolean or string.", attributeName, contentPart.PartDefinition.Name));
     }
 }
        private void ImportSettingPart(ContentPart sitePart, XElement element) {

            foreach (var attribute in element.Attributes()) {
                var attributeName = attribute.Name.LocalName;
                var attributeValue = attribute.Value;

                var property = sitePart.GetType().GetProperty(attributeName);
                if (property == null) {
                    continue;
                }

                var propertyType = property.PropertyType;
                if (propertyType == typeof(string)) {
                    property.SetValue(sitePart, attributeValue, null);
                }
                else if (propertyType == typeof(bool)) {
                    property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
                }
                else if (propertyType == typeof(int)) {
                    property.SetValue(sitePart, Int32.Parse(attributeValue), null);
                }
            }
        }
        private void ImportSettingPart(ContentPart sitePart, XElement element) {

            foreach (var attribute in element.Attributes()) {
                var attributeName = attribute.Name.LocalName;
                var attributeValue = attribute.Value;

                var property = sitePart.GetType().GetProperty(attributeName);
                if (property == null) {
                    throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because it was not found.", attributeName, sitePart.PartDefinition.Name));
                }

                var propertyType = property.PropertyType;
                if (propertyType == typeof(string)) {
                    property.SetValue(sitePart, attributeValue, null);
                }
                else if (propertyType == typeof(bool)) {
                    property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
                }
                else if (propertyType == typeof(int)) {
                    property.SetValue(sitePart, Int32.Parse(attributeValue), null);
                }
            }
        }
Beispiel #9
0
 public void Weld(ContentPart part)
 {
     Parts.Add(part.GetType().Name, part);
 }
Beispiel #10
0
 public static ContentItem Update(this ContentItem contentItem, ContentPart contentPart)
 {
     contentItem.Data[contentPart.GetType().Name] = JObject.FromObject(contentPart);
     return(contentItem);
 }
Beispiel #11
0
 /// <summary>
 /// Updates the content item data.
 /// </summary>
 /// <returns>The current <see cref="ContentPart"/> instance.</returns>
 public static ContentPart Apply(this ContentPart contentPart)
 {
     contentPart.ContentItem.Apply(contentPart.GetType().Name, contentPart);
     return(contentPart);
 }
Beispiel #12
0
 public void Weld(ContentPart part)
 {
     Parts.Add(part.GetType().Name, part);
 }