Пример #1
0
        public async Task ExportSiteAsTemplate(string siteId, string templateId, string templateTitle, string processId)
        {
            if (siteId == null)
            {
                throw new ArgumentNullException(nameof(siteId));
            }

            if (string.IsNullOrWhiteSpace(templateId))
            {
                throw new ArgumentNullException(nameof(templateId));
            }

            if (string.IsNullOrWhiteSpace(templateTitle))
            {
                throw new ArgumentNullException(nameof(templateTitle));
            }

            templateId = templateId.Replace(" ", String.Empty).ToLower();

            // Get the site and site template for common access
            _site = await _siteManager.GetByIdAsync(siteId);

            _baseTemplate = _templateManager.GetTemplate(_site.SiteTemplateId);

            // Set IO paths for common access
            _exportTemplateFolder     = Path.Combine(_exportRootFolder, templateId);
            _exportDataFolder         = Path.Combine(_exportTemplateFolder, SiteTemplate.DATA_FOLDER_NAME);
            _exportDefaultThemeFolder = Path.Combine(_exportTemplateFolder, SiteTemplate.THEMES_FOLDER_NAME, SiteTemplate.THEMES_DEFAULT_NAME);
            _baseTemplateFolder       = Path.Combine(_coreOptions.FileSystemRoot, _baseTemplate.TemplateFolder.Replace("/", @"\"));
            _baseDefaultThemeFolder   = Path.Combine(_baseTemplateFolder, SiteTemplate.THEMES_FOLDER_NAME, SiteTemplate.THEMES_DEFAULT_NAME);

            _logger.SetCategory("Jobs.ExportTemplate", processId ?? Guid.NewGuid().ToString());
            _logger.Log($"Exporting site {_site.Title} as Template {templateTitle}, version {CURRENT_SCHEMA}");

            // Initialize a new template to export
            _exportTemplate = new SiteTemplate()
            {
                Schema        = CURRENT_SCHEMA,
                Id            = templateId,
                Title         = templateTitle,
                PageTemplates = new List <PageTemplate>(),
                Pages         = new List <SiteTemplatePage>(),
                MasterPages   = new List <SiteTemplateMasterPage>(),
                NavMenus      = new List <SiteTemplateNav>(),
                Themes        = new List <SiteTemplateTheme>(),

                // scripts can be set directly from base w/o modification
                Scripts = _baseTemplate.Scripts
            };

            // Perform export steps
            ScaffoldExportFolder();
            ExportDefaultTheme();
            ExportPageTemplates();

            await ExportSiteCssAsTemplateCss();
            await ExportMasterPages();
            await ExportPages();

            WriteTemplateConfigFile();

            _logger.Log("Export complete");

            // Refresh template manager cache to pickup the exported template
            _templateManager.RefreshInternalCache();
        }