// Token: 0x060010AA RID: 4266 RVA: 0x00032EEC File Offset: 0x000310EC internal RunspaceMediator GetRunspacePooledMediatorInstance(MonadMediatorPoolKey key) { if (key == null) { throw new ArgumentNullException("key"); } if (this.connectionPooledInstace != null) { RunspaceMediator runspaceMediator = null; MonadRunspaceCache result = null; for (int i = 0; i < this.runspaceMediatorSize; i++) { if (key.Equals(this.currentKey[i]) && !this.connectionPooledInstanceCache[i].IsDisposed) { runspaceMediator = this.connectionPooledInstace[i]; result = this.connectionPooledInstanceCache[i]; break; } } if (runspaceMediator != null) { this.CleanUpCache(this.connectionPooledInstanceCache, this.inactivityCacheCleanupThreshold, result); return(runspaceMediator); } } else { lock (this.syncInstance) { if (this.connectionPooledInstace == null) { this.connectionPooledInstace = new RunspaceMediator[this.runspaceMediatorSize]; this.connectionPooledInstanceCache = new MonadRunspaceCache[this.runspaceMediatorSize]; this.currentKey = new MonadMediatorPoolKey[this.runspaceMediatorSize]; } } } RunspaceMediator result2; lock (this.syncInstance) { this.CleanUpCache(this.connectionPooledInstanceCache, this.inactivityCacheCleanupThreshold, null); int num = this.ResolveNextCacheToReplace(); if (this.connectionPooledInstanceCache[num] != null && !this.connectionPooledInstanceCache[num].IsDisposed) { this.connectionPooledInstanceCache[num].Dispose(); } this.connectionPooledInstanceCache[num] = new MonadRunspaceCache(); this.connectionPooledInstace[num] = new RunspaceMediator(new MonadRemoteRunspaceFactory(key.ConnectionInfo, key.ServerSettings), this.connectionPooledInstanceCache[num]); this.currentKey[num] = key; this.lastUpdatedKey = num; result2 = this.connectionPooledInstace[num]; } return(result2); }
// Token: 0x060010AC RID: 4268 RVA: 0x00033114 File Offset: 0x00031314 private void CleanUpCache(MonadRunspaceCache[] connectionPooledInstanceCache, TimeSpan inactivityCacheCleanupThreshold, MonadRunspaceCache result) { if (connectionPooledInstanceCache == null) { return; } if (inactivityCacheCleanupThreshold == TimeSpan.Zero) { return; } for (int i = 0; i < connectionPooledInstanceCache.Length; i++) { if (connectionPooledInstanceCache[i] != null && (result == null || result != connectionPooledInstanceCache[i]) && !connectionPooledInstanceCache[i].IsDisposed) { TimeSpan t = ExDateTime.UtcNow - connectionPooledInstanceCache[i].LastTimeCacheUsed; if (t > inactivityCacheCleanupThreshold) { connectionPooledInstanceCache[i].Dispose(); } } } }