lixiaojun
2024-07-23 ec9bc16c81d897549568d826047da0189b8e85a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace Yw
{
    /// <summary>
    /// 调用入口
    /// </summary>
    public sealed partial class BIMFaceClient
    {
        /// <summary>
        /// 获取BimfaceClient对象
        /// </summary>
        public static BIMFaceClient Instance(string appKey, string appSecret)
        {
            var client = _clients.Find(x => x.AppKey == appKey && x.AppSecret == appSecret);
            if (client == null)
            {
                lock (_locker)
                {
                    client = _clients.Find(x => x.AppKey == appKey && x.AppSecret == appSecret);
                    if (client == null)
                    {
                        client = new BIMFaceClient(appKey, appSecret);
                        _clients.Add(client);
                    }
                }
            }
            return client;
        }
 
        //私有构造函数
        private BIMFaceClient(string AppKey, string AppSecret)
        {
            _appKey = AppKey;
            _appSecret = AppSecret;
        }
 
        /// <summary>
        /// AppKey
        /// </summary>
        public string AppKey { get => _appKey; }
        private string _appKey;
 
        /// <summary>
        /// AppSecret
        /// </summary>
        public string AppSecret { get => _appSecret; }
        private string _appSecret;
 
        private static object _locker = new();//锁对象
        private static List<BIMFaceClient> _clients = new();//client 列表
 
 
    }
 
}