private void DeployThemes(SitePackage sitepackage, Data.Guid guid, IPackageStatusNotifier notifier) { //Deploy the themes into the site foreach (SitePackageTheme themeWrapper in sitepackage.Themes) { CmsTheme theme = themeWrapper.Theme; Boolean isEnabled = theme.IsEnabled; theme = ThemeManager.Instance.Add(guid, theme.Name, theme.Description); theme.IsEnabled = isEnabled; theme.Header = themeWrapper.Header; theme.Footer = themeWrapper.Footer; ThemeManager.Instance.Save(theme); //Save all of the templates for this theme foreach (CmsTemplate template in themeWrapper.Templates) { CmsTemplate newTemplate = new CmsTemplate(); newTemplate.IsGlobalTemplateType = template.IsGlobalTemplateType; newTemplate.Name = template.Name; newTemplate.SubscriptionGuid = guid.Value; newTemplate.Theme = theme; newTemplate.Content = template.Content; newTemplate.LastSaved = template.LastSaved; TemplateManager.Instance.Save(newTemplate); } //Save the javascript files for this theme foreach (JavascriptFile js in themeWrapper.Javascript) { JavascriptManager.Instance.Save(guid, theme, js); } //Save the css files for this theme foreach (CssFile css in themeWrapper.Css) { CssManager.Instance.Save(guid, theme, css); } //Save all the images for this theme DoNotify(notifier, "Copying Theme Images to Site (please wait...) "); String copyFromImageContainer = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, sitepackage.OriginalSiteGuid.Value); String copyToImageContainer = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, guid.Value); IStorageClient client = StorageHelper.GetStorageClient(); client.CopyFromSnapshots(themeWrapper.Images, copyFromImageContainer, copyToImageContainer, theme.ThemeGuid, Permissions.Public); SaveImagesToDatabase(notifier, guid, copyToImageContainer, theme.ThemeGuid); } }
private void DeployPages(SitePackage sitepackage, Data.Guid guid, IPackageStatusNotifier notifier) { //Deploy the sitemap foreach (CmsSitePath path in sitepackage.SiteMapPaths) { path.Id = 0; path.SubscriptionGuid = guid.Value; CmsSiteMap.Instance.Save(path); } //Deploy the pages into the site foreach (SitePackagePage pageWrapper in sitepackage.Pages) { CmsPage page = pageWrapper.Page; page.Id = 0; page.SubscriptionId = guid.Value; page.IsApproved = false; page.Guid = System.Guid.NewGuid().ToString(); PageManager.Instance.Save(page); //Save the javascript files for this theme foreach (JavascriptFile js in pageWrapper.Javascript) { JavascriptManager.Instance.Save(guid, page, js); } //Save the css files for this theme foreach (CssFile css in pageWrapper.Css) { CssManager.Instance.Save(guid, page, css); } } DoNotify(notifier, "Copying Page Images to Site (please wait...) "); //Save all the page-level images for this site String copyFromImageContainer = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, sitepackage.OriginalSiteGuid.Value); String copyToImageContainer = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, guid.Value); IStorageClient client = StorageHelper.GetStorageClient(); client.CopyFromSnapshots(sitepackage.PageImages, copyFromImageContainer, copyToImageContainer, StorageClientConst.RootFolder, Permissions.Public); //Save the page images to the database SaveImagesToDatabase(notifier, guid, copyToImageContainer, StorageClientConst.RootFolder); }
private static void DeployContentTypes(SitePackage sitepackage, Data.Guid guid) { foreach (SiteContentType ct in sitepackage.ContentTypes) { CmsContentType type = ct.ContentType; type.Id = 0; type.Guid = null; ContentManager.Instance.AddContentType(guid, type); foreach (CmsContentTypeField field in ct.Fields) { field.Id = 0; field.Parent = null; ContentManager.Instance.AddContentTypeField(type, field); } } }
private void DeployContent(SitePackage sitepackage, Data.Guid guid) { foreach (SiteContent ct in sitepackage.SiteContent) { CmsContent newcontent = new CmsContent(); CmsContent content = ct.Content; IList<CmsContentField> fields = new List<CmsContentField>(content.Fields); newcontent.Guid = System.Guid.NewGuid().ToString(); newcontent.SubscriptionId = guid.Value; newcontent.ContentType = content.ContentType; newcontent.Content = content.Content; newcontent.Culture = content.Culture; newcontent.ExpireDate = content.ExpireDate; newcontent.IsApproved = content.IsApproved; newcontent.LastSaved = content.LastSaved; newcontent.PublishDate = content.PublishDate; newcontent.RegistrationPage = content.RegistrationPage; newcontent.RequiresRegistration = content.RequiresRegistration; foreach (CmsContentField field in fields) { CmsContentField newfield = new CmsContentField(); newfield.Name = field.Name; newfield.ObjectType = field.ObjectType; newfield.Value = field.Value; newcontent.AddField(newfield); } ContentManager.Instance.Save(newcontent); } }
public Data.Guid CreatePackage(Package package, IPackageStatusNotifier notifier) { PackageDao dao = new PackageDao(); this.guid = package.Guid; String siteGuid = package.OwnerSubscriptionId; SitePackage sitepackage = new SitePackage(); IList<SitePackageTheme> packageThemes = new List<SitePackageTheme>(); IList<SitePackagePage> packagePages = new List<SitePackagePage>(); IList<SiteContentType> packageContentTypes = new List<SiteContentType>(); IList<SiteContent> packageContent = new List<SiteContent>(); IList<CmsSitePath> sitePaths = new List<CmsSitePath>(); DoNotify(notifier, "Packaging Themes"); PackageThemes(siteGuid, packageThemes, notifier); DoNotify(notifier, "Packaging Pages"); PackagePages(siteGuid, packagePages); DoNotify(notifier, "Packaging Content Types"); PackageContentTypes(siteGuid, packageContentTypes); DoNotify(notifier, "Packaging Content"); PackageContent(siteGuid, packageContent); IStorageClient client = StorageHelper.GetStorageClient(); String imageDirectory = SiteHelper.GetStorageKey(SiteHelper.ImagesContainerKey, siteGuid); DoNotify(notifier, "Creating Page Image Snapshots (please wait)"); sitepackage.PageImages = client.CreateSnapshot(imageDirectory, StorageClientConst.RootFolder); sitepackage.Themes = packageThemes; sitepackage.SiteMapPaths = CmsSiteMap.Instance.GetAllPaths(siteGuid); sitepackage.Pages = packagePages; sitepackage.ContentTypes = packageContentTypes; sitepackage.SiteContent = packageContent; sitepackage.OriginalSiteGuid = siteGuid; DoNotify(notifier, "Creating Package Archive"); byte[] data = null; using (MemoryStream outputstream = new MemoryStream()) { //Serialize the object and then compress the serialized object data = Serializer.ToByteArray<SitePackage>(sitepackage); using (ZipFile zip = new ZipFile()) { zip.AddEntry("sitepackage.bin", data); zip.Save(outputstream); } data = null; //Write the serialized data to the container data = outputstream.ToArray(); } DoNotify(notifier, "Saving Package Archive"); client = StorageHelper.GetStorageClient(); client.Save(PackageContainer,PackageDirectory, package.Guid + PackageExtension, data, Permissions.Private); return package.Guid; }