예제 #1
0
        private void InitializeCache()
        {
            lock (s_dataLock)
            {
                try
                {
                    if (_cache == null)
                    {
                        LegacyProvider.s_onAppDomainUnload = new EventHandler(OnAppDomainUnload);
                        System.Threading.Thread.GetDomain().DomainUnload += LegacyProvider.s_onAppDomainUnload;

                        if (_logs || _detailedLogs)
                        {
                            if (_ncacheLog == null)
                            {
                                _ncacheLog = new NCacheLogger();
                                _ncacheLog.Initialize(LoggerNames.SessionStoreProvider, _cacheId);

                                if (_detailedLogs)
                                {
                                    NCacheLog.SetLevel("all");
                                }
                                else
                                {
                                    if (_logs)
                                    {
                                        NCacheLog.SetLevel("info");
                                    }
                                }
                            }
                        }
                        if (_isLocationAffinityEnabled)
                        {
                            _cache = new RegionalCache(_ncacheLog, NCacheSessionStateConfigReader.LoadSessionLocationSettings());
                        }
                        else
                        {
                            _cache = new SingleRegionCache(_operationRetry, _operationRetryInterval);
                        }

                        _cache.InitializeCache(_cacheId);
                        _cache.ExceptionsEnabled = true;
                        s_cacheNeedInit          = false;
                        if (_logs)
                        {
                            NCacheLog.Info("NSessionStoreProvider initialized");
                        }
                        Thread.Sleep(_inprocDelay);
                    }
                }
                catch (Exception exc)
                {
                    _cache = null; // so that next time cache can be initialized. Check the above condition if(_cache == null)
                    RaiseException(exc);
                }
            }
        }
예제 #2
0
        private void InitializeCache()
        {
            lock (s_dataLock)
            {
                try
                {
                    //if (StaticLogs.IsWriterNull && _logs) StaticLogs.Initialize(_cacheId, "SessionStoreProvider");

                    if (_cache == null)
                    {
                        if (_logs || _detailedLogs)
                        {
                            if (_ncacheLog == null)
                            {
                                string logFileNmae = _cacheId;

                                _ncacheLog = new NCacheLogger();
                                _ncacheLog.Initialize(LoggerNames.SessionStoreProvider, logFileNmae);

                                if (_detailedLogs)
                                {
                                    NCacheLog.SetLevel("all");
                                }
                                else
                                {
                                    if (_logs)
                                    {
                                        NCacheLog.SetLevel("info");
                                    }
                                }
                            }
                        }

                        _cache = new SingleRegionCache(_operationRetry, _operationRetryInterval);

                        _cache.InitializeCache(_cacheId);
                        s_cacheNeedInit = false;
                        OnCacheInitialize();
                        if (_logs)
                        {
                            LogInfo("NSessionStoreProvider initialized", null);
                        }
                        Thread.Sleep(_inprocDelay);
                    }
                }
                catch (Exception exc)
                {
                    _cache = null; //taimoor: so that next time cache can be initialized. Check the above condition if(_cache == null)
                    LogError(exc, null);
                }
            }
        }
예제 #3
0
        private void InitializeCache(HttpApplication application)
        {
            this._cacheId = ConfigurationSettings.AppSettings["cacheName"];
            if (this._cacheId == null || this._cacheId == string.Empty)
            {
                throw new ConfigurationException("The 'cacheName' attribute cannot be null or empty string");
            }

            string[] boolValStrings = { "exceptionsEnabled", "writeExceptionsToEventLog",
                                        "enableLogs",        "enableDetailLogs", "clearASPSession" };
            string   configVal = null;
            bool     value     = false;

            for (int i = 0; i < boolValStrings.Length; i++)
            {
                configVal = ConfigurationSettings.AppSettings[boolValStrings[i]];
                if (configVal != null)
                {
                    if (configVal != "true" && configVal != "false")
                    {
                        throw new ConfigurationException("The '" + boolValStrings[i] + "' attribute must be one of the following values: true, false.");
                    }
                    else
                    {
                        value = Convert.ToBoolean(configVal);
                        switch (i)
                        {
                        case 0: this._exceptionsEnabled = value; break;

                        case 1: this._writeExceptionsToEventLog = value; break;

                        case 2: this._logs = value; break;

                        case 3: this._detailedLogs = value; break;

                        case 4: this._clearASPSession = value; break;
                        }
                    }
                }
            }
            if (this._logs || this._detailedLogs)
            {
                if (_ncacheLog == null)
                {
                    _ncacheLog = new NCacheLogger();
                    _ncacheLog.Initialize(LoggerNames.HttpModule, this._cacheId);

                    if (this._detailedLogs)
                    {
                        NCacheLog.SetLevel("all");
                    }
                    else
                    {
                        if (this._logs)
                        {
                            NCacheLog.SetLevel("info");
                        }
                    }
                }
            }

            _applicationId = ConfigurationSettings.AppSettings["sessionAppId"];

            if (_isLocationAffinityEnabled)
            {
                _cache = new RegionalCache(_ncacheLog, NCacheSessionStateConfigReader.LoadSessionLocationSettings());
            }
            else
            {
                _cache = new SingleRegionCache();
            }

            try
            {
                this._cache.InitializeCache(this._cacheId);
                this._cache.ExceptionsEnabled = true;
                if (NCacheLog != null)
                {
                    NCacheLog.Info("NSessionStateModule initialized");
                }
                application.Application["NSessionStateModule.Cache"] = this._cache;
            }
            catch (Exception e)
            {
                RaiseExceptions(e);
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes a module and prepares it to handle requests.
        /// </summary>
        /// <param name="application">An <see cref="System.Web.HttpApplication"/> object that provides
        /// references to the intrinsic server objects (for example,
        /// Request, Response, Session, and Server) used to service HTTP requests.
        /// </param>
        void IHttpModule.Init(HttpApplication application)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            this._onResolveRequestCache = new EventHandler(ResolveRequestCache);
            this._onUpdaterequestCache  = new EventHandler(UpdateRequestCache);
            this._onDispose             = new EventHandler(Dispose);

            application.ResolveRequestCache += this._onResolveRequestCache;
            application.UpdateRequestCache  += this._onUpdaterequestCache;
            application.Disposed            += this._onDispose;

            if (_reader == null)
            {
                lock (s_mutex)
                {
                    if (_reader == null)
                    {
                        NItem.RegisterTypeWithCompactFramework();
                        _reader   = new OutPutCacheConfigReader();
                        _settings = _reader.LoadCacheSettings();
                        _reader.LoadPageSettings();
                    }
                }
            }

            try
            {
                if (IsNullOrEmpty(_settings.CacheName))
                {
                    return;
                }

                if (_settings.EnableLogs || _settings.EnableDetailedLogs)
                {
                    _ncacheLog = new NCacheLogger();
                    _ncacheLog.Initialize(LoggerNames.OutputCache, _settings.CacheName);

                    if (_settings.EnableDetailedLogs)
                    {
                        NCacheLog.SetLevel("all");
                    }
                    else
                    {
                        if (_settings.EnableLogs)
                        {
                            NCacheLog.SetLevel("info");
                        }
                    }
                }

                lock (s_mutex)
                {
                    this._cache = CacheContainer.GetCacheInstance(_settings);
                }

                if (NCacheLog != null)
                {
                    NCacheLog.Info("NOutputCache initialized");
                }
            }
            catch (Exception e)
            {
                RaiseException(e);
            }
        }
예제 #5
0
        private void InitializeCache()
        {
            lock (s_dataLock)
            {
                try
                {
                    if (_cache == null)
                    {
                        if (_logs || _detailedLogs)
                        {
                            if (_ncacheLog == null)
                            {
                                string logFileNmae = _cacheId;

                                if (_isLocationAffinityEnabled && _regionalCacheSessionStateSettings.PrimaryCache != null)
                                {
                                    foreach (string prefix in _regionalCacheSessionStateSettings.PrimaryCache.Keys)
                                    {
                                        logFileNmae = _regionalCacheSessionStateSettings.PrimaryCache[prefix] as string;
                                        break;
                                    }
                                }

                                _ncacheLog = new NCacheLogger();
                                _ncacheLog.Initialize(LoggerNames.SessionStoreProvider, logFileNmae);

                                if (_detailedLogs)
                                {
                                    NCacheLog.SetLevel("all");
                                }
                                else
                                {
                                    if (_logs)
                                    {
                                        NCacheLog.SetLevel("info");
                                    }
                                }
                            }
                        }
                        if (_isLocationAffinityEnabled)
                        {
                            string sid    = string.Empty;
                            string pcache = string.Empty;

                            if (_regionalCacheSessionStateSettings.PrimaryCache != null)
                            {
                                foreach (string prefix in _regionalCacheSessionStateSettings.PrimaryCache.Keys)
                                {
                                    sid    = prefix;
                                    pcache = _regionalCacheSessionStateSettings.PrimaryCache[prefix] as string;
                                    break;
                                }
                            }

                            if (_logs)
                            {
                                LogInfo("NsessionStoreProvider.Initialize() -> primary cache and sid : " + pcache + " : " + sid, null);
                            }
                            _cache = new RegionalCache(_ncacheLog, _regionalCacheSessionStateSettings);
                        }
                        else
                        {
                            _cache = new SingleRegionCache(_operationRetry, _operationRetryInterval);
                        }

                        _cache.InitializeCache(_cacheId);
                        _cache.ExceptionsEnabled = true;
                        s_cacheNeedInit          = false;
                        OnCacheInitialize();
                        if (_logs)
                        {
                            LogInfo("NSessionStoreProvider initialized", null);
                        }
                        Thread.Sleep(_inprocDelay);
                    }
                }
                catch (Exception exc)
                {
                    _cache = null; // so that next time cache can be initialized. Check the above condition if(_cache == null)
                    LogError(exc, null);
                }
            }
        }