Пример #1
0
        private IPacketsStore GetPacketsStore(AcquiredDbParameters acquiredDbParameters, int dbCount)
        {
            // no-lock вариант...
            var oldCachedStores = this.cachedPacketsStores;
            var storeKeyPair    = oldCachedStores.FirstOrDefault(x => x.DbParameters.Equals(acquiredDbParameters));

            if (storeKeyPair != null)
            {
                return(storeKeyPair.Store);
            }
            else
            {
                var newStore        = new MongoDbPacketsStore(new MongoDbParameters(acquiredDbParameters.ConnStringOrUrl, acquiredDbParameters.DatabaseName));
                var newCachedStores = (new CachePair[] { new CachePair
                                                         {
                                                             DbParameters = acquiredDbParameters,
                                                             Store = newStore
                                                         } })
                                      // последние 3 стора
                                      .Union(oldCachedStores.Take(dbCount - 1))
                                      .ToArray();

                this.cachedPacketsStores = newCachedStores;

                return(newStore);
            }
        }
Пример #2
0
 public AcquiredLockServices(AcquiredDbParameters acquiredDbParameters, ILockService lockService, ITimeService timeService, ILeaseLockObject lockObject)
 {
     this.AcquiredDbParameters = acquiredDbParameters;
     this.LockService          = lockService;
     this.TimeService          = timeService;
     this.LockObject           = lockObject;
 }