private IEnumerable<UrlDefinition> ProcessSite(Sitecore.Data.Items.Item homeItem, SiteDefinition def, Sitecore.Globalization.Language language) { IProviderSearchContext ctx; if (string.IsNullOrEmpty(this.indexName)) ctx = ContentSearchManager.GetIndex((SitecoreIndexableItem)homeItem).CreateSearchContext(); else ctx = ContentSearchManager.GetIndex(this.indexName).CreateSearchContext(); try { var results = ctx.GetQueryable<SitemapResultItem>() .Where(i => i.Paths.Contains(homeItem.ID) && i.Language == language.Name); var tmplPred = PredicateBuilder.False<SitemapResultItem>(); foreach (var tmpl in def.IncludedBaseTemplates.Select(i => Sitecore.Data.ID.Parse(i))) tmplPred = tmplPred.Or(i => i.AllTemplates.Contains(tmpl)); foreach (var tmpl in def.IncludedTemplates.Select(i => Sitecore.Data.ID.Parse(i))) tmplPred = tmplPred.Or(i => i.TemplateId == tmpl); var itemPred = PredicateBuilder.True<SitemapResultItem>(); foreach (var id in def.ExcludedItems.Select(i => Sitecore.Data.ID.Parse(i))) itemPred = itemPred.And(i => i.ItemId != id); results = results.Where(tmplPred.And(itemPred)); var items = results .Select(i => Sitecore.Configuration.Factory.GetDatabase(i.DatabaseName).GetItem(i.ItemId, Sitecore.Globalization.Language.Parse(i.Language), Sitecore.Data.Version.Latest)) .ToList(); var sb = new StringBuilder(); var options = Sitecore.Links.UrlOptions.DefaultOptions; options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving; options.Site = SiteContext.GetSite(def.SiteName); if (def.EmbedLanguage) options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always; else options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never; options.AlwaysIncludeServerUrl = true; options.Language = language; foreach (var item in items) { if (item.Versions.Count > 0) yield return new UrlDefinition(Sitecore.Links.LinkManager.GetItemUrl(item, options), item.Statistics.Updated); } } finally { ctx.Dispose(); } }
public void GetSiteDefinition_ProviderReturnsDefinition_ShouldReturnDefinition(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName) { var siteDefinitionId = ID.NewID; db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) { item }); var definitionItem = db.GetItem(siteDefinitionId); var definition = new SiteDefinition(); definition.Item = definitionItem; provider.GetContextSiteDefinition(Arg.Any<Item>()).Returns(definition); var siteContext = new SiteContext(provider); var contextItem = db.GetItem(item.ID); var siteDefinition = siteContext.GetSiteDefinition(contextItem); siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID); }
/// <summary> /// The get server url by site. /// </summary> /// <param name="site"> /// The site. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public static string GetServerUrlBySite(SiteDefinition site) { return(site.SiteUrl.AbsoluteUri); }
/// <summary> /// Creates a new instance of the ModelNode adding site model provided. /// If RequireSelfProcessing set as 'true', then site model is going to be processed and pushed by SPMeta2 API. /// Use action to get access to the "site model node" and construct model tree. /// </summary> /// <param name="siteDefinition"></param> /// <param name="action"></param> /// <returns></returns> public static SiteModelNode NewSiteModel(SiteDefinition siteDefinition, Action <SiteModelNode> action) { return(NewModelNode <SiteDefinition, SiteModelNode>(siteDefinition, action)); }
private static SiteDefinition SiteDefinition(XmlNode node) { var def = new SiteDefinition { EmbedLanguage = true, SiteName = XmlUtil.GetAttribute("name", node), }; var embed = XmlUtil.GetAttribute("embedLanguage", node); if (!string.IsNullOrEmpty(embed)) { bool embedVal; if (!bool.TryParse(embed, out embedVal)) { embedVal = true; } def.EmbedLanguage = embedVal; } var useDisplayName = XmlUtil.GetAttribute("useDisplayName", node); if (!string.IsNullOrEmpty(useDisplayName)) { bool useDisplay; if (!bool.TryParse(useDisplayName, out useDisplay)) { useDisplay = false; } def.UseDisplayName = useDisplay; } var indexName = XmlUtil.GetAttribute("IndexName", node); def.IndexName = !string.IsNullOrEmpty(indexName) ? indexName : "sitecore_web_index"; var fieldName = XmlUtil.GetAttribute("DisplayInSitemapFieldName", node); def.DisplayInSitemapFieldName = !string.IsNullOrEmpty(fieldName) ? fieldName : "Display in Sitemap"; var urlFieldName = XmlUtil.GetAttribute("SitemapUrlFieldname", node); def.SitemapUrlFieldName = !string.IsNullOrEmpty(urlFieldName) ? urlFieldName : "Sitemap Url"; var useHttps = XmlUtil.GetAttribute("UseHttps", node); def.UseHttps = useHttps != null && useHttps.Equals("true"); var hostName = XmlUtil.GetAttribute("HostName", node); def.HostName = !string.IsNullOrEmpty(hostName) ? hostName : HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); var templateNode = node.SelectSingleNode("Templates"); if (templateNode == null) { return(def); } foreach (XmlNode template in templateNode.ChildNodes) { def.Templates.Add(template.InnerText); } return(def); }
public SiteBuilder(SiteDefinition definition) { _definition = definition; }
public static ModelNode AddHostSite(this ModelNode model, SiteDefinition definition) { return(AddHostSite(model, definition, null)); }
public static ModelNode AddHostSite(this ModelNode model, SiteDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing())); }
private static void SetupSiteDefinition() { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var siteDefinitionRepository = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>(); var siteName = "IntegrationTestSite"; var oldSiteDefinition = siteDefinitionRepository.Get(siteName); if (oldSiteDefinition != null) { siteDefinitionRepository.Delete(oldSiteDefinition.Id); } var startPage = contentRepository.GetDefault<StartPage>(ContentReference.RootPage); startPage.Name = "Start page"; var startPageReference = contentRepository.Save(startPage, SaveAction.Publish, AccessLevel.NoAccess); var siteDefinition = new SiteDefinition { Name = siteName, StartPage = startPageReference.ToReferenceWithoutVersion(), SiteUrl = new Uri("http://localhost/") }; siteDefinition.Hosts.Add(new HostDefinition { Name = siteDefinition.SiteUrl.Authority }); siteDefinition.Hosts.Add(new HostDefinition { Name = SiteDefinition.WildcardHostName }); siteDefinitionRepository.Save(siteDefinition); SiteDefinition.Current = siteDefinition; }
public void Happypath() { var popCenter = new SiteDefinition() { Name = "Population Center", Description = "A center of population.", }; popCenter.Attributes["Evil"] = new AttributeDefinition() { BaseValue = "Rand.Next(-5, 5)" }; popCenter.Attributes["Population"] = new AttributeDefinition() { BaseValue = "Rand.Next(0, 1000000)" }; var cityDef = new SiteDefinition() { Name = "City", Description = "A moderate sized settlement", InheritsFrom = "Population Center", }; cityDef.Attributes["Population"] = new AttributeDefinition() { BaseValue = "Rand.Next(20000, 100000)" }; IList <SiteDefinition> sites = new List <SiteDefinition> { popCenter, cityDef, }; var definitions = new Definitions(sites); int worldSeed = 915434125; Random rdm = new Random(worldSeed); ConditionCompiler <BaseGlobalVariables> processor = new ConditionCompiler <BaseGlobalVariables>(new BaseGlobalVariables() { World = new Contracts.World(), }); definitions.Attach(processor); ThingFactory factory = new ThingFactory(definitions); for (int i = 0; i < 100; i++) { Site city = factory.CreateSite(rdm, 0, 0, "City"); city.FinalizeConstruction(rdm); Console.WriteLine($"City created: {city.EffectiveAttribute("Population")} {city.EffectiveAttribute("Evil")}"); Assert.AreEqual(ThingType.Site, city.ThingType); Assert.AreEqual(cityDef, city.Definition); int population = city.EffectiveAttribute("Population"); Assert.IsTrue(population <= 100000); Assert.IsTrue(population >= 20000); int evil = city.EffectiveAttribute("Evil"); Assert.IsTrue(evil <= 5); Assert.IsTrue(evil >= -5); } }
/// <summary> /// Creates a new instance of the ModelNode adding site model provided. /// If RequireSelfProcessing set as 'true', then site model is going to be processed and pushed by SPMeta2 API. /// </summary> /// <param name="siteDefinition"></param> /// <returns></returns> public static SiteModelNode NewSiteModel(SiteDefinition siteDefinition) { return(NewSiteModel(siteDefinition, null)); }
public void Current_ShouldReturnSiteDefinitionWithIsCurrentPropertySet(SiteDefinitions siteDefinitions, SiteDefinition definition) { definition.IsCurrent = true; siteDefinitions.Sites = new List<SiteDefinition> {definition}; siteDefinitions.Current.ShouldBeEquivalentTo(definition); }
private IEnumerable <UrlDefinition> ProcessSite(Sitecore.Data.Items.Item homeItem, SiteDefinition def, Sitecore.Globalization.Language language) { IProviderSearchContext ctx; if (string.IsNullOrEmpty(this.indexName)) { ctx = ContentSearchManager.GetIndex((SitecoreIndexableItem)homeItem).CreateSearchContext(); } else { ctx = ContentSearchManager.GetIndex(this.indexName).CreateSearchContext(); } try { var results = ctx.GetQueryable <SitemapResultItem>() .Where(i => i.Paths.Contains(homeItem.ID) && i.Language == language.Name); var tmplPred = PredicateBuilder.False <SitemapResultItem>(); foreach (var tmpl in def.IncludedBaseTemplates.Select(i => Sitecore.Data.ID.Parse(i))) { tmplPred = tmplPred.Or(i => i.AllTemplates.Contains(tmpl)); } foreach (var tmpl in def.IncludedTemplates.Select(i => Sitecore.Data.ID.Parse(i))) { tmplPred = tmplPred.Or(i => i.TemplateId == tmpl); } var itemPred = PredicateBuilder.True <SitemapResultItem>(); foreach (var id in def.ExcludedItems.Select(i => Sitecore.Data.ID.Parse(i))) { itemPred = itemPred.And(i => i.ItemId != id); } results = results.Where(tmplPred.And(itemPred)); var items = results .Select(i => Sitecore.Configuration.Factory.GetDatabase(i.DatabaseName).GetItem(i.ItemId, Sitecore.Globalization.Language.Parse(i.Language), Sitecore.Data.Version.Latest)) .ToList(); var sb = new StringBuilder(); var options = Sitecore.Links.UrlOptions.DefaultOptions; options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving; options.Site = SiteContext.GetSite(def.SiteName); if (def.EmbedLanguage) { options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always; } else { options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never; } options.AlwaysIncludeServerUrl = true; options.Language = language; foreach (var item in items) { if (item.Versions.Count > 0) { yield return(new UrlDefinition(Sitecore.Links.LinkManager.GetItemUrl(item, options), item.Statistics.Updated)); } } } finally { ctx.Dispose(); } }
private void Save(SiteDefinition site) { _repository.Save(site); }
public static TModelNode AddSite <TModelNode>(this TModelNode model, SiteDefinition definition, Action <SiteModelNode> action) where TModelNode : ModelNode, ISiteHostModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
public static TModelNode AddSite <TModelNode>(this TModelNode model, SiteDefinition definition) where TModelNode : ModelNode, ISiteHostModelNode, new() { return(AddSite(model, definition, null)); }
public static TModelNode AddHostSite <TModelNode>(this TModelNode model, SiteDefinition definition, Action <SiteModelNode> action) where TModelNode : ModelNode, ISiteHostModelNode, new() { return(model.AddTypedDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing())); }
public ActionResult Create(SetupViewModel model) { Stream siteStream = null; if (model.SiteLocation.Equals("Remote", StringComparison.InvariantCultureIgnoreCase)) { if (model.SiteName.IsNullOrEmpty() || model.SiteName.Equals("0")) { ModelState.AddModelError(nameof(model.SiteName), "Site is required."); return(RedirectToAction("Index")); } var file = StorageService.GetCloudBlockBlob(new Uri(model.SiteName)); if (!file.Exists()) { throw new Exception("Site blob does not exist"); } siteStream = file.OpenRead(); } else { siteStream = model.SiteFile?.FirstOrDefault()?.InputStream; if (siteStream == null) { ModelState.AddModelError(nameof(model.SiteFile), "File is required for local import."); return(RedirectToAction("Index")); } } if (siteStream != null) { var siteDefinition = new SiteDefinition { Name = InstallService.FoundationConfiguration.ApplicationName, SiteUrl = new Uri($"http://{InstallService.FoundationConfiguration.ApplicationName}"), Hosts = new List <HostDefinition>() { new HostDefinition { Name = "*", Type = HostDefinitionType.Undefined } } }; if (!InstallService.FoundationConfiguration.SitePublicDomain.IsNullOrEmpty() && !InstallService.FoundationConfiguration.ApplicationName.Equals(InstallService.FoundationConfiguration.SitePublicDomain)) { siteDefinition.Hosts.Add(new HostDefinition { Name = InstallService.FoundationConfiguration.SitePublicDomain, Type = HostDefinitionType.Primary }); } else { siteDefinition.Hosts.Add(new HostDefinition { Name = InstallService.FoundationConfiguration.ApplicationName, Type = HostDefinitionType.Primary }); } CreateSite(siteStream, siteDefinition, ContentReference.RootPage); } if (model.CatalogLocation.Equals("Remote", StringComparison.InvariantCultureIgnoreCase)) { if (model.CatalogName.IsNullOrEmpty() || model.CatalogName.Equals("0")) { return(Redirect("/")); } var file = StorageService.GetCloudBlockBlob(new Uri(model.CatalogName)); if (!file.Exists()) { throw new Exception("Catalog blob does not exist"); } CreateCatalog(file); } else { if (model.CatalogFile.FirstOrDefault() == null) { return(Redirect("/")); } CreateCatalog(model.CatalogFile.FirstOrDefault()); } var searchManager = new SearchManager(Mediachase.Commerce.Core.AppContext.Current.ApplicationName); searchManager.BuildIndex(true); var config = EPiServer.Find.Configuration.GetConfiguration(); if (!config.ServiceUrl.Equals("https://es-us-api01.episerver.com/9IKGqgMZaTD9KP4Op3ygsVB6JeJzR0N6") && !config.DefaultIndex.Equals("episerverab_index55794")) { RunIndexJob(); } return(Redirect("/")); }
public static ModelNode AddSite(this ModelNode model, SiteDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
public static IAlloySiteSettings Get(this ISiteSettingsRepository repository, SiteDefinition site = null) { return repository.Get<IAlloySiteSettings>(site); }
public ActionResult AddSite(ConfigurationViewModel model) { if (model.SiteName.IsNullOrEmpty()) { model = GetConfigurationViewModel(); ModelState.AddModelError(nameof(model.SelectedSiteName), "Site name is required."); return(View("Index", model)); } if (model.SiteDomainName.IsNullOrEmpty()) { model = GetConfigurationViewModel(); ModelState.AddModelError(nameof(model.SiteDomainName), "Site domain name is required."); return(View("Index", model)); } Stream siteStream = null; if (model.SiteImportLocation.Equals("Remote")) { if (model.SelectedSiteName.IsNullOrEmpty()) { model = GetConfigurationViewModel(); ModelState.AddModelError(nameof(model.SelectedSiteName), "Site is required."); return(View("Index", model)); } var file = StorageService.GetCloudBlockBlob(new Uri(model.SelectedSiteName)); if (!file.Exists()) { throw new Exception("Site blob does not exist"); } siteStream = file.OpenRead(); } else { siteStream = model.SiteImportFile?.FirstOrDefault()?.InputStream; if (siteStream == null) { ModelState.AddModelError(nameof(model.SiteImportFile), "File is required for disk import."); return(View("Index")); } } var domainName = model.SiteDomainName; if (model.SiteDomainName.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)) { domainName = domainName.Replace("http://", ""); } else if (model.SiteDomainName.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) { domainName = domainName.Replace("https://", ""); } var siteDefinition = SiteDefinitionRepository.Get(model.SiteName); if (siteDefinition == null) { siteDefinition = new SiteDefinition { Name = model.SiteName, SiteUrl = new Uri($"http://{domainName}"), Hosts = new List <HostDefinition>() { new HostDefinition { Name = domainName, Type = HostDefinitionType.Undefined } } }; } CreateSite(siteStream, siteDefinition, ContentReference.IsNullOrEmpty(siteDefinition.StartPage) ? ContentReference.RootPage : siteDefinition.StartPage); RunIndexJob(); return(RedirectToAction("Index")); }