protected override Sites GetSites() { List <Site> sites = SiteConfiguration.GetSites(); Sites clonedSites = new Sites(); foreach (Site site in sites) { clonedSites.Add(new Site() { ID = site.ID, Name = site.Name, Url = site.Url, ProductVersion = site.ProductVersion }); } return(clonedSites); }
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); }
public static string GetPhysicalPathForId(string siteId, bool isTemplate, string relativePath, out FaultContract Fault) { Fault = null; string physicalPath = null; if (isTemplate) { Template template = TemplateConfiguration.FindTemplateById(siteId); if (template == null) { Fault = new FaultContract(); Fault.FaultType = "Error"; Fault.Message = "Unable to find template with ID = " + siteId; return(null); } else { physicalPath = ServerUtility.MapPath(TemplateFolderPath) + "\\" + template.ID; if (!string.IsNullOrEmpty(relativePath)) { physicalPath += "\\" + relativePath.Replace("/", "\\"); } } } else { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { Fault = new FaultContract(); Fault.FaultType = "Error"; Fault.Message = "Unable to find Site with ID = " + siteId; return(null); } else { physicalPath = site.PhysicalPath; if (!string.IsNullOrEmpty(relativePath)) { physicalPath += "\\" + relativePath.Replace("/", "\\"); } } } return(physicalPath); }
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); }
protected override void SaveSite(string siteId, string newTitle, SitePublishInfo info) { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } FaultContract Fault = null; if (!(new ApplicationBuilderHelper()).SaveConfigurationForSite(site, info, out Fault, newTitle)) { throw new Exception(Fault != null ? Fault.Message : "Unable to save site"); } if (!string.IsNullOrEmpty(newTitle) && site.Title != newTitle) // Update site's title in site configuration list { site.Title = newTitle; SiteConfiguration.SaveSite(site); } }
protected override void DeleteSite(string siteId) { Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } try { // Delete the folder if (System.IO.Directory.Exists(site.PhysicalPath)) { System.IO.Directory.Delete(site.PhysicalPath, true); } } catch { } // Delete the site from the catalog SiteConfiguration.DeleteSite(siteId); }
/// <summary> /// Upgrades the site with the specified ID to the current version of the product /// </summary> /// <param name="siteId"></param> /// <param name="templateId"></param> /// <returns></returns> protected override Site UpgradeSite(string siteId, string templateId, out FaultContract fault) { // Get the site Site site = SiteConfiguration.FindExistingSiteByID(siteId); if (site == null) { throw new Exception("Unable to find site with siteId = " + siteId); } // Do upgrade fault = null; bool upgraded = ApplicationBuilderHelper.UpgradeSite(site, templateId, out fault); if (upgraded) { // Upgrade successful - update the version on the site and save it to disk Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; site.ProductVersion = string.Format("{0}.{1}.{2}.0", currentVersion.Major, currentVersion.Minor, currentVersion.Build); SiteConfiguration.SaveSite(site); return(site); } else { if (fault == null) { fault = new FaultContract() { Message = "Upgrade failed" } } ; return(null); } } }