CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2022-06-23 9ed0595e0cc3d7e38b182d4b02d59bf73b70d610
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
using System;
using System.Collections.Generic;
using Shared.SimpleControl;
 
namespace Shared
{
    [System.Serializable]
    public class UserConfig
    {
        public static string configFile = "UserConfig";
 
        static UserConfig instance;
        public static UserConfig Instance {
            get {
                if (instance == null) {
                    try {
                        var userConfigBytes = IO.FileUtils.ReadFile (configFile);
                        var userConfigString = CommonPage.MyEncodingUTF8.GetString (userConfigBytes);
                        UserConfig temp = null;
                        if (userConfigString != null) {
                            temp = Newtonsoft.Json.JsonConvert.DeserializeObject<UserConfig> (userConfigString);
                        }
                        if (temp == null) {
                            instance = new UserConfig { };
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Projector);
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.DoorLock);
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.FreshAir);
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Sensor);
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Environmental);
                            instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.MusicModel);
                            //instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.UniversalDevice);
                        } else {
                            instance = temp;
                        }
                    } catch{
                        instance = new UserConfig { };
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Projector);
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.DoorLock);
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.FreshAir);
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Sensor);
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.Environmental);
                        instance.HideDeviceTypes.Add (SimpleControl.R.MyInternationalizationString.MusicModel);
                    }
                }
                return instance;
            }
        }
 
        public int internetStatus = 2;
 
        byte [] GetUserConfigBytes ()
        {
            return CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this));
        }
 
        public void RefreshUserConfig ()
        {
            instance = null;
        }
 
        public void SaveUserConfig ()
        {
            IO.FileUtils.WriteFileByBytes (configFile, GetUserConfigBytes ());
        }
 
        //public void RefeshUserConfig()
        //{
        //}
 
        /// <summary>
        /// 存放不用调光功能的调光设备
        /// </summary>
        public List<string> UnEnableDimmingLight = new List<string> ();
 
        /// <summary>
        /// 插座开关列表
        /// </summary>
        public List<string> SocketList = new List<string> ();
 
        /// <summary>
        /// 手机appID
        /// </summary>
        public string tokenID = string.Empty;
 
        /// <summary>
        /// 手机别名
        /// </summary>
        public string phoneName = string.Empty;
 
        /// <summary>
        /// 用户界面进入时是否显示的是全局场景界面
        /// </summary>
        public bool SceneOfGloba = false;
 
        /// <summary>
        /// 保存远程连接的网络设备文件名
        /// </summary>
        public string RemoteModeFile = string.Empty;
 
        /// <summary>
        /// 是否展开房间灯光列表
        /// </summary>
        public bool ShowRoomLightList = true;
 
        /// <summary>
        /// 是否展开房间窗帘列表
        /// </summary>
        public bool ShowRoomCurtainList = true;
 
        /// <summary>
        /// 隐藏没有场景的房间
        /// </summary>
        public bool HideInvalidRoomScene = false;
 
        public List<int> HideDeviceTypes = new List<int> ();
 
        public Dictionary<string, int> SkinVision = new Dictionary<string, int> ();
        public Dictionary<string, int> DowlaodSkinVision = new Dictionary<string, int> ();
        /// <summary>
        /// 当前使用的皮肤
        /// </summary>
        public string CurrentSkinName {
            get {
                string skinPath = "Phone";
                if (SkinCode == 0) {
                    skinPath = "Phone";
                } else if (SkinCode == 1) {
                    skinPath = "Phone2";
                }
                return skinPath;
            }
        }
 
        public string VersionNumber {
            get { return MainPage.RequestVersion; }
        }
 
        public string TipVersionBackup = string.Empty;
 
        /// <summary>
        /// 安防密码
        /// </summary>
        public string ArmPW = "85521566";
 
 
        /// <summary>
        /// 是否显示场景列表
        /// </summary>
        public bool ShowAlternativeScene = true;
 
        //门锁密码保存
        public Dictionary<string, string> RemoteDoorLockPasswordList = new Dictionary<string, string> ();
 
        //public string CountryCode = "CN";
        /// <summary>
        /// 
        /// </summary>
        public int SkinCode = 1;
        /// <summary>
        /// 住宅列表
        /// </summary>
        public List<RegionInfoRes> HomeLists = new List<RegionInfoRes> ();
        /// <summary>
        /// 当前住宅
        /// </summary>
        RegionInfoRes currentRegion = new RegionInfoRes ();
        public RegionInfoRes CurrentRegion {
            set {
                currentRegion = value;
                //CheckIfNeedGetMasterAccountToken ();
                //切换住宅 设置本地加密Key
                SetLocalEncryptKey ();
                //清空之前网关的信息,重新获取
                HomeGateway = null;
                GetHomeGatewayList ();
                EquipmentPublicClass.upLoadLink = false;
            }
            get {
                if (currentRegion == null) {
                    currentRegion = new RegionInfoRes ();
                }
                return currentRegion;
            }
        }
 
        #region HomeGateway
        /// <summary>
        /// 是否获取中
        /// 2020-01-11 
        /// </summary>
        bool bGettingMac = false;
        //public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
        /// <summary>
        /// 检查是否需要获取控制分享项目(住宅)请求信息
        /// </summary>
        /// <param name="mMainAccountId"></param>
        /// <param name="mSharedHid"></param>
        public void GetHomeGatewayList ()
        {
            //System.Threading.Tasks.Task.Run (() => {
            //if (bGettingMac) return;
            HttpServerRequest.Current.GetHomeGatewayList ();
            //});
        }
        /// <summary>
        /// 网关详细信息
        /// </summary>
        public HomeGatewayInfo HomeGateway;
        /// <summary>
        /// 是否允许远程控制
        /// </summary>
        public bool AllowRemoteControl {
            get {
                if (HomeIsOtherShare) {
                    //等于0是允许远程控制
                    return UserConfig.Instance.CurrentRegion.isRemoteControl;
                } else {
                    //住宅是自己本人的允许控制
                    return true;
                }
            }
        }
 
        /// <summary>
        /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token)
        /// </summary>
        public bool HomeIsOtherShare {
            get {
                if (UserConfig.Instance == null || UserConfig.Instance.CurrentRegion == null) {
                    return false;
                } else {
                    return UserConfig.Instance.CurrentRegion.IsOthreShare;
                }
            }
        }
 
        /// <summary>
        /// 检测住宅是否绑定了网关
        /// gatewayId 判空
        /// </summary>
        /// <returns></returns>
        public bool CheckWhetherGatewayIdNotNull ()
        {
            if (HomeGateway != null && !string.IsNullOrEmpty (HomeGateway.gatewayId)) {
                return true;
            } else {
                return false;
            }
        }
 
        /// <summary>
        /// 检测住宅是否绑定了网关
        /// </summary>
        /// <returns></returns>
        public bool CheckHomeGatewaysNotEmpty ()
        {
            if (HomeGateway != null && !string.IsNullOrEmpty (HomeGateway.mac)) {
                return true;
            } else {
                return false;
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        public string GatewayMAC {
            get {
                if (CheckHomeGatewaysNotEmpty ()) {
                    return HomeGateway.mac;
                } else {
                    return "";
                }
            }
            set {
                if (CheckHomeGatewaysNotEmpty()) {
                    HomeGateway.mac = value;
                } else {
                    //2020-01-11 
                    if (HomeGateway != null) {
                        HomeGateway.mac = value;
                    } else {
                        HomeGateway = new HomeGatewayInfo () { mac = value};
                    }
                }
            }
 
        }
 
        #endregion
 
        ///// <summary>
        ///// 更新设置当前住宅网关
        ///// 2020-01-11 
        ///// </summary>
        ///// <param name="mGatewayDataList"></param>
        //public void SetNowHomeGateways (List<GatewayRes> mGatewayDataList) {
        //    try {
        //        if (currentRegion != null) {
        //            if (mGatewayDataList != null && mGatewayDataList.Count > 0) {
        //                var mMacList = new List<HomeGateways> ();
        //                foreach (var mGatewayRes in mGatewayDataList) {
        //                    var mac = new HomeGateways ();
        //                    mac.GatewayUniqueId = mGatewayRes.GatewayUniqueId;
        //                    mMacList.Add (mac);
        //                }
        //                //HomeGateways = mMacList;
        //            }
        //        }
        //    } catch {
 
        //    }
        //}
 
        //public List<string> RometoUserInfoKeys = new List<string> ();
 
        /// <summary>
        /// 本地通信加密Key
        /// </summary>
        public string LocalEncryptKey = string.Empty;
 
        /// <summary>
        /// 是否加密密码验证通过
        /// </summary>
        public bool EncryptedPasswordCorrect = true;
        /// <summary>
        /// 是否加密
        /// </summary>
        public bool IsLocalEncrypt = false;
        //public bool IsLocalEncrypt {
        //    set {  }
        //    get { return false; }
        //}
        /// <summary>
        /// 设置为默认加密,并计算加密Key
        /// </summary>
        private void SetLocalEncryptKey ()
        {
            if (currentRegion != null) {
                IsLocalEncrypt = true;
                GenerateLocalEncryptionKey ();
                //LocalEncryptKey = CommonPage.MyEncodingUTF8.GetString (GenerateLocalEncryptionKey ());
            }
        }
 
        /// <summary>
        /// 获取16位的key byte []
        /// </summary>
        /// <returns></returns>
        public byte [] GenerateLocalEncryptionKey ()
        {
            byte [] aseKey = new byte [16];
            try {
                //生成加密Key
                byte [] homeId =  System.Text.Encoding.ASCII.GetBytes (currentRegion.Id);
                Array.Copy (homeId, 0, aseKey, 0, 16 < homeId.Length ? 16 : homeId.Length);
                LocalEncryptKey = System.Text.Encoding.ASCII.GetString (aseKey);
                return aseKey;
 
            } catch {
                return aseKey;
            }
 
        }
 
        public string MasterAccountToken = "";
        public string MasterAccountRequestBaseUrl = "";
        /// <summary>
        /// 是否获取中
        /// 2020-01-11 
        /// </summary>
        bool bGetting = false;
        //public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
        /// <summary>
        /// 获取控制分享项目(住宅)请求信息
        /// </summary>
        /// <param name="mMainAccountId"></param>
        /// <param name="mSharedHid"></param>
        public void CheckIfNeedGetMasterAccountToken ()
        {
            if (bGetting) return;
 
            ////2020-01-08 判断是否分享过来的住宅
            //if (currentRegion != null && currentRegion.IsOthreShare) {
            //    //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare;
            //    //请求主账号token
            //    System.Threading.Tasks.Task.Run (() => {
            //        try {
            //            bGetting = true;
            //            var requestObj = new GetSharedHomeApiControlObj () {
            //                LoginAccessToken = MainPage.LoginUser.LoginTokenString,
            //                MainAccountId = currentRegion.MainUserDistributedMark,
            //                SharedHid = currentRegion.Id,
 
            //            };
            //            var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
            //            var revertObj = MainPage.RequestHttps (API.GetSharedHomeApiControl, requestJson);
            //            if (revertObj.StateCode.ToUpper () == StateCode.SUCCESS) {
            //                var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberAdministratorResult> (revertObj.ResponseData.ToString ());
            //                if (responseDataObj != null) {
            //                    MasterAccountToken = responseDataObj.RequestToken;
            //                    MasterAccountRequestBaseUrl = responseDataObj.RequestBaseUrl;
            //                }
            //            }
            //        } catch {
 
            //        } finally {
            //            bGetting = false;
            //        }
            //    });
            //}
        }
 
        }
    }