예제 #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Trys to load previously cached Module Content
        /// </summary>
        /// <returns>A Boolean that indicates whether the cahed content was loaded</returns>
        private bool TryLoadCached()
        {
            bool   success       = false;
            string cachedContent = string.Empty;

            try
            {
                var cache  = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod());
                var varyBy = new SortedDictionary <string, string> {
                    { "locale", Thread.CurrentThread.CurrentUICulture.ToString() }
                };

                string cacheKey    = cache.GenerateCacheKey(_moduleConfiguration.TabModuleID, varyBy);
                byte[] cachedBytes = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod()).GetModule(_moduleConfiguration.TabModuleID, cacheKey);

                if (cachedBytes != null && cachedBytes.Length > 0)
                {
                    cachedContent = Encoding.UTF8.GetString(cachedBytes);
                    success       = true;
                }
            }
            catch (Exception ex)
            {
                cachedContent = string.Empty;
                Exceptions.LogException(ex);
                success = false;
            }
            if (success)
            {
                this.RestoreCachedClientResourceRegistrations(cachedContent);
                _control = ModuleControlFactory.CreateCachedControl(cachedContent, _moduleConfiguration);
                Controls.Add(_control);
            }
            return(success);
        }
예제 #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Trys to load previously cached Module Content
        /// </summary>
        /// <returns>A Boolean that indicates whether the cahed content was loaded</returns>
        /// <history>
        ///     [cnurse]	12/15/2007  created
        /// </history>
        /// -----------------------------------------------------------------------------
        private bool TryLoadCached()
        {
            bool   success       = false;
            string cachedContent = string.Empty;

            try
            {
                var cache  = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod());
                var varyBy = new SortedDictionary <string, string> {
                    { "locale", Thread.CurrentThread.CurrentUICulture.ToString() }
                };

                string cacheKey    = cache.GenerateCacheKey(_moduleConfiguration.TabModuleID, varyBy);
                byte[] cachedBytes = ModuleCachingProvider.Instance(_moduleConfiguration.GetEffectiveCacheMethod()).GetModule(_moduleConfiguration.TabModuleID, cacheKey);

                if (cachedBytes != null && cachedBytes.Length > 0)
                {
                    cachedContent = Encoding.UTF8.GetString(cachedBytes);
                    success       = true;
                }
            }
            catch (Exception ex)
            {
                cachedContent = string.Empty;
                Exceptions.LogException(ex);
                success = false;
            }
            if (success)
            {
                //parse the registered CDF from content
                var matches = Regex.Matches(cachedContent, "<\\!--CDF\\((JAVASCRIPT|CSS)\\|(.+?)\\)-->", RegexOptions.IgnoreCase);
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        cachedContent = cachedContent.Replace(match.Value, string.Empty);
                        if (match.Groups[1].Value.ToUpperInvariant() == "JAVASCRIPT")
                        {
                            ClientResourceManager.RegisterScript(Page, match.Groups[2].Value);
                        }
                        else
                        {
                            ClientResourceManager.RegisterStyleSheet(Page, match.Groups[2].Value);
                        }
                    }
                }
                _control = ModuleControlFactory.CreateCachedControl(cachedContent, _moduleConfiguration);
                Controls.Add(_control);
            }
            return(success);
        }