Beispiel #1
0
        public void Exporting(ExportContext context)
        {
            if (!context.ExportOptions.CustomSteps.Contains("RedactedSiteSettings"))
            {
                return;
            }

            var excludedSettings = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>().ExcludedSiteSettings;

            var settings   = new XElement("RedactedSiteSettings");
            var hasSetting = false;

            foreach (var sitePart in _orchardServices.WorkContext.CurrentSite.ContentItem.Parts)
            {
                if (excludedSettings.Contains(sitePart.PartDefinition.Name))
                {
                    continue;
                }

                var setting = new XElement(sitePart.PartDefinition.Name);

                foreach (var property in sitePart.GetType().GetProperties())
                {
                    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)
                        {
                            setting.SetAttributeValue(property.Name, _textRedactionService.RedactText(Convert.ToString(property.GetValue(sitePart, null))));
                            hasSetting = true;
                        }
                    }
                }

                if (hasSetting)
                {
                    settings.Add(setting);
                    hasSetting = false;
                }
            }

            var rootElement = context.Document.Descendants("Orchard").FirstOrDefault();

            if (rootElement == null)
            {
                var ex = new OrchardException(T("Could not export this site's Redacted Settings because the document passed via the Export Context did not contain a node called 'Orchard'. The document was malformed."));
                Logger.Error(ex, ex.Message);
                throw ex;
            }

            rootElement.Add(settings);
        }
Beispiel #2
0
 protected override void Exporting(BodyPart part, Orchard.ContentManagement.Handlers.ExportContentContext context)
 {
     context.Element(part.PartDefinition.Name).SetAttributeValue("Text", _textRedactionService.RedactText(part.Text));
 }