public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("Current Theme")) { return; }

            var currentTheme = _siteThemeService.GetSiteTheme();

            if (currentTheme == null)
            {
                var ex = new OrchardException(T("Could not add the Current Theme step to the export because there is currently no theme activated."));
                Logger.Error(ex, ex.Message);
                throw ex;
            }

            var xmlElement = new XElement("CurrentTheme", new XAttribute("name", currentTheme.Name), new XAttribute("id", currentTheme.Id));

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not add the Current Theme step to the export 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(xmlElement);
        }
        public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("RunContentMigrations")) { return; }

            var xmlElement = new XElement("RunContentMigrations");

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not add the Run Data Migrations step to the export 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(xmlElement);
        }
        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);
        }
        public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("Aliases")) { return; }

            var xmlElement = new XElement("Aliases");

            var autoroutePaths = _contentManager.Query<AutoroutePart>().List().Select(p=>p.Path);
            var allAliasInfos = _aliasHolder.GetMaps().SelectMany(m=>m.GetAliases()).ToList();
            
            //we need to remove any aliases that are autoroutes because the remote conent id may not sync up with the local content id. the autoroutes will be imported as part of the content import
            var aliasInfosToExport = allAliasInfos.Where(ai => !autoroutePaths.Contains(ai.Path));

            foreach (var aliasInfo in aliasInfosToExport) 
            {
                var aliasElement = new XElement("Alias", new XAttribute("Path", aliasInfo.Path));

                var routeValuesElement = new XElement("RouteValues");
                foreach (var routeValue in aliasInfo.RouteValues) {
                    routeValuesElement.Add(new XElement("Add", new XAttribute("Key", routeValue.Key), new XAttribute("Value", routeValue.Value)));
                }

                aliasElement.Add(routeValuesElement);
                xmlElement.Add(aliasElement);
            }

            //add a collection of all the alias paths in this site so that the importing site can remove aliases that don't exist remotely
            var pathsElement = new XElement("Paths");
            foreach (var aliasInfo in allAliasInfos) {
                pathsElement.Add(new XElement("Add", new XAttribute("Path", aliasInfo.Path)));
            }

            xmlElement.Add(pathsElement);

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not export this site's Aliases 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(xmlElement);
        }
        public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("FeatureSync")) { return; }

            var xmlElement = new XElement("FeatureSync");

            foreach (var feature in _featureManager.GetEnabledFeatures()) {
                xmlElement.Add(new XElement("Feature", new XAttribute("Id", feature.Id)));
            }

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not export this site's Enabled Features 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.AddFirst(xmlElement);
        }
        public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("Executed Data Migrations")) { return; }

            var xmlElement = new XElement("ExecutedDataMigrations");

            foreach (var migration in _contentMigrationStateService.GetExecutedMigrations())
            {
                xmlElement.Add(new XElement("Migration", new XAttribute("Name", migration)));
            }

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not export this site's Executed Data Migrations 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(xmlElement);
        }
        public void Exporting(ExportContext context) {
            if (!context.ExportOptions.CustomSteps.Contains("ContentTrim")) { return; }

            var xmlElement = new XElement("ContentTrim");
            var contentTypesElement = new XElement("ContentTypes");

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

            var contentTypeNames = _contentManager.GetContentTypeDefinitions().Select(ctd => ctd.Name).Except(settings.ExcludedContentTypes).ToList();

            foreach (var contentType in contentTypeNames)
            {
                contentTypesElement.Add(new XElement("add", new XAttribute("type", contentType)));
            }

            xmlElement.Add(contentTypesElement);

            var contentToKeepElement = new XElement("ContentToKeep");

            foreach (var identityPart in _contentManager.Query<IdentityPart>(contentTypeNames.ToArray()).List())
            {
                contentToKeepElement.Add(new XElement("add", new XAttribute("identifier", identityPart.Identifier)));
            }

            xmlElement.Add(contentToKeepElement);

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

            if (rootElement == null) 
            {
                var ex = new OrchardException(T("Could not export the content to trim 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(xmlElement);
        }