黄学彪
2019-11-20 5174e95a428876018ce3372f3dbc24b2861ea472
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
using System;
using Shared.Common;
using Newtonsoft.Json;
using Shared.Common.ResponseEntity;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 个人中心逻辑类
    /// </summary>
    public class UserCenterLogic
    {
        #region ■ 云端接口访问_______________________
 
        /// <summary>
        /// 访问指定接口,返回是否成功
        /// </summary>
        /// <returns>是否成功</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【false】</pra>
        /// </param>
        public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                {
                    return false;
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return false;
                }
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            //检测是否存在错误信息
            return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
        }
 
        /// <summary>
        /// 访问指定接口,返回状态码(出现异常时,返回 Error)
        /// </summary>
        /// <returns>接口的状态码(出现异常时,返回 Error)</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【Success】</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【ErrorEx】</pra>
        /// </param>
        public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                {
                    return "ErrorEx";
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return "Error";
                }
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            return revertObj.StateCode;
        }
 
        /// <summary>
        /// 访问指定接口,并返回接口把对象已经序列化了的字符串,存在错误信息时,返回null
        /// </summary>
        /// <returns>返回:接口把对象已经序列化了的字符串,存在错误信息时,返回null</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回空字符串</pra>
        /// </param>
        public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
            if (byteData == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                {
                    return string.Empty;
                }
                byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (byteData == null)
                {
                    return null;
                }
            }
            var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
            //检测错误
            bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
            if (notError == false)
            {
                return null;
            }
            if (revertObj == null || revertObj.ResponseData == null)
            {
                return string.Empty;
            }
            return revertObj.ResponseData.ToString();
        }
 
        /// <summary>
        /// 访问指定接口,并直接返回接口返回的比特,存在错误信息时,返回null
        /// </summary>
        /// <returns>返回:并直接返回接口返回的比特,存在错误信息时,返回null</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <param name="listNotShowError">
        /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
        /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回null</pra>
        /// </param>
        public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
            //获取从接口那里取到的比特数据
            var revertObj = await GettByteResponsePack(RequestName, connectMode, obj);
 
            if (revertObj == null)
            {
                if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
                {
                    return null;
                }
                //重新发送
                revertObj = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
                if (revertObj == null)
                {
                    return null;
                }
            }
            if (revertObj != null && revertObj.Length > 0)
            {
                if (revertObj[0] == '{' && revertObj[revertObj.Length - 1] == '}')
                {
                    string data2 = System.Text.Encoding.UTF8.GetString(revertObj);
                    var data = JsonConvert.DeserializeObject<ResponsePack>(data2);
                    if (data != null && string.IsNullOrEmpty(data.StateCode) == false)
                    {
                        bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError, obj);
                        if (notError == false)
                        {
                            return null;
                        }
                    }
                }
            }
            return revertObj;
        }
 
        /// <summary>
        /// 私有类型:从新发送(懂的人自然懂,很难解释清楚)
        /// </summary>
        /// <param name="RequestName">访问地址</param>
        /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
        /// <param name="obj">一个类</param>
        /// <returns></returns>
        private static async Task<byte[]> ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
        {
            //获取接口的连接模式
            var connectMode = GetHttpConnectMode(checkAuthority);
 
            byte[] responsePack = null;
            int count = 0;
            while (true)
            {
                await Task.Delay(1000);
                //调用接口
                responsePack = await GettByteResponsePack(RequestName, connectMode, obj);
                if (responsePack != null)
                {
                    break;
                }
                count++;
                if (count == 3)
                {
                    Application.RunOnMainThread(() =>
                    {
                        //网络不稳定,请稍后再试
                        string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
                        var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                        control.Show();
                    });
                    break;
                }
            }
            return responsePack;
        }
 
        /// <summary>
        /// 获取从接口那里取到的内容
        /// </summary>
        /// <returns>获取从接口那里取到的文本内容</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="connectMode">接口的连接模式</param>
        /// <param name="obj">一个类</param>
        private static async Task<byte[]> GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
        {
            try
            {
                //序列化对象
                var requestJson = JsonConvert.SerializeObject(obj);
                //访问接口
                byte[] result = null;
                if (connectMode == HttpConnectMode.Normal)
                {
                    //普通访问
                    result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
                }
                else if (connectMode == HttpConnectMode.Admin)
                {
                    //以管理员的身份访问,自身是成员
                    result = await CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
                }
                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
 
        /// <summary>
        /// 检测是否存在错误信息,并显示错误
        /// </summary>
        /// <returns>是否存在错误信息</returns>
        /// <param name="revertObj">从接口接收到的数据</param>
        /// <param name="RequestName">请求接口</param>
        /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别)</param>
        /// <param name="pra">请求的参数</param>
        public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null, object pra = null)
        {
            if (revertObj == null)
            {
                Application.RunOnMainThread(() =>
                {
                    //网络不稳定,请稍后再试
                    string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
                    var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                    control.Show();
                });
 
                return false;
            }
            if (revertObj.StateCode.ToUpper() != "SUCCESS")
            {
                if (listNotShowError != null && listNotShowError.Contains(revertObj.StateCode) == true)
                {
                    //不显示错误,然后返回true
                    return true;
                }
                Application.RunOnMainThread(() =>
                {
                    if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
                    {
                        //如果用户已经退出了登陆,则不处理
                        return;
                    }
                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
                    if (msg != null)
                    {
                        var control = new ShowMsgControl(ShowMsgType.Tip, msg);
                        control.Show();
 
                        //无效登录Token
                        if (revertObj.StateCode == "NoLogin")
                        {
                            UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
                        }
                    }
                });
 
                return false;
            }
            return true;
        }
 
        /// <summary>
        /// 获取接口的连接模式
        /// </summary>
        /// <param name="checkAuthority">是否检测权限</param>
        /// <returns></returns>
        public static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
        {
            if (checkAuthority == false)
            {
                return HttpConnectMode.Normal;
            }
            if (Config.Instance.isAdministrator == true)
            {
                return HttpConnectMode.Admin;
            }
            return HttpConnectMode.Normal;
        }
 
        #endregion
 
        #region ■ 添加界面相关_______________________
 
        /// <summary>
        /// 检测能否添加画面
        /// </summary>
        /// <returns>true:可以追加 false:不可追加</returns>
        /// <param name="form">Form</param>
        public static bool CheckCanAddForm(CommonFormBase form)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
 
            //二重追加不可
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
            {
                return true;
            }
            //暂时这样弄看看,如果重复,则关闭掉原来的界面
            var formTemp = UserCenterResourse.DicActionForm[formName];
            formTemp.CloseForm();
            UserCenterResourse.DicActionForm.Remove(formName);
            formTemp = null;
 
            return true;
        }
 
        /// <summary>
        /// 把打开的画面添加到内存中
        /// </summary>
        /// <param name="form">Form.</param>
        public static void AddActionForm(CommonFormBase form)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
 
            //二重追加不可
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
            {
                form.FormID = formName;
                //内存添加
                UserCenterResourse.DicActionForm[formName] = form;
                //添加画面时,它自身就是激活的界面
                UserCenterResourse.NowActionFormID = form.FormID;
 
                UserCenterResourse.listActionFormId.Add(form.FormID);
            }
        }
 
        /// <summary>
        /// 从列表中移除画面
        /// </summary>
        /// <param name="form">Form</param>
        public static void RemoveActionForm(CommonFormBase form)
        {
            //获取画面英文名字
            string formName = GetFormName(form);
 
            if (UserCenterResourse.DicActionForm.ContainsKey(formName) == true)
            {
                //刷新当前正在操作的画面ID
                if (UserCenterResourse.NowActionFormID == UserCenterResourse.DicActionForm[formName].FormID)
                {
                    //向前推一位即为下一个激活的界面
                    int index = UserCenterResourse.listActionFormId.IndexOf(UserCenterResourse.NowActionFormID) - 1;
                    //初始值
                    UserCenterResourse.NowActionFormID = string.Empty;
                    if (index >= 0)
                    {
                        var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
                        if (actionForm != null && actionForm is CommonFormBase)
                        {
                            //设置当前激活的画面ID
                            UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                            //追加条件一:关闭的界面为EditorCommonForm的时候才处理
                            if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                            {
                                try
                                {
                                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                    if (Myform is EditorCommonForm)
                                    {
                                        //触发界面再次激活的事件
                                        int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
                                        if (value == 1)
                                        {
                                            //Log出力
                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    //出现未知错误,数据丢失
                                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
                                    alert.Show();
 
                                    //Log出力
                                    HdlLogLogic.Current.WriteLog(ex);
                                }
                            }
                        }
                        else if (actionForm != null && actionForm is UserView.UserPage)
                        {
                            //这里它已经退到主页了,如果它包含个人中心主页的话
                            if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == true)
                            {
                                //设置当前激活的画面ID
                                UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                                //追加条件一:关闭的界面为EditorCommonForm的时候才处理
                                if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                                {
                                    try
                                    {
                                        var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                        if (Myform is EditorCommonForm)
                                        {
                                            //触发界面再次激活的事件
                                            int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
                                            if (value == 1)
                                            {
                                                //Log出力
                                                HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        //出现未知错误,数据丢失
                                        var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
                                        alert.Show();
 
                                        //Log出力
                                        HdlLogLogic.Current.WriteLog(ex);
                                    }
                                }
                            }
                        }
                    }
                }
                //移除ID
                UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
                //移除画面
                var formTemp = UserCenterResourse.DicActionForm[formName];
                UserCenterResourse.DicActionForm.Remove(formName);
                formTemp = null;
            }
        }
 
        /// <summary>
        /// 获取画面英文名字
        /// </summary>
        /// <returns>The form name.</returns>
        /// <param name="form">Form.</param>
        public static string GetFormName(CommonFormBase form)
        {
            if (form.FormID != string.Empty)
            {
                return form.FormID;
            }
            //将命名空间去掉
            string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
            string formName = Arry[Arry.Length - 1].Trim();
            return formName;
        }
 
        /// <summary>
        /// 获取当前正在激活的画面
        /// </summary>
        /// <returns></returns>
        public static CommonFormBase GetNowActionForm()
        {
            if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
            {
                return UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
            }
            return null;
        }
 
        #endregion
 
        #region ■ 刷新本地缓存_______________________
        /// <summary>
        /// 刷新本地所有缓存
        /// </summary>
        public static void RefreshAllMemory()
        {
            //备份的数据,有可能是主人自己上传的,如果管理员登陆时,他获取的备份数据有点特殊
            //比如下面这三个东西在主账号那里是不需要的
            bool isOthreShare = Config.Instance.Home.IsOthreShare;
            int accountType = Config.Instance.Home.AccountType;
            string mainMark = Config.Instance.Home.MainUserDistributedMark;
            //还原住宅对象
            Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
            Config.Instance.Home.IsOthreShare = isOthreShare;
            Config.Instance.Home.AccountType = accountType;
            Config.Instance.Home.MainUserDistributedMark = mainMark;
            Config.Instance.Home.Save();
 
            //刷新本地网关文件
            HdlGatewayLogic.Current.ReFreshByLocal();
            //刷新本地设备
            Common.LocalDevice.Current.ReFreshByLocal();
            //需优先于刷新房间,同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
            HdlGatewayLogic.Current.SynchronizeDbGateway();
            //从本地重新加载全部的房间
            Common.Room.RefreshAllRoomByLocation();
        }
 
        #endregion
 
        #region ■ 删除本地文件_______________________
 
        /// <summary>
        /// 删除本地所有文件
        /// </summary>
        /// <param name="all">true:全部删除(用于住宅删除) false:重要的文件不删除</param>
        public static void DeleteAllLocationFile(bool all = true)
        {
            string dPath = Config.Instance.FullPath;
            if (System.IO.Directory.Exists(dPath) == false)
            {
                return;
            }
 
            //然后获取全部的文件
            List<string> listFile = Global.FileListByHomeId();
            foreach (string file in listFile)
            {
                if (all == false && IsNotDeleteFile(file) == true)
                {
                    //这是不能删除的文件
                    continue;
                }
                //删除文件
                Global.DeleteFilebyHomeId(file);
            }
            //如果是把文件全部删除的话,那么文件夹也一起删除掉
            if (all == true)
            {
                //删除文件夹
                System.IO.Directory.Delete(dPath, true);
            }
        }
 
        /// <summary>
        /// 判断是不是不应该删除的文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool IsNotDeleteFile(string fileName)
        {
            if (fileName == "Config.json")
            {
                //不能删除Config文件
                return true;
            }
            else if (fileName.StartsWith("House_") == true)
            {
                //不能删除住宅文件
                return true;
            }
            return false;
        }
 
        #endregion
 
        #region ■ 重新登录___________________________
 
        /// <summary>
        /// 重新登录
        /// </summary>
        /// <param name="account">账号</param>
        /// <param name="noticeDb">是否通知云端</param>
        public static void ReLoginAgain(string account = "", bool noticeDb = true)
        {
            UserCenterResourse.Option.OldAccountId = string.Empty;
            //关闭所有接收
            HdlDeviceAttributeLogic.Current.RemoveAllEvent();
            //清除升级列表
            FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
            FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
 
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //检测APP是否能够退出
                while (UserCenterResourse.Option.AppCanSignout == false)
                {
                    await Task.Delay(500);
                }
                //设定一个时间
                Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
                Config.Instance.Save();
 
                //清空当前住宅id
                Shared.Common.Config.Instance.HomeId = string.Empty;
                HdlGatewayLogic.Current.ClearAllRealGateway();
               
 
                if (noticeDb == true)
                {
                    //通知云端,已经退出登陆
                    var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //关闭所有打开了的界面
                    CloseAllOpenForm();
 
                    //显示登陆画面
                    var formLogin = new Shared.Phone.Device.Account.AccountLogin();
                    Shared.Common.CommonPage.Instance.AddChidren(formLogin);
                    formLogin.Show(account);
                });
            });
        }
 
        /// <summary>
        /// 关闭所有打开了的界面
        /// </summary>
        public static void CloseAllOpenForm()
        {
            var listForm = new List<CommonFormBase>();
            var listId = new List<string>();
            foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
            {
                if (form.FormID != "UserMainForm")
                {
                    listForm.Insert(0, form);
                    listId.Add(form.FormID);
                }
            }
            foreach (var id in listId)
            {
                UserCenterResourse.DicActionForm.Remove(id);
            }
 
            //关闭所有画面
            foreach (CommonFormBase form in listForm)
            {
                form.CloseForm();
            }
            listForm.Clear();
        }
 
        #endregion
 
        #region ■ 子控件的Y轴坐标____________________
 
        /// <summary>
        /// 指定位置类型获取Rowlayout的子控件的Y轴坐标(请确保子控件不大于父容器)
        /// </summary>
        /// <param name="fatherCtrHeight">父控件的真实高度</param>
        /// <param name="ctrHeight">子控件的真实高度</param>
        /// <param name="alignment">位置对齐方式</param>
        /// <param name="Space">上下间的空白间距,省略时,取行控件共通变量的值。设置为-1时,不计算空白间距</param>
        /// <returns></returns>
        public static int GetControlChidrenYaxis(int fatherCtrHeight, int ctrHeight, UViewAlignment alignment, int Space = 0)
        {
            if (Space < 0)
            {
                //不计算间距值
                Space = 0;
            }
 
            if (alignment == UViewAlignment.Center)
            {
                return fatherCtrHeight / 2 - ctrHeight / 2;
            }
            else if (alignment == UViewAlignment.Top)
            {
                return (fatherCtrHeight / 2 - Space / 2) / 2 - ctrHeight / 2;
            }
            else
            {
                int top = fatherCtrHeight / 2 + Space / 2;
                return top + (fatherCtrHeight - top) / 2 - ctrHeight / 2;
            }
        }
 
        #endregion
 
        #region ■ 拼接信息___________________________
 
        /// <summary>
        /// 拼接路径(全路径),以住宅ID的文件夹为起点,当没有指定参数时,则返回【住宅ID的文件夹】的全路径
        /// </summary>
        /// <param name="listNames">要拼接的路径</param>
        /// <returns></returns>
        public static string CombinePath(params object[] listNames)
        {
            string rootPath = Config.Instance.FullPath;
            if (listNames == null || listNames.Length == 0)
            {
                return rootPath;
            }
            foreach (var file in listNames)
            {
                if (file == null)
                {
                    continue;
                }
                rootPath = System.IO.Path.Combine(rootPath, file.ToString());
            }
            return rootPath;
        }
 
        /// <summary>
        /// 拼接网关回复超时的信息
        /// </summary>
        /// <param name="errorMsg">错误信息</param>
        /// <param name="resultData">网关返回的resultData,里面有【errorMessageBase】这个东西的那种对象</param>
        /// <param name="strResultData">网关返回的resultData,里面的【errorMessageBase】的值,设定有此值时,resultData无效</param>
        /// <param name="addBrackets">是否添加括号</param>
        /// <returns></returns>
        public static string CombineGatewayTimeOutMsg(string errorMsg, object resultData, string strResultData = null, bool addBrackets = true)
        {
            if (resultData == null && strResultData == null)
            {
                return errorMsg;
            }
 
            string errorMsgBase = strResultData;
            if (errorMsgBase == null)
            {
                Type myType = resultData.GetType();
                object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null);
                if (errorObj == null)
                {
                    return errorMsg;
                }
                errorMsgBase = errorObj.ToString();
            }
 
            if (errorMsgBase.Contains("回复超时") == false)
            {
                //只有回复超时的时候才会加上
                return errorMsg;
            }
            errorMsg += "\r\n";
            if (addBrackets == true)
            {
                //(网关回复超时,请稍后再试)
                return errorMsg + "(" + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut) + ")";
            }
            else
            {
                //网关回复超时,请稍后再试
                return errorMsg + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
            }
        }
 
        #endregion
 
        #region ■ 刷新个人中心的内存及线程___________
 
        /// <summary>
        /// 异步方法执行(仅限切换住宅时调用),刷新个人中心的内存及线程
        /// </summary>
        public async static Task<bool> InitUserCenterMenmoryAndThread()
        {
            //APP缓存加载开始
            UserCenterResourse.Option.AppCanSignout = false;
 
            //强制指定不关闭进度条
            ProgressBar.SetCloseBarFlag(true);
 
            //只有在住宅ID不一样的时候才做这个操作
            if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
                || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
            {
                //加载账号配置信息
                var optionInfo = UserCenterResourse.Option.Load();
                UserCenterResourse.Option = optionInfo;
                //变更根用户图片目录路径
                UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
 
                //初始化登陆账号的信息
                await InitUserAccoutInfo();
                //初始化管理员权限信息
                await InitAdminConnectMqttInfo(true);
 
                //初始化缓存成员的信息
                InitLocalMemberListInfo();
 
                //重新发送命令去绑定断网情况下备份的网关
                HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
 
                //预创建个人中心全部的文件夹
                CreatAllUserCenterDirectory();
 
                //关闭所有接收
                HdlDeviceAttributeLogic.Current.RemoveAllEvent();
                //刷新安防上报信息
                HdlAlarmsLogic.Current.RefreshAlarmInfo();
                //添加保存安防设备报警的事件(不需要再执行任何操作,并且永久存在)
                HdlAlarmsLogic.Current.AddAlarmInfoEvent();
 
                //保存用户的登陆信息到本地
                SaveUserInformationToLocation();
 
                UserCenterResourse.Option.OldHomeStringId = Common.Config.Instance.HomeId;
                UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
 
                //同步数据(二次调用没关系)
                var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
 
                //初始化本地的网关信息
                HdlGatewayLogic.Current.ReFreshByLocal();
                //初始化本地的设备信息
                Common.LocalDevice.Current.ReFreshByLocal();
 
                //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
                HdlGatewayLogic.Current.SynchronizeDbGateway();
 
                //初始化住宅对象
                Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
 
                //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
                Room.RefreshAllRoomByLocation();
 
                //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
                HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
 
                //清空强制指定文本的附加信息
                ProgressBar.SetAppendText(string.Empty);
 
                //0:已经同步过,不需要同步,这个时候需要提示备份
                //if (result == 0)
                //{
                //    //开启自动备份提示
                //    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
                //}
            }
 
            //恢复可关闭进度条
            ProgressBar.SetCloseBarFlag(false);
            //APP缓存加载完成
            UserCenterResourse.Option.AppCanSignout = true;
 
            return true;
        }
 
        #endregion
 
        #region ■ 初始化登陆账号的信息_______________
 
        /// <summary>
        /// 初始化登陆账号的信息
        /// </summary>
        /// <returns></returns>
        private async static Task<bool> InitUserAccoutInfo()
        {
            //获取本地记录的用户信息
            UserCenterResourse.UserInfo = GetUserInformationFromLocation();
            UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
 
            //获取登录账号的信息
            var pra = new AccountInfoPra();
            var listNotShow = new List<string>() { "NotSetAgain" };
            string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetAccountInfo", false, pra, listNotShow);
            if (string.IsNullOrEmpty(result) == true)
            {
                //断网的话,该干嘛就干嘛吧,总之不能控主人的东西
                Config.Instance.isAdministrator = false;
                return false;
            }
 
            var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(result);
            userInfo.Account = Common.Config.Instance.Account;
            if (string.IsNullOrEmpty(userInfo.UserName) == true)
            {
                //没有昵称的时候,把账号作为昵称
                userInfo.UserName = Common.Config.Instance.Account;
            }
 
            if (Common.Config.Instance.Home.IsOthreShare == false)
            {
                //身份:管理员
                userInfo.AuthorityNo = 1;
                userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.Administrator);
            }
            else if (Common.Config.Instance.Home.AccountType == 1)
            {
                //身份:成员(拥有管理员权限)
                userInfo.AuthorityNo = 2;
                userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMemberHadActionAuthority);
            }
            else
            {
                //身份:成员
                userInfo.AuthorityNo = 3;
                userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMember);
            }
 
            if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo)
            {
                //如果登陆的账号的权限和上一次的不一样,则删除本地这个住宅全部的文件,从头再来
                string dirPath = CombinePath();
                if (System.IO.Directory.Exists(dirPath) == true)
                {
                    //先记录起住宅的一些信息
                    var house = House.GetHouseByHouseId(Config.Instance.HomeId);
                    //删除整个文件夹
                    System.IO.Directory.Delete(dirPath, true);
                    //创建住宅文件夹
                    Global.CreateHomeDirectory(Config.Instance.HomeId);
                    //预创建个人中心全部的文件夹
                    CreatAllUserCenterDirectory();
 
                    var newHouse = new House();
                    newHouse.Id = house.Id;
                    newHouse.Name = house.Name;
                    newHouse.IsOthreShare = house.IsOthreShare;
                    newHouse.AccountType = house.AccountType;
                    newHouse.MainUserDistributedMark = house.MainUserDistributedMark;
                    newHouse.Save();
                }
            }
            if (string.IsNullOrEmpty(userInfo.UserName) == true)
            {
                //没有昵称的话,把账号丢过去
                userInfo.UserName = userInfo.Account;
            }
 
            UserCenterResourse.UserInfo = userInfo;
            UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
            if (UserCenterResourse.UserInfo.HeadImage != null)
            {
                //写入头像内容
                Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
            }
            UserCenterResourse.UserInfo.HeadImage = null;
            //手势密码
            UserCenterResourse.Option.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd;
            UserCenterResourse.UserInfo.GesturePwd = null;
            //密码验证
            UserCenterResourse.Option.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
            UserCenterResourse.UserInfo.StringPwd = null;
 
            //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
            await InitAdminConnectMainInfo();
 
            return true;
        }
 
        /// <summary>
        /// 从本地获取用户的登陆信息
        /// </summary>
        /// <returns></returns>
        private static UserInformation GetUserInformationFromLocation()
        {
            string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            var value = LoadFileContent(fileName);
            if (value == null)
            {
                return new UserInformation();
            }
            var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
            return info;
        }
 
        /// <summary>
        /// 保存用户的登陆信息到本地
        /// </summary>
        private static void SaveUserInformationToLocation()
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
            //写入内容
            SaveFileContent(fullName, UserCenterResourse.UserInfo);
 
            //搞一下主人的默认头像
            string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png");
            if (defultFile == string.Empty)
            {
                return;
            }
            if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
            {
                return;
            }
            //复制过去
            System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile);
        }
 
        #endregion
 
        #region ■ 初始化管理员权限远程连接___________
 
        /// <summary>
        /// 初始化管理员权限远程连接主人的信息
        /// </summary>
        /// <returns></returns>
        public static async Task<bool> InitAdminConnectMainInfo()
        {
            //先清空
            Config.Instance.isAdministrator = false;
            Config.Instance.AdminRequestBaseUrl = string.Empty;
            Config.Instance.AdminRequestToken = string.Empty;
 
            if (UserCenterResourse.UserInfo.AuthorityNo != 2)
            {
                //拥有管理员权限的成员才能这样搞,  这里必须是2
                return true;
            }
            var pra = new
            {
                CommonPage.RequestVersion,
                LoginAccessToken = Config.Instance.Token,
                MainAccountId = Config.Instance.Home.MainUserDistributedMark,
                SharedHid = Config.Instance.Home.Id
            };
 
            var listNotShow = new List<string>() { "NotSetAgain" };
            var result = await GetResponseDataByRequestHttps("App/GetSharedHomeApiControl", false, pra, listNotShow);
            if (string.IsNullOrEmpty(result) == true)
            {
                return false;
            }
 
            Config.Instance.isAdministrator = true;
            //分享链接
            var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
            Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
            Config.Instance.AdminRequestToken = info.RequestToken;
 
            return true;
        }
 
        /// <summary>
        /// 初始化管理员权限的远程连接信息
        /// </summary>
        /// <param name="stopRemote">是否中断远程</param>
        /// <returns></returns>
        public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //只有成员分身才能调用这个函数
                return true;
            }
            var praMqtt = new
            {
                CommonPage.RequestVersion,
                LoginAccessToken = Config.Instance.Token,
                Config.Instance.Home.MainUserDistributedMark,
                HomeId = Config.Instance.Home.Id
            };
 
            var listNotShow = new List<string>() { "NotSetAgain" };
            var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
            if (string.IsNullOrEmpty(result2) == true)
            {
                return false;
            }
 
            //远程Mqtt
            var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
            Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
            Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
            Config.Instance.AdminMqttKey = info2.MqttKey;
            Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
            Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
 
            return true;
        }
 
        #endregion
 
        #region ■ 初始化缓存成员的信息_______________
 
        /// <summary>
        /// 初始化缓存成员的信息
        /// </summary>
        private static void InitLocalMemberListInfo()
        {
            //先清空
            UserCenterResourse.ListMemberInfo.Clear();
            string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
            if (System.IO.File.Exists(fileName) == false)
            {
                return;
            }
            var varByte = Shared.IO.FileUtils.ReadFile(fileName);
            UserCenterResourse.ListMemberInfo = JsonConvert.DeserializeObject<List<MemberInfoRes>>(System.Text.Encoding.UTF8.GetString(varByte));
        }
 
        /// <summary>
        /// 保存缓存成员的信息
        /// </summary>
        public static void SaveLocalMemberListInfo()
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(UserCenterResourse.ListMemberInfo);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
 
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
        }
 
        #endregion
 
        #region ■ 预创建个人中心全部的文件夹_________
 
        /// <summary>
        /// 预创建个人中心全部的文件夹
        /// </summary>
        public static void CreatAllUserCenterDirectory()
        {
            //本地缓存的根目录
            string LocalDirectory = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory);
            Global.CreateEmptyDirectory(LocalDirectory);
 
            //自动备份【文件夹】(编辑,追加)
            string directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //自动备份【文件夹】(删除)
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupdeleteDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //下载备份的时候所使用的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadBackupTempDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //保存安防记录的【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.SafeguardAlarmDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //上传网关备份文件到云端的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.GatewayBackupDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //下载分享文件的临时【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //LOG出力【文件夹】
            directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
            Global.CreateEmptyDirectory(directory);
 
            //用户图片目录路径【文件夹】
            if (UserCenterResourse.Option.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.Option.UserPictruePath))
            {
                System.IO.Directory.CreateDirectory(UserCenterResourse.Option.UserPictruePath);
            }
        }
 
        #endregion
 
        #region ■ 获取控制主人账号的Token____________
 
        /// <summary>
        /// 获取控制主人账号的Token
        /// </summary>
        /// <returns></returns>
        public static string GetConnectMainToken()
        {
            //启用管理员权限
            if (Config.Instance.isAdministrator == true)
            {
                return Config.Instance.AdminRequestToken;
            }
            return Config.Instance.Token;
        }
 
        #endregion
 
        #region ■ 16进制转化_________________________
 
        /// <summary>
        /// 将16进制的文本翻译为正常文本
        /// </summary>
        /// <param name="hexText">16进制的文本</param>
        /// <param name="count">以多少个字节为一组</param>
        /// <returns></returns>
        public static string TranslateHexadecimalIntoText(string hexText, int count = 2)
        {
            string textValue = string.Empty;
            while (hexText.Length > 0)
            {
                string temp = hexText.Substring(0, count);
                hexText = hexText.Substring(count);
                int value = Convert.ToInt32(temp, 16);
                textValue += ((char)value).ToString();
            }
            return textValue;
        }
 
        /// <summary>
        /// 将文本翻译为16进制的文本
        /// </summary>
        /// <param name="text">指定文本</param>
        /// <returns></returns>
        public static string TranslateTextIntoHexadecimal(string text)
        {
            string textValue = string.Empty;
            foreach (char c in text)
            {
                int value = Convert.ToInt32(c);
                textValue += Convert.ToString(value, 16);
            }
            return textValue;
        }
 
        #endregion
 
        #region ■ 加密和解密_________________________
 
        /// <summary>
        /// 加密密码
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="strPsw"></param>
        /// <returns></returns>
        public static string EncryptPassword(string keys, string strPsw)
        {
            if (strPsw == string.Empty)
            {
                return strPsw;
            }
            var des = new System.Security.Cryptography.DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
            des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
            des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
            var ms = new System.IO.MemoryStream();
            var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            StringBuilder ret = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                ret.AppendFormat("{0:X2}", b);
            }
            return ret.ToString();
        }
 
        /// <summary>
        /// 解密密码
        /// </summary>
        /// <param name="strPsw"></param>
        /// <returns></returns>
        public static string DecryptPassword(string keys, string strPsw)
        {
            if (strPsw == string.Empty)
            {
                return strPsw;
            }
            var des = new System.Security.Cryptography.DESCryptoServiceProvider();
 
            byte[] inputByteArray = new byte[strPsw.Length / 2];
            for (int x = 0; x < strPsw.Length / 2; x++)
            {
                int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
                inputByteArray[x] = (byte)i;
            }
 
            des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
            des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
            var ms = new System.IO.MemoryStream();
            var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
 
            StringBuilder ret = new StringBuilder();
 
            return System.Text.Encoding.Default.GetString(ms.ToArray());
        }
        #endregion
 
        #region ■ 文件保存和读取_____________________
 
        /// <summary>
        /// 文件保存(整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <param name="obj">需要序列化的东西</param>
        public static void SaveFileContent(string fullName, object obj)
        {
            var data = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var byteData = System.Text.Encoding.UTF8.GetBytes(data);
            //写入内容
            Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
        }
 
        /// <summary>
        /// 读取文件(文件不存在返回null,整天忘记,所以建一个函数来玩玩)
        /// </summary>
        /// <param name="fullName">全路径</param>
        /// <returns></returns>
        public static string LoadFileContent(string fullName)
        {
            if (System.IO.File.Exists(fullName) == false)
            {
                return null;
            }
            var varByte = Shared.IO.FileUtils.ReadFile(fullName);
            return System.Text.Encoding.UTF8.GetString(varByte);
        }
 
        #endregion
    }
}