Exemple #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);
        }
Exemple #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadModuleControl loads the ModuleControl (PortalModuelBase)
        /// </summary>
        private void LoadModuleControl()
        {
            try
            {
                if (DisplayContent())
                {
                    //if the module supports caching and caching is enabled for the instance and the user does not have Edit rights or is currently in View mode
                    if (SupportsCaching() && IsViewMode(_moduleConfiguration, PortalSettings) && !IsVersionRequest())
                    {
                        //attempt to load the cached content
                        _isCached = TryLoadCached();
                    }
                    if (!_isCached)
                    {
                        // load the control dynamically
                        _control = ModuleControlFactory.LoadModuleControl(Page, _moduleConfiguration);
                    }
                }
                else //content placeholder
                {
                    _control = ModuleControlFactory.CreateModuleControl(_moduleConfiguration);
                }
                if (Skin != null)
                {
                    //check for IMC
                    Skin.Communicator.LoadCommunicator(_control);
                }

                //add module settings
                ModuleControl.ModuleContext.Configuration = _moduleConfiguration;
            }
            catch (ThreadAbortException exc)
            {
                Logger.Debug(exc);

                Thread.ResetAbort();
            }
            catch (Exception exc)
            {
                Logger.Error(exc);

                //add module settings
                _control = ModuleControlFactory.CreateModuleControl(_moduleConfiguration);
                ModuleControl.ModuleContext.Configuration = _moduleConfiguration;
                if (TabPermissionController.CanAdminPage())
                {
                    //only display the error to page administrators
                    Exceptions.ProcessModuleLoadException(_control, exc);
                }
                else
                {
                    // Otherwise just log the fact that an exception occurred
                    new ExceptionLogController().AddLog(exc);
                }
            }

            //Enable ViewState
            _control.ViewStateMode = ViewStateMode.Enabled;
        }
Exemple #3
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);
        }