public override ActionResult Index() { var vm = new LanguageSelectorPartViewModel(); if (WebSession.IsInitialized) { var siteRoot = CmsFinder.FindSitePageFromSiteId(WebSession.Current.SiteId); if (siteRoot != null) { vm.Languages = siteRoot.GetChildren <LanguageRoot>().Select(l => new Language { FlagUrl = l.FlagUrl, LanguageCode = l.LanguageCode, LanguageTitle = l.LanguageTitle }).ToList(); } return(PartialView(vm)); } vm.Languages = new List <Language>(); return(PartialView(vm)); }
public ActionResult ForceReplication(string id) { #if false if (string.IsNullOrEmpty(id)) { return(Content( string.Format(ReplicationNoSiteHtml, string.Join(",", CmsFinder.FindAll <StartPage>().Select(s => s.SiteID))), "text/html; charset=UTF-8")); } var startPages = GetSites(id); if (startPages.Count == 0) { return(Content(id + " is not a valid site id")); } var results = new Dictionary <string, int>(); foreach (var startPage in startPages) { var childCount = AdvancePubDateForSite(startPage); results.Add(startPage.SiteID, childCount); } _contentItemRepository.Flush(); var resultTableRows = results.Aggregate(string.Empty, (current, result) => current + string.Format("<tr><td>{0}</td><td class='numcol'>{1}</td></tr>", result.Key, result.Value)); return(Content(string.Format(ReplicationResultsHtml, resultTableRows), "text/html; charset=UTF-8")); #endif return(Content("Done! well, not really")); }
private string GetContentPageTitle() { var contentPageName = ContentPageName; var contentPage = CmsFinder.FindAll <ContentItem>().FirstOrDefault(c => c.Name == contentPageName); return(contentPage == null ? string.Empty : contentPage.Title); }
public string GenerateInterstitialLink() { string ret; var cacheKey = string.Format("{0} {1} {2} {3}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "InterstitialLink", "generic"); if (!_urlCache.TryGet(cacheKey, out ret)) { try { var interstitialPage = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ShoppingCartInterstitialPage>().FirstOrDefault(ip => string.IsNullOrEmpty(ip.ProductID)); if (interstitialPage == null) { ret = null; } else { var url = new Url(GetNormalizedPageUrl(interstitialPage)); ret = url.ToString(); } AddCache(cacheKey, ret); } catch (Exception e) { _logger.Error(e, "Unable to create shopping cart POP interstitial link"); } } return(ret); }
public void FindNonSiteDesc_Pred() { SetupFindNonSiteDesc(); var res = CmsFinder.FindAllNonSiteDescendentsOfRoot <CatalogPage>(c => c.CategoryID.EndsWith("x")); Assert.Equal(1, res.Count); Assert.Equal("3x", res[0].CategoryID); }
public void WrapCF_FindLanguageIntersection_One() { _n2Repository.Add <LanguageIntersection>(l => l.Name = "1"); var res = CmsFinder.FindLanguageIntersection(); Assert.NotNull(res); Assert.Equal("1", res.Name); }
public string GenerateProductLink(long?productId, out object matchingProductPage) { string ret; var cacheKey = string.Format("{0} {1} {2} {3}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "ProductLink", productId); if (!_urlCache.TryGet(cacheKey, out ret)) { try { var prodPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(); if (prodPages.All(pp => !string.IsNullOrEmpty(pp.ProductID))) { // find a product page from the root level that has no product ID var page = CmsFinder.FindAllNonSiteDescendentsOfRoot <ProductPage>() .LastOrDefault(pp => string.IsNullOrEmpty(pp.ProductID)); if (page != null) { prodPages.Add(page); } } var targetProductPage = prodPages.FirstOrDefault( pp => pp.ProductID.Split().Any(pid => pid.Equals(productId.ToString(), StringComparison.InvariantCultureIgnoreCase))) ?? prodPages.LastOrDefault(pp => pp.ProductID.Length == 0); if (targetProductPage == null) { ret = null; } else { var url = new Url(GetNormalizedPageUrl(targetProductPage)); if ((string.IsNullOrEmpty(targetProductPage.ProductID) || targetProductPage.ProductID.Split().Length > 1) && productId != null) { url = url.Append(productId.ToString()); } ret = url.ToString(); } AddCache(cacheKey, ret, targetProductPage); } catch (Exception e) { _logger.Error(e, "Unable to create product link for product {0}", productId); } } _itemCache.TryGet(cacheKey, out matchingProductPage); return(ret); }
public void FindNonSiteDesc() { SetupFindNonSiteDesc(); var res = CmsFinder.FindAllNonSiteDescendentsOfRoot <CatalogPage>(); Assert.Equal(2, res.Count); Assert.Equal("3x", res[0].CategoryID); Assert.Equal("4", res[1].CategoryID); }
public CmsFinderTests() { // to break dependency on user security to satisfy ContentItem.GetChildren and AccessFilter: _securityManager.Setup(s => s.IsAuthorized(It.IsAny <ContentItem>(), It.IsAny <IPrincipal>())).Returns(true); AccessFilter.CurrentSecurityManager = () => _securityManager.Object; // to break dependency on N2 database access, be it NHibernate or XML-file-based CmsFinder.TheFinder = new ContentFinder(_n2Repository); // to break dependency on N2 initializing an engine CmsFinder.SetSessionInfoResolver(_sessionInfoResolver.Object); }
public void FindDescOrFallback_NoCrnt_NoStart() { // no current page // no start page for current site id _n2Repository.Add <ProductPage>( _n2Repository.Add <StartPage>(s => s.SiteID = "s2", _n2Repository.Add <LanguageIntersection>())); _sessionInfoResolver.SetupGet(s => s.SiteId).Returns("s1"); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>((ContentItem)null); Assert.Equal(0, res.Count); }
public void FindDescOrFallback_HaveCrnt_DescOfLangRoot_Pred() { var langRoot = _n2Repository.Add <LanguageRoot>(); _n2Repository.Add <ProductPage>(p => p.ProductID = "2", langRoot); var catPage = _n2Repository.Add <CatalogPage>(langRoot); _n2Repository.Add <ProductPage>(p => p.ProductID = "4x", catPage); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(catPage, p => p.ProductID.EndsWith("x")); Assert.Equal(1, res.Count); Assert.Equal("4x", res[0].ProductID); }
private static string GetDefaultLanguageForSite(string siteId) { var li = CmsFinder.FindLanguageIntersection(); if (li != null) { var site = li.GetChildren <StartPage>() .FirstOrDefault(sp => sp.SiteID.Equals(siteId, StringComparison.InvariantCultureIgnoreCase)); if (site != null) { return(site.LanguageCode); } } return("en-US"); }
private int AdvancePubDateForSite(ContentItem startPage) { var childs = CmsFinder.FindAllDescendentsOf <ContentItem>(startPage); childs.Add(startPage); var childCount = 0; foreach (var child in childs.Where(child => child.IsPublished())) { child.Published = child.Published.HasValue ? child.Published.Value.AddSeconds(1.0) : DateTime.Now; _contentItemRepository.SaveOrUpdate(child); ++childCount; } return(childCount); }
public void WrapCF_FindTranslationsOf() { // we don't really need to test CmsFinder.FindTranslationsOf very thoroughly, // because it's merely a forward to IContentFinder.FindAllDescendentsOf var somePage = _n2Repository.Add <LanguageIntersection>(); _n2Repository.Add <LanguageRoot>(s => s.Name = "1", somePage); _n2Repository.Add <LanguageRoot>(s => s.Name = "2", somePage); var res = CmsFinder.FindTranslationsOf(somePage).ToList(); // just make sure it was a straight pass-thru to IContentFinder Assert.Equal(2, res.Count); Assert.Equal("1", res[0].Name); Assert.Equal("2", res[1].Name); }
public void FindStartPageOf() { var productPage = _n2Repository.Add <ProductPage>( _n2Repository.Add <CatalogPage>( _n2Repository.Add <LanguageRoot>( _n2Repository.Add <StartPage>(s => s.Name = "12345", _n2Repository.Add <LanguageIntersection>( _n2Repository.Add <RootBase>()))))); var result = CmsFinder.FindStartPageOf(productPage); Assert.NotNull(result); result.ShouldBeTypeOf <StartPage>(); Assert.Equal("12345", result.Name); }
public string GenerateFAQLink() { string ret; var cacheKey = string.Format("{0} {1} {2}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "FaqLink"); if (!_urlCache.TryGet(cacheKey, out ret)) { var page = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <FaqPage>().FirstOrDefault(); ret = page == null ? null : new Url(GetNormalizedPageUrl(page)).ToString(); AddCache(cacheKey, ret); } return(ret); }
public void FindDescOrFallback_NoCrnt_NoLangRoot() { // no current page // has start page for current site id // said start page has no language root for current language code _n2Repository.Add <ProductPage>( _n2Repository.Add <LanguageRoot>(l => l.LanguageCode = "lc1", _n2Repository.Add <StartPage>(s => s.SiteID = "s1", _n2Repository.Add <LanguageIntersection>()))); _sessionInfoResolver.SetupGet(s => s.SiteId).Returns("s1"); _sessionInfoResolver.SetupGet(s => s.CultureCode).Returns("lc2"); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>((ContentItem)null); Assert.Equal(0, res.Count); }
public void FindDescOrFallback_HaveCrnt_NoOtherQualDesc() { // current page has no ancestor language root // current page has start page, but start page has no descendent pages of requested type // tree has at least one language intersection, but it has no descendents of requested type not descended from a start page var langInt = _n2Repository.Add <LanguageIntersection>(); var startPage1 = _n2Repository.Add <StartPage>(langInt); _n2Repository.Add <ProductPage>(startPage1); _n2Repository.Add <ProductPage>(startPage1); var catPage2 = _n2Repository.Add <CatalogPage>( _n2Repository.Add <StartPage>(langInt)); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(catPage2); Assert.Equal(0, res.Count); }
public string GenerateShoppingCartLink() { string ret; var cacheKey = string.Format("{0} {1} {2}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "CartLink"); if (_urlCache.TryGet(cacheKey, out ret)) { return(ret); } var cartPage = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ShoppingCartPage>().FirstOrDefault(); ret = GetNormalizedPageUrl(cartPage); AddCache(cacheKey, ret); return(ret); }
public void FindDescOrFallback_HaveCrnt_DescOfLangRoot() { // current page has ancestor language root // said language root has descendent pages of requested type var langRoot = _n2Repository.Add <LanguageRoot>(); _n2Repository.Add <ProductPage>(p => p.Name = "2", langRoot); var catPage = _n2Repository.Add <CatalogPage>(langRoot); _n2Repository.Add <ProductPage>(p => p.Name = "4", catPage); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(catPage); Assert.Equal(2, res.Count); Assert.Equal("2", res[0].Name); Assert.Equal("4", res[1].Name); }
public void FindDescOrFallback_NoCrnt_NoOtherQualDesc() { // no current page // has start page for current site id and language root for current language code // neither said language root nor start page have descendents of requested type // nothing else has any either var langInt = _n2Repository.Add <LanguageIntersection>(); _n2Repository.Add <LanguageRoot>(l => l.LanguageCode = "lc1", _n2Repository.Add <StartPage>(s => s.SiteID = "s1", langInt)); _sessionInfoResolver.SetupGet(s => s.SiteId).Returns("s1"); _sessionInfoResolver.SetupGet(s => s.CultureCode).Returns("lc1"); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>((ContentItem)null); Assert.Equal(0, res.Count); }
public void FindDescOrFallback_NoCrnt_DescOfNonSite_Pred() { var langInt = _n2Repository.Add <LanguageIntersection>(); _n2Repository.Add <LanguageRoot>(l => l.LanguageCode = "lc1", _n2Repository.Add <StartPage>(s => s.SiteID = "s1", langInt)); _n2Repository.Add <ProductPage>(p => p.ProductID = "4", langInt); _n2Repository.Add <ProductPage>(p => p.ProductID = "5x", langInt); _sessionInfoResolver.SetupGet(s => s.SiteId).Returns("s1"); _sessionInfoResolver.SetupGet(s => s.CultureCode).Returns("lc1"); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(null, p => p.ProductID.EndsWith("x")); Assert.Equal(1, res.Count); Assert.Equal("5x", res[0].ProductID); }
public string GenerateSearchLink() { string ret; var cacheKey = string.Format("{0} {1} {2}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "SearchLink"); if (!_urlCache.TryGet(cacheKey, out ret)) { var page = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <SearchPage>().FirstOrDefault() ?? CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <SearchPage>(p => p.Name.Equals("search", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); ret = page == null ? null : GetNormalizedPageUrl(page); AddCache(cacheKey, ret); } return(ret); }
private static IList <StartPage> GetSites(string siteId) { var startPages = new List <StartPage>(); if (string.Compare("all", siteId, StringComparison.OrdinalIgnoreCase) == 0) { startPages.AddRange(CmsFinder.FindAll <StartPage>()); } else { var startPage = CmsFinder.FindSitePageFromSiteId(siteId); if (startPage != null) { startPages.Add(startPage); } } return(startPages); }
//public string GenerateNotFoundLink() //{ // string ret; // var cacheKey = CacheKeyUtils.Get("NotFoundLink"); // if (!_urlCache.TryGet(cacheKey, out ret)) // { // var notFoundPages = FindUtils.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<NotFoundPage>(); // ret = notFoundPages.Any() ? GetNormalizedPageUrl(notFoundPages.First()) : null; // AddCache(cacheKey, ret); // } // return ret; //} //public string GenerateServerErrorLink() //{ // string ret; // var cacheKey = CacheKeyUtils.Get(WebSession.Current.LanguageCode, "ServerErrorLink"); // if (!_urlCache.TryGet(cacheKey, out ret)) // { // var svrerrPages = FindUtils.FindDescendentsOrFallbackOfCurrentPageLanguageRoot<ServerErrorPage>(); // ret = svrerrPages.Any() ? GetNormalizedPageUrl(svrerrPages.First()) : null; // AddCache(cacheKey, ret); // } // return ret; //} public string GenerateLinkForNamedContentItem(string name) { string ret; var cacheKey = string.Format("{0} {1} {2}", WebSession.Current.LanguageCode, "NamedContentItem", name); if (!_urlCache.TryGet(cacheKey, out ret)) { // TODO: Should "store" be configurable? var page = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <PageModelBase>(p => p.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); ret = page == null ? null : GetNormalizedPageUrl(page); AddCache(cacheKey, ret); } return(ret); }
public void FindDescOrFallback_HaveCrnt_DescOfNonSite_Pred() { var langInt = _n2Repository.Add <LanguageIntersection>(); var catPage1 = _n2Repository.Add <CatalogPage>(langInt); _n2Repository.Add <ProductPage>(p => p.ProductID = "3", catPage1); _n2Repository.Add <ProductPage>(p => p.ProductID = "4x", catPage1); _n2Repository.Add <ProductPage>( _n2Repository.Add <StartPage>(langInt)); var catPage2 = _n2Repository.Add <CatalogPage>( _n2Repository.Add <StartPage>(langInt)); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(catPage2, p => p.ProductID.EndsWith("x")); Assert.Equal(1, res.Count); Assert.Equal("4x", res[0].ProductID); }
public override PathData FindPath(string remainingUrl) { var path = base.FindPath(remainingUrl); if (path.IsEmpty() && !(this is LanguageRoot)) { var languageRoot = Find.ClosestOf <LanguageRoot>(this); if (languageRoot != null) { path = languageRoot.FindPath(remainingUrl); } } if (path.IsEmpty() && !(this is StartPage)) { var siteRoot = Find.ClosestOf <StartPage>(this); if (siteRoot != null) { path = siteRoot.FindPath(remainingUrl); } } if (path.IsEmpty() && !(this is LanguageIntersection)) { var languageIntersection = Find.ClosestOf <LanguageIntersection>(this); if (languageIntersection != null) { path = languageIntersection.FindPath(remainingUrl); } } if (path.IsEmpty() && remainingUrl == HttpContext.Current.Request.ApplicationPath) { return(PathDictionary.GetPath(CmsFinder.FindLanguageIntersection(), string.Empty)); } if (path.IsEmpty() && !(this is LanguageIntersection) && !(this is StartPage) && !(this is LanguageRoot)) // { path = base.FindPath("Index" + "/" + remainingUrl); } return(path); }
public string GenerateInterstitialLink(long?productId) { string ret; var cacheKey = string.Format("{0} {1} {2} {3}", WebSession.Current.SiteId, WebSession.Current.LanguageCode, "InterstitialLink", productId); if (!_urlCache.TryGet(cacheKey, out ret)) { try { var interstitialPages = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ShoppingCartInterstitialPage>(); var targetInterstitialPage = interstitialPages.FirstOrDefault( ip => ip.ProductID.Split().Any(pid => pid.Equals(productId.ToString(), StringComparison.InvariantCultureIgnoreCase))); if (targetInterstitialPage == null) { ret = null; } else { var url = new Url(GetNormalizedPageUrl(targetInterstitialPage)); if ((string.IsNullOrEmpty(targetInterstitialPage.ProductID) || targetInterstitialPage.ProductID.Split().Length > 1) && productId != null) { url = url.Append(productId.ToString()); } ret = url.ToString(); } AddCache(cacheKey, ret); } catch (Exception e) { _logger.Error(e, "Unable to create shopping cart interstitial link for product {0}", productId); } } return(ret); }
/// <summary> /// Create links to other translations /// </summary> /// <returns></returns> public static IHtmlString TranslationLinks() { var sb = new StringBuilder(); // TODO could also check for translation of current item foreach (var locale in CmsFinder.FindTranslationsOf(CmsFinder.FindLanguageIntersection()).Where(loc => !string.IsNullOrEmpty(loc.LanguageCode))) { var anchor = new TagBuilder("a"); anchor.MergeAttribute("href", locale.Url); anchor.MergeAttribute("hreflang", string.IsNullOrWhiteSpace(locale.LanguageCode) ? string.Empty : locale.LanguageCode.Substring(0, 2)); // var ci = CultureInfo.CreateSpecificCulture(locale.LanguageCode); //anchor.InnerHtml = ci.DisplayName; anchor.InnerHtml = locale.LanguageTitle; sb.Append(anchor); sb.Append("</br>"); } return(new HtmlString(sb.ToString())); }
public void FindDescOrFallback_HaveCrnt_DescOfNonLang() { // current page has no ancestor language root (condition not tested: current page has language root, but language root has no pages of requested type) // current page has ancestor start page // said start page has descendent pages of requested type // and some of those descendent pages are excluded from the result because they descend from a language root var startPage = _n2Repository.Add <StartPage>(); var catPage = _n2Repository.Add <CatalogPage>(startPage); _n2Repository.Add <ProductPage>(p => p.Name = "3", catPage); _n2Repository.Add <ProductPage>(p => p.Name = "4", catPage); _n2Repository.Add <ProductPage>( _n2Repository.Add <LanguageRoot>(catPage)); var res = CmsFinder.FindDescendentsOrFallbackOfCurrentPageLanguageRoot <ProductPage>(catPage); Assert.Equal(2, res.Count); Assert.Equal("3", res[0].Name); Assert.Equal("4", res[1].Name); }