private SiteDefinition CreateSiteDefinition() { var site = new SiteDefinition() { Name = Name, SiteUrl = Url, StartPage = StartPage }; _repository.Save(site); return(site); }
private int MergeSiteDefinitions(IEnumerable <SiteDefinition> siteDefinitionsToUpdate) { var updatedSites = 0; var existingSites = _siteDefinitionRepository.List(); foreach (var siteDefinitionToUpdate in siteDefinitionsToUpdate) { SiteDefinition site = GetExistingSiteDefinition(existingSites, siteDefinitionToUpdate); if (site != null) { site = site.CreateWritableClone(); if (!string.IsNullOrEmpty(siteDefinitionToUpdate.Name) && site.Name != siteDefinitionToUpdate.Name) { // Will set the name of the site to the provided Name if Id exist and Name is specified and different from the found existing site. site.Name = siteDefinitionToUpdate.Name; } site.SiteUrl = siteDefinitionToUpdate.SiteUrl; site.Hosts = siteDefinitionToUpdate.Hosts; _siteDefinitionRepository.Save(site); updatedSites++; Logger.Information($"Updated {siteDefinitionToUpdate.Name} to site URL {siteDefinitionToUpdate.SiteUrl} and {siteDefinitionToUpdate.Hosts.Count} hostnames."); resultLog.AppendLine($"Updated {siteDefinitionToUpdate.Name} to site URL {siteDefinitionToUpdate.SiteUrl} and {siteDefinitionToUpdate.Hosts.Count} hostnames.<br />"); } else { Logger.Warning($"Could not find site {siteDefinitionToUpdate.Name} or site already has site URL {siteDefinitionToUpdate.SiteUrl}."); resultLog.AppendLine($"Could not find site {siteDefinitionToUpdate.Name} or site already has site URL {siteDefinitionToUpdate.SiteUrl}.<br />"); } } return(updatedSites); }
public Task ExecuteAsync() { var primaryWebsiteUrl = SiteConfiguration.Site.PrimaryUrl; var home = _contentRepository.GetDefault <HomePage>(ContentReference.RootPage); home.Name = SiteConfiguration.Site.Name; var homeReference = _contentRepository.Save(home, SaveAction.Publish); var siteDefinitions = _siteDefinitionRepository.List().ToArray(); if (siteDefinitions.Any()) { foreach (var siteDefinition in siteDefinitions.Select(d => d.CreateWritableClone())) { siteDefinition.StartPage = homeReference; _siteDefinitionRepository.Save(siteDefinition); } } else { var primaryWebsiteUri = new Uri(primaryWebsiteUrl); _siteDefinitionRepository.Save(new SiteDefinition { Name = SiteConfiguration.Site.Name, Id = Guid.NewGuid(), StartPage = homeReference, SiteUrl = new Uri(primaryWebsiteUrl), Hosts = new[] { new HostDefinition { Language = new CultureInfo("no"), Name = primaryWebsiteUri.Authority, Type = HostDefinitionType.Primary, UseSecureConnection = "https".Equals(primaryWebsiteUri.Scheme, StringComparison.OrdinalIgnoreCase) } } }); } return(Task.CompletedTask); }
public Task ExecuteAsync() { var allSites = _siteDefinitionRepository.List(); foreach (var siteDefinition in allSites) { var clone = siteDefinition.CreateWritableClone(); clone.Hosts.Add(new HostDefinition() { Name = "*", UseSecureConnection = true }); _siteDefinitionRepository.Save(clone); } return(Task.CompletedTask); }
private static void DefineSite(ISiteDefinitionRepository siteDefinitionRepository, string siteName, ContentReference startPage, string siteUrl) { var existingSite = siteDefinitionRepository.Get(siteName); if (existingSite != null) { return; } // Define our site var siteDefinition = new SiteDefinition { Name = siteName, SiteUrl = new Uri($"http://{siteUrl}/", UriKind.Absolute), StartPage = startPage }; siteDefinitionRepository.Save(siteDefinition); }
private static void EnsureSiteDefinition(ISiteDefinitionRepository siteDefinitionRepository, ContentReference startPage, ContentReference assetsFolder) { var siteDefinition = siteDefinitionRepository.List() .FirstOrDefault(x => x.StartPage.CompareToIgnoreWorkID(startPage)); if (siteDefinition != null) { return; } siteDefinition = new SiteDefinition { Name = "Static Website", StartPage = startPage, SiteAssetsRoot = assetsFolder, SiteUrl = new Uri(StaticWebsiteUrl) // To do: Should come from configuration? }; siteDefinitionRepository.Save(siteDefinition); }
public void Dump() { var startPage = _contentRepository.GetDefault <StartPage>(ContentReference.RootPage); startPage.Name = "Start"; var contentLink = _contentRepository.Save(startPage, SaveAction.Publish, AccessLevel.NoAccess); var site = new SiteDefinition { Name = "Start", StartPage = contentLink, SiteUrl = new Uri("http://localhost/") }; site.Hosts.Add(new HostDefinition { Name = site.SiteUrl.Authority }); site.Hosts.Add(new HostDefinition { Name = SiteDefinition.WildcardHostName }); _siteDefinitionRepository.Save(site); }
public static bool CreateSite( ISiteDefinitionRepository siteDefinitionRepository, IContent homePage, string siteUrl) { Guard.ValidateObject(siteDefinitionRepository); if (siteDefinitionRepository.List().Any()) { return(true); } var siteDefinition = new SiteDefinition { Name = "JonDJones.Website", SiteUrl = new Uri(siteUrl), StartPage = homePage.ContentLink, Hosts = GetHostDefinitions() }; siteDefinitionRepository.Save(siteDefinition); return(true); }
private void Save(SiteDefinition site) { _repository.Save(site); }