public static Website GetWebsite(long versionNumber = 0, Language language = null) { if (language == null) { language = FrameworkSettings.GetCurrentLanguage(); } var key = "GetWebsite?version=" + versionNumber + "&languageId=" + language.ID; var website = ContextHelper.GetFromRequestContext(key); if (website != null) { return((Website)website); } website = WebsitesMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryVersionNumber == versionNumber && i.MediaType.Name == enumName && i.LanguageID == language.ID); if (website == null) { var defaultLanguage = LanguagesMapper.GetDefaultLanguage(); website = WebsitesMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryVersionNumber == versionNumber && i.MediaType.Name == enumName && i.LanguageID == defaultLanguage.ID); } ContextHelper.SetToRequestContext(key, website); return((Website)website); }
public string CalculatedVirtualPath() { var parents = MediaDetailsMapper.GetAllParentMediaDetails(this, LanguagesMapper.GetByID(this.LanguageID)).Reverse(); var virtualPath = ""; foreach (var parent in parents) { if (parent is RootPage || parent is Website) { continue; } virtualPath = StringHelper.CreateSlug(parent.LinkTitle) + "/" + virtualPath; } if (virtualPath == "") { virtualPath = "~/"; } virtualPath = URIHelper.ConvertAbsUrlToTilda(virtualPath); return(virtualPath); }
public void RemoveFromCache() { var htmlCacheKey = GetCacheKey(RenderVersion.HTML); var mobileCacheKey = GetCacheKey(RenderVersion.Mobile); FileCacheHelper.RemoveFromCache(htmlCacheKey); RedisCacheHelper.RemoveFromCache(htmlCacheKey); ContextHelper.RemoveFromCache(htmlCacheKey); RedisCacheHelper.RemoveFromCache(mobileCacheKey); FileCacheHelper.RemoveFromCache(mobileCacheKey); ContextHelper.RemoveFromCache(mobileCacheKey); var language = this.Language; if (language == null && this.LanguageID > 0) { language = LanguagesMapper.GetByID(this.LanguageID); } var parents = MediaDetailsMapper.GetAllParentMediaDetails(this, language).Where(i => i.ID != this.ID); foreach (var item in parents) { item.RemoveFromCache(); } }
public static string LanguageBaseUrl(Language language) { var url = BaseUrl; if (LanguagesMapper.CountAllActive() > 1) { url += language.UriSegment + "/".ToLower(); } return(url); }
public static Settings GetSettings() { /*var settings = (Settings)ContextHelper.GetFromRequestContext("SettingsMapper_GetSettings"); * * if (settings != null) * return settings;*/ /*if (CanConnectToDB is null || !(bool)CanConnectToDB) * return null;*/ var settings = GetDataModel().AllSettings.FirstOrDefault(); if (settings != null && settings.DefaultLanguage == null && settings.DefaultLanguageID > 0) { settings.DefaultLanguage = LanguagesMapper.GetByID(settings.DefaultLanguageID); } //ContextHelper.SetToRequestContext("SettingsMapper_GetSettings", settings); return(settings); }
public static Language GetDefaultLanguage() { var language = ContextHelper.GetFromRequestContext("GetDefaultLanguage"); if (language != null) { return((Language)language); } var settings = SettingsMapper.GetSettings(); language = settings.DefaultLanguage; if (language == null && settings.DefaultLanguageID > 0) { language = LanguagesMapper.GetByID(settings.DefaultLanguageID); } ContextHelper.SetToRequestContext("GetDefaultLanguage", language); return((Language)language); }
public static Language GetCurrentLanguage() { Language language = (Language)ContextHelper.Get(SelectedLanguageKey, ContextType.Session); if (language == null) { language = (Language)ContextHelper.Get(SelectedLanguageKey, ContextType.RequestContext); if (language == null) { language = LanguagesMapper.GetDefaultLanguage(); ContextHelper.Set(SelectedLanguageKey, language, ContextType.RequestContext); } } if ((language != null) && (Thread.CurrentThread.CurrentCulture.Name != language.CultureCode)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(language.CultureCode); } return(language); }
public static bool StartsWithLanguage(string url) { IEnumerable <Language> languages = LanguagesMapper.GetAllActive(); url = ConvertAbsUrlToTilda(url); foreach (Language language in languages) { string url2 = URIHelper.ConvertAbsUrlToTilda(GetBaseUrlWithLanguage(language)); if (url2.EndsWith("/")) { url2 = url2.Remove(url2.Length - 1); } if (url.StartsWith(url2)) { return(true); } } return(false); }