/// <summary> /// Get body scripts /// </summary> /// <returns>Contents of multi-line text field as a string</returns> public static string GetBodyScripts() { try { if (CacheManagerService.GetObject(Constants.BodyScriptsCacheKey) == null) { var commonScripts = _analyticsService.GetCommonScripts(); if (commonScripts != null) { CacheManagerService.SetObject(Constants.BodyScriptsCacheKey, commonScripts.BodyScripts); return(commonScripts.BodyScripts); } } return(CacheManagerService.GetObject(Constants.BodyScriptsCacheKey).ToString()); } catch (Exception ex) { _logService.Error("Sample.Feature.Analytics -> GetBodyScripts -> Exception Occured", ex); } return(string.Empty); }
/// <summary> /// Get head scripts /// </summary> /// <returns>Contents of multi-line text field as a string</returns> public static string GetHeadScripts() { try { //check if we have this value cached for the current site or not if (CacheManagerService.GetObject(Constants.HeadScriptsCacheKey) == null) { //if it wasn't previously cached and there's a value present, lets set it in cache for next time var commonScripts = _analyticsService.GetCommonScripts(); if (commonScripts != null) { CacheManagerService.SetObject(Constants.HeadScriptsCacheKey, commonScripts.HeadScripts); return(commonScripts.HeadScripts); } } //grab the value from cache for the current site return(CacheManagerService.GetObject(Constants.HeadScriptsCacheKey).ToString()); } catch (Exception ex) { _logService.Error("Sample.Feature.Analytics -> GetHeadScripts -> Exception Occured", ex); } return(string.Empty); }
public override void Process(HttpRequestArgs args) { HttpContext context = HttpContext.Current; if (context == null) { return; } string requestUrl = context.Request.Url.ToString(); if (string.IsNullOrEmpty(requestUrl) || !requestUrl.ToLower().EndsWith("sitemap.xml")) { return; } string siteMapContent = string.Empty; if (Sitecore.Context.Site != null && Sitecore.Context.Database != null) { Item siteTenantItem = SiteExtensions.GetTenantItem(Sitecore.Context.Site); Item homeItem = SiteExtensions.GetStartItem(Sitecore.Context.Site); if (siteTenantItem != null && homeItem != null) { var logService = ServiceLocator.ServiceProvider.GetService <ILogService>(); var glassMapperService = ServiceLocator.ServiceProvider.GetService <IGlassMapperService>(); //grab the base domain to use in each page item var siteMapBaseDomain = siteTenantItem.Fields[Constants.SitemapBaseDomainField].Value; var homeSiteMapItem = glassMapperService.GetItem <ISiteMapItem>(homeItem.Paths.Path); //Cached "per site" string siteCacheKey = string.Format("{0}_{1}", Sitecore.Context.Site.Name, Constants.SitemapContentCacheKey); if (CacheManagerService.GetObject(siteCacheKey) == null) { List <ISiteMapItem> allPageItemsFlattened = new List <ISiteMapItem>(); if (homeSiteMapItem.IncludeInSitemap) { allPageItemsFlattened.Add(homeSiteMapItem); } var flattenedSiteMapItems = GetRecursiveFlattenedSiteMapItems(homeSiteMapItem, allPageItemsFlattened); if (flattenedSiteMapItems != null) { siteMapContent = GenerateSiteMapXML(flattenedSiteMapItems, siteMapBaseDomain, logService, glassMapperService); CacheManagerService.SetObject(siteCacheKey, siteMapContent); } } else { siteMapContent = CacheManagerService.GetObject(siteCacheKey).ToString(); } } } context.Response.ContentType = "text/xml"; context.Response.Write(siteMapContent); context.Response.End(); }