internal static IEnhancedOrgService GetConnection(string connectionString, bool noCache = false) { if (noCache) { ResetCache(connectionString); } var memKey = $"{ConnCacheMemKey}_{connectionString}"; lock (lockObj) { try { var service = CacheHelpers.GetFromMemCache <IEnhancedOrgService>(memKey); if (service != null) { return(service); } Status.Update($"Creating connection to CRM ... "); Status.Update($"Connection String:" + $" '{CrmHelpers.SecureConnectionString(connectionString)}'."); service = EnhancedServiceHelper.GetCachingPoolingService( new ServiceParams { ConnectionParams = new ConnectionParams { ConnectionString = connectionString }, PoolParams = new PoolParams { PoolSize = 5, DequeueTimeout = TimeSpan.FromSeconds(20) }, CachingParams = new CachingParams { CacheScope = CacheScope.Service }, OperationHistoryLimit = 1 }); CacheHelpers.AddToMemCache(memKey, service, TimeSpan.MaxValue); Status.Update($"Created connection."); return(service); } catch { CacheHelpers.RemoveFromMemCache(memKey); throw; } } }
private static IEnhancedOrgService ConnectToCrm(string connectionString) { connectionString.Require(nameof(connectionString)); log.Log($"Connecting to '{EscapePassword(connectionString)}' ..."); connectionPool = connectionPool ?? EnhancedServiceHelper.GetPool(connectionString); connectionPool.GetService().Dispose(); log.Log($"Connected!"); return(connectionPool.GetService()); }
protected internal virtual void StartNode() { try { Pool = EnhancedServiceHelper.GetPool(Params); LatencyEvaluatorService = Pool.Factory.CreateCrmService(); LatencyEvaluator.Start(); Started = DateTime.Now; Downtime = TimeSpan.Zero; } catch (Exception ex) { throw new NodeInitException("Failed to start node.", ex, this); } }