Exemplo n.º 1
0
        /// <summary>
        /// 获取连接池
        /// </summary>
        /// <param name="type">SQL 客户端处理类型</param>
        /// <param name="connection">连接字符串</param>
        /// <returns></returns>
        internal static ConnectionPool Get(Type type, string connection)
        {
            ConnectionPool pool;
            Key            key = new Key(type, connection);

            if (poolLock.TryGetValueEnter(ref key, out pool))
            {
                return(pool);
            }
            try
            {
                poolLock.SetOnly(ref key, pool = new ConnectionPool());
            }
            finally { Monitor.Exit(poolLock.Lock); }
            return(pool);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 获取 TCP 注册服务客户端
 /// </summary>
 /// <param name="serviceName">服务名称</param>
 /// <param name="Log">日志处理</param>
 /// <returns>TCP注册服务客户端,失败返回null</returns>
 internal static Client Get(string serviceName, ILog Log)
 {
     if (!string.IsNullOrEmpty(serviceName))
     {
         Client     client;
         HashString nameKey = serviceName;
         if (clients.TryGetValueEnter(ref nameKey, out client))
         {
             return(client);
         }
         try
         {
             clients.SetOnly(ref nameKey, client = new Client(serviceName));
         }
         catch (Exception error)
         {
             Log.Add(AutoCSer.Log.LogType.Error, error);
         }
         finally { clients.Exit(); }
         return(client);
     }
     return(null);
 }