protected override Site CreateSite(string targetSiteName, string targetTitle, string targetSiteDescription, string targetSiteTemplateId, SitePublishInfo targetSitePublishInfo) { // Make sure target site directory does not already exist string physicalPath = string.Format("{0}\\{1}", AppSettings.AppsPhysicalDir, targetSiteName); if (System.IO.Directory.Exists(physicalPath)) { throw new Exception("Site with name '" + targetSiteName + "' is in use already. Please try an alternate name."); } // Create a new site Site targetSite = new Site() { ID = Guid.NewGuid().ToString("N"), IsHostedOnIIS = true, Name = targetSiteName, Title = targetTitle, Description = targetSiteDescription, PhysicalPath = physicalPath, Url = string.Format("{0}/{1}", AppSettings.AppsBaseUrl.TrimEnd('/'), targetSiteName.TrimStart('/')) }; Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; targetSite.ProductVersion = string.Format("{0}.{1}.{2}.0", currentVersion.Major, currentVersion.Minor, currentVersion.Build); // Create the viewer application ApplicationBuilderHelper appBuilderHelper = new ApplicationBuilderHelper(); FaultContract Fault = null; if (!appBuilderHelper.CreateSiteFromTemplate(targetSiteTemplateId, targetSite, true, out Fault)) { throw new Exception(Fault != null ? Fault.Message : "Unable to create site"); } // Save the configuration files if (!appBuilderHelper.SaveConfigurationForSite(targetSite, targetSitePublishInfo, out Fault)) { return(null); } // Add entry to Sites.xml SiteConfiguration.AddSite(targetSite); // Return target site object return(targetSite); }
protected override Site CopySite(string sourceSiteId, string targetSiteName, string targetSiteDescription) { // Resolve source site id into its corresponding site object Site sourceSite = SiteConfiguration.FindExistingSiteByID(sourceSiteId); if (sourceSite == null) { throw new Exception("Unable to find site with siteId = " + sourceSiteId); } // Make sure target site directory does not already exist string physicalPath = string.Format("{0}\\{1}", AppSettings.AppsPhysicalDir, targetSiteName); if (System.IO.Directory.Exists(physicalPath)) { throw new Exception("Site with name '" + targetSiteName + "' is in use already. Please try an alternate name."); } // Create a new site Site targetSite = new Site(); targetSite.ID = Guid.NewGuid().ToString("N"); targetSite.IsHostedOnIIS = true; targetSite.Name = targetSiteName; targetSite.Description = targetSiteDescription; targetSite.PhysicalPath = physicalPath; targetSite.Url = string.Format("{0}/{1}", AppSettings.AppsBaseUrl.TrimEnd('/'), targetSiteName.TrimStart('/')); targetSite.ProductVersion = sourceSite.ProductVersion; // Copy files from source site directory to target site directory FaultContract Fault = null; if (!(new ApplicationBuilderHelper()).CopySite(sourceSite.PhysicalPath, targetSite, true, out Fault)) { throw new Exception(Fault != null ? Fault.Message : "Unable to copy site"); } // Update site database (XML file) SiteConfiguration.AddSite(targetSite); // Return target site object return(targetSite); }