Пример #1
0
 public ConfirmationCommandHandler(
     IWampHostedRealm realm,
     ISessionCache sessionCache)
 {
     _subject      = realm?.Services.GetSubject(Topic);
     _sessionCache = sessionCache;
 }
Пример #2
0
        public async Task <T> LoadOne <T>(object id, ISessionCache sessionCache, ITrackingProvider tracking)
            where T : class
        {
            var result = await Load <T>(new[] { id }, sessionCache, tracking, new LoadFromDatabaseAction(_couchDb));

            return(result.FirstOrDefault());
        }
        /// <summary>
        /// Fills the system ASP.NET session from NCache.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="cache"></param>
        /// <param name="strict"></param>
        void IDistributionStrategy.FillSessionFromCache(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict)
        {
            try
            {
                string sessionId = session.SessionID;
                if (strict)
                {
                    session.Clear();
                }

                IDictionaryEnumerator i = (IDictionaryEnumerator)cache.GetEnumerator();
                while (i != null && i.MoveNext())
                {
                    SessionKey key = i.Key as SessionKey;
                    if (key != null && key.SessionID == sessionId)
                    {
                        session[key.Key] = i.Value;
                    }
                }
            }
            catch (Exception exc)
            {
                if (strict)
                {
                    session.Clear();
                }
                module.RaiseExceptions(exc, "SingleValueDistribution.FillSessionFromCache");
            }
        }
Пример #4
0
 protected void DisposeCache()
 {
     try
     {
         if (_cache != null)
         {
             lock (s_dataLock)
             {
                 s_cacheNeedInit = true;
                 _cache.Dispose();
                 _cache = null;
             }
         }
         if (_logs)
         {
             LogInfo("Disposed", null);
         }
     }
     catch (Exception exc)
     {
         LogError(exc, null);
     }
     finally
     {
     }
 }
Пример #5
0
        protected virtual async Task <IEnumerable <T> > Load <T>(IEnumerable ids, ISessionCache sessionCache,
                                                                 ITrackingProvider tracking, IAction <IEnumerable <LoadContext> > loadTask) where T : class
        {
            //setup the pipeline
            var pipe = new Middleware <IEnumerable <LoadContext> >();

            pipe.Use(new TrackingAction <LoadContext>(tracking));
            pipe.Use(new SessionAction <LoadContext>(sessionCache));
            pipe.Use(loadTask);

            //setup the load context
            var type         = typeof(T);
            var loadContexts = ids.Cast <object>().Select(id =>
            {
                var idKey = _idManager.GetFromId(type, id);
                return(new LoadContext()
                {
                    Key = idKey,
                    Type = type
                });
            }).ToList();


            await pipe.Execute(loadContexts);

            return(loadContexts.Select(x => x.Entity).Where(x => x != null).Cast <T>());
        }
Пример #6
0
/// <summary>
/// Fills the system ASP.NET session from NCache.
/// </summary>
/// <param name="session"></param>
/// <param name="cache"></param>
/// <param name="strict"></param>

        void IDistributionStrategy.FillSessionFromCache(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict)
        {
            string sessionId = session.SessionID;

            SessionKey key = new SessionKey(sessionId, module.ApplicationId);

            if (strict)
            {
                session.Clear();
            }

            /// save the binary form of data, for comparision on FillCacheFromAspNet()
            _table = (byte[])cache.Get(key.ToString());

            if (_table == null)
            {
                _isNewSession = true;
                return;
            }

            Hashtable ht = (Hashtable)CompactBinaryFormatter.FromByteBuffer(_table, module.CacheID);

            if (ht == null)
            {
                return;
            }

            IDictionaryEnumerator i = ht.GetEnumerator();

            while (i.MoveNext())
            {
                session[i.Key.ToString()] = i.Value;
            }
        }
Пример #7
0
 internal JsUpdateHelper(IBindingLifeCycle bindingLifeCycle, HtmlViewContext context, Lazy <IJavascriptFrameworkMapper> frameworkMapper, ISessionCache sessionCache)
 {
     _Context = context;
     _JavascriptFrameworkMapper = frameworkMapper;
     _SessionCache = sessionCache;
     bindingLifeCycle.OnJavascriptSessionReady += BindingLifeCycleOnJavascriptSessionReady;
 }
Пример #8
0
 public BasicAuthenticationHandler(IOptionsMonitor <AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder urlEncoder, ISystemClock systemClock, ISessionCache sessionCache,
                                   ISessionInfo sessionInfo)
     : base(options, logger, urlEncoder, systemClock)
 {
     _sessionCache = sessionCache;
     _sessionInfo  = sessionInfo;
 }
Пример #9
0
        public virtual async Task Process(ISessionCache sessionCache, ITrackingProvider tracking)
        {
            //var taskCtx = new CreateTaskContext(_couchDb, _idManager, _revisionAccessor, sessionCache);

            //setup the pipeline
            var pipe = new Middleware <IEnumerable <CommitContext> >();

            pipe.Use(new TrackingAction(tracking));
            pipe.Use(new TransactionAction(_transactionCoordinator));
            pipe.Use(new SessionAction(sessionCache));
            pipe.Use(new CommitToDatabaseAction(_couchDb, _revisionAccessor));

            //setup the bulk update context
            var bulkContexts = sessionCache.Entries.Select(entry =>
            {
                var bulkCtx = new CommitContext()
                {
                    ActionType = entry.Action,
                    Entity     = entry.Instance,
                    Key        = entry.Key
                };
                return(bulkCtx);
            });

            await pipe.Execute(bulkContexts);
        }
 public JavascriptObjectBulkBuilderStrategy(IWebView webView, ISessionCache cache, bool mapping)
 {
     _Mapping = mapping;
     _WebView = webView;
     _Cache   = cache;
     _Factory = new Lazy <BulkJsHelper>(FactoryBuilder);
 }
Пример #11
0
        /// <summary>
        /// Fills the system ASP.NET session from NCache.
        /// </summary>
        /// <param name="context">The current http request context</param>
        private void FillAspNetSessionFromNCache(HttpContext context)
        {
            this._isAbandoned = false;
            ISessionCache cache = GetCache(context);

            if (cache == null)
            {
                return;
            }
            if (this._isAlreadyLoaded)
            {
                this._isAlreadyLoaded = false;
                return;
            }

            try
            {
                this._transformer.FillSessionFromCache(cache, this._httpSession, this, this._clearASPSession);
                //Trace("Session: " + _httpSession.Count + "<br>");
            }
            catch (Exception e)
            {
                RaiseExceptions(e, "NSessionStateModule.FillAspNetSessionFromNCache");
            }
        }
Пример #12
0
 public JavascriptObjectSynchroneousBuilder(IJavascriptObjectFactory factory, ISessionCache cache, IJsCsGlue root, bool mapping)
 {
     _Mapping = mapping;
     _Factory = factory;
     _Cache   = cache;
     _Root    = root;
 }
Пример #13
0
 private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs)
 {
     try
     {
         System.Threading.Thread.GetDomain().DomainUnload -= LegacyProvider.s_onAppDomainUnload;
         if (_cache != null)
         {
             lock (s_dataLock)
             {
                 s_cacheNeedInit = true;
                 _cache.Dispose();
                 _cache = null;
             }
         }
         if (_logs)
         {
             NCacheLog.Info(" disposed");
         }
     }
     catch (Exception exc)
     {
         RaiseException(exc);
     }
     finally
     {
     }
 }
Пример #14
0
 public OperationsProjection(
     IWampHostedRealm realm,
     ISessionCache sessionCache)
 {
     _subject      = realm?.Services.GetSubject(Topic);
     _sessionCache = sessionCache;
 }
 public WampSessionAuthenticatorFactory(
     ITokenValidator tokenValidator,
     ISessionCache sessionCache)
 {
     _tokenValidator = tokenValidator;
     _sessionCache   = sessionCache;
 }
Пример #16
0
/// <summary>
/// Fills NCache from the system ASP.NET session.
/// </summary>
/// <param name="cache"></param>
/// <param name="session"></param>
/// <param name="strict"></param>
/// <param name="async"></param>

        void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned)
        {
            string     sessionId = session.SessionID;
            SessionKey key       = new SessionKey(sessionId, module.ApplicationId);

            try
            {
                if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned)
                {
                    return;
                }

                if (/*session.Count == 0 ||*/ isAbandoned)//[Ata]: Session is not removed from store if it is cleared
                {
                    cache.Remove(sessionId, key.ToString(), false);
                    if (module.DetailedLogsEnabled)
                    {
                        NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache");
                    }
                    return;
                }

                //use-case: A session my get emptied while doing different updates... although whien added first time is is not empty
                //So we must update that session rather doing no operation thinking it is empty session and need not to be added.
                if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache. [Asif Imam] April 09, 08
                {
                    return;
                }

                IDictionary ht = new Hashtable();
                foreach (string skey in session.Keys)
                {
                    ht[skey] = session[skey];
                }

                byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID);

                if (_table != null)
                {
                    if (BinaryComparer(_stable, _table))
                    {
                        return;
                    }
                }

                CacheItem sessionItem = new CacheItem(_stable);
                sessionItem.Priority = CacheItemPriority.NotRemovable;

                sessionItem.Expiration = new Runtime.Caching.Expiration(Runtime.Caching.ExpirationType.Sliding, TimeSpan.FromMinutes(session.Timeout));
                cache.Insert(sessionId, key.ToString(), sessionItem, false);
            }
            finally
            {
                if (session != null && strict)
                {
                    session.Clear();
                }
            }
        }
Пример #17
0
 public JavascriptObjectSynchroneousBuilderAdapter(IJavascriptObjectFactory factory, ISessionCache cache, IJsCsGlue @object, bool mapping)
 {
     _Mapping = mapping;
     _Factory = factory;
     _Cache   = cache;
     _Object  = @object;
     _AfterChildrenUpdates = null;
 }
Пример #18
0
 public SipServer(string localAddress, int localPort, int minRtpPort, int maxRtpPort, string dbConnectionString, ISessionCache sessionCache)
     : base(minRtpPort, maxRtpPort)
 {
     _localAddress = localAddress;
     _localPort    = localPort;
     _sessionCache = sessionCache;
     _database     = new Database(dbConnectionString);
 }
Пример #19
0
 public InitializeOperation(
     ISessionCache sessionCache,
     IBalanceUpdatePublisher balanceUpdatePublisher)
     : base("com.init")
 {
     _sessionCache           = sessionCache;
     _balanceUpdatePublisher = balanceUpdatePublisher;
 }
Пример #20
0
 public WampSessionAuthenticatorFactory(
     ITokenValidator tokenValidator,
     ISessionCache sessionCache,
     string realm)
 {
     _tokenValidator = tokenValidator;
     _sessionCache   = sessionCache;
     _realm          = realm;
 }
Пример #21
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);
                }
            }
        }
 public JavascriptObjectBulkBuilder(IJavascriptObjectFactory factory, ISessionCache cache, IBulkUpdater bulkPropertyUpdater,
                                    IJsCsGlue root, bool mapping)
 {
     _Mapping     = mapping;
     _Factory     = factory;
     _Cache       = cache;
     _Root        = root;
     _BulkUpdater = bulkPropertyUpdater;
 }
Пример #23
0
 public RpcFrontend(
     IBalanceUpdatePublisher balanceUpdatePublisher,
     IWalletStatusUpdatePublisher walletStatusUpdatePublisher,
     ISessionCache sessionCache)
 {
     _balanceUpdatePublisher      = balanceUpdatePublisher;
     _walletStatusUpdatePublisher = walletStatusUpdatePublisher;
     _sessionCache = sessionCache;
 }
Пример #24
0
        /// <summary>
        /// Fills NCache from the system ASP.NET session.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="session"></param>
        /// <param name="strict"></param>
        /// <param name="async"></param>
        void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned)
        {
            string     sessionId = session.SessionID;
            SessionKey key       = new SessionKey(sessionId, module.ApplicationId);

            try
            {
                if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned)
                {
                    return;
                }

                if (isAbandoned)// Session is not removed from store if it is cleared
                {
                    cache.Remove(sessionId, key.ToString(), false);
                    if (module.DetailedLogsEnabled)
                    {
                        NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache");
                    }
                    return;
                }

                if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache.
                {
                    return;
                }

                IDictionary ht = new Hashtable();
                foreach (string skey in session.Keys)
                {
                    ht[skey] = session[skey];
                }

                byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID);

                if (_table != null)
                {
                    if (BinaryComparer(_stable, _table))
                    {
                        return;
                    }
                }

                CacheItem sessionItem = new CacheItem(_stable);
                sessionItem.Priority = CacheItemPriority.NotRemovable;

                sessionItem.SlidingExpiration = TimeSpan.FromMinutes(session.Timeout);
                cache.Insert(sessionId, key.ToString(), sessionItem, false);
            }
            finally
            {
                if (session != null && strict)
                {
                    session.Clear();
                }
            }
        }
Пример #25
0
 public HistoryExportProjection(
     ILog log,
     IWampHostedRealm realm,
     ISessionCache sessionCache)
 {
     _log          = log;
     _subject      = realm?.Services.GetSubject(Topic);
     _sessionCache = sessionCache;
 }
Пример #26
0
        public BuildSession(IPipelineGraph pipelineGraph, string requestedName = null, ExplicitArguments args = null)
        {
            _pipelineGraph = pipelineGraph;

            _sessionCache = new SessionCache(this, args);


            RequestedName = requestedName ?? DEFAULT;
        }
Пример #27
0
 public TestApiController(IApplicationCache appCache, ISessionCache sessionCache, IXmlFileManager xmlFileManager, IRequestClient requestClient, ITextFileManager textFileManager, IReportManager reportManager)
 {
     _appCache        = appCache;
     _sessionCache    = sessionCache;
     _xmlFileManager  = xmlFileManager;
     _requestClient   = requestClient;
     _textFileManager = textFileManager;
     _reportManager   = reportManager;
 }
Пример #28
0
 public OrdersPublisher(
     [NotNull] IClientAccountClient clientAccountClient,
     [NotNull] IOrdersConverter ordersConverter,
     [NotNull] ISessionCache sessionCache,
     [NotNull] IWampHostedRealm realm)
 {
     _clientAccountClient = clientAccountClient ?? throw new ArgumentNullException(nameof(clientAccountClient));
     _ordersConverter     = ordersConverter ?? throw new ArgumentNullException(nameof(ordersConverter));
     _sessionCache        = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache));
     _subject             = realm?.Services.GetSubject(Topic) ?? throw new ArgumentNullException(nameof(realm));
 }
Пример #29
0
        private BuildSession(IPipelineGraph pipelineGraph, string requestedName, ExplicitArguments args,
                             Stack <Instance> buildStack)
        {
            this.pipelineGraph = pipelineGraph;

            _sessionCache = new SessionCache(this, args);

            RequestedName = requestedName ?? DEFAULT;

            _instances = buildStack ?? new Stack <Instance>();
        }
        public TicketSessionAuthenticator(
            [NotNull] WampPendingClientDetails details,
            [NotNull] ITokenValidator sessionService,
            [NotNull] ISessionCache sessionCache)
        {
            _details        = details ?? throw new ArgumentNullException(nameof(details));
            _tokenValidator = sessionService ?? throw new ArgumentNullException(nameof(sessionService));
            _sessionCache   = sessionCache ?? throw new ArgumentNullException(nameof(sessionCache));

            AuthenticationId = details.HelloDetails.AuthenticationId;
        }
        public void SetUp()
        {
            authenticationMock = mocks.DynamicMock<IAuthentication>();
            SetupResult.For(authenticationMock.Identifier).Return("johndoe");
            sessionMock = mocks.DynamicMock<ISessionCache>();

            manager = new InternalSecurityManager();
            manager.Users = new IAuthentication[]{
                authenticationMock
            };
            manager.SessionCache = sessionMock;
        }
Пример #32
0
        public static void InitializeDatabase(ISessionCache cache)
        {
            // Will cache the connection if in memory database
            SetupConfiguration(cache);

            // If database config is in memory, connection will be cached in in session state
            var conn = GetConnectionFromSessionState((IConnectionCache)cache);
            if (conn == null) return;

            // Connection has been cache so in memory database
            SetupInMemoryDatabase(cache, conn);
        }
Пример #33
0
        private static void SetupInMemoryDatabase(ISessionCache cache, IDbConnection conn)
        {
            var fact = SessionFactoryManager.GetSessionFactory(cache.GetEnvironment());
            cache.SetSessionFactory(fact);

            UseSessionFactoryFromApplicationOrSessionCache(cache);
            var session = ObjectFactory.GetInstance<ISessionFactory>().OpenSession(conn);

            SessionFactoryManager.BuildSchema(cache.GetEnvironment(), session);
            CurrentSessionContext.Bind(session);

            UserServices.ConfigureSystemUser();
        }
Пример #34
0
        private void InitializeCache()
        {
            lock (s_dataLock)
            {
                try
                {
                    if (_cache == null)
                    {
                        NSessionStoreProvider.s_onAppDomainUnload = new EventHandler(OnAppDomainUnload);
                        System.Threading.Thread.GetDomain().DomainUnload += NSessionStoreProvider.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");
                                }
                            }
                        }

                        _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);
                }
            }
        }
Пример #35
0
 private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs)
 {
     try
     {
         System.Threading.Thread.GetDomain().DomainUnload -= NSessionStoreProvider.s_onAppDomainUnload;
         if (_cache != null)
         {
             lock (s_dataLock)
             {
                 s_cacheNeedInit = true;
                 _cache.Dispose();
                 _cache = null;
             }
         }
         if(_logs) NCacheLog.Info(" disposed");
     }
     catch (Exception exc)
     {      
             RaiseException(exc);
     }
 }
Пример #36
0
 private static void UseSessionFactoryFromApplicationOrSessionCache(ISessionCache cache)
 {
     if (cache.GetSessionFactory() == null)
         ObjectFactory.Configure(
             x =>
             x.For<ISessionFactory>().Use(GenFormApplication.GetSessionFactory(cache.GetEnvironment())));
     else
     {
         ObjectFactory.Configure(
             x =>
             x.For<ISessionFactory>().Use(cache.GetSessionFactory));
     }
 }
Пример #37
0
 private static void SetupConfiguration(ISessionCache cache)
 {
     var environment = cache.GetEnvironment();
     var envConf = ConfigurationManager.Instance.GetConfiguration(environment);
     envConf.GetConnection();
 }
Пример #38
0
 public DatabaseServices(ISessionCache cache)
 {
     _cache = cache;
 }