gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
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
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
using System.Linq;
 
namespace Shared.Common
{
    /// <summary>
    /// 房间对象
    /// </summary>
    [System.Serializable]
    public class Room
    {
        #region ◆ 变量____________________________
 
        /// <summary>
        /// 房间文件
        /// </summary>
        /// <value>The name of the file.</value>
        [Newtonsoft.Json.JsonIgnore]
        public string FileName
        {
            get
            {
                return $"Room_{Id}.json";
            }
        }
        /// <summary>
        /// 房间id--使用guid
        /// Guid.NewGuid().ToString()
        /// </summary>
        public string Id = Guid.NewGuid().ToString();
        /// <summary>
        /// 楼层Id
        /// 新增时使用Guid
        /// </summary>
        public string FloorId = string.Empty;
        /// <summary>
        /// 楼层名称
        /// </summary>
        public string FloorName
        {
            get
            {
               return Config.Instance.Home.GetFloorNameById(FloorId);
            }
        }
        /// <summary>
        /// 房间名
        /// </summary>
        public string Name = string.Empty;
 
        /// <summary>
        /// 房间背景图
        /// </summary>
        public string BackgroundImage = string.Empty;
 
        /// <summary>
        /// 图片来源 0--本地图库 1--拍照 2--系统图库
        /// </summary>
        public int BackgroundImageType = 0;
 
        /// <summary>
        /// 楼层--备用
        /// </summary>
        public Dictionary<string, string> FloorList = new Dictionary<string, string> { };
 
        /// <summary>
        /// 温度传感器(设备主键)
        /// </summary>
        public string TemperatrueDevice = string.Empty;
        /// <summary>
        /// 湿度传感器(设备主键)
        /// </summary>
        public string HumidityDevice = string.Empty;
        /// <summary>
        /// 温度
        /// </summary>
        public decimal Temperatrue;
        /// <summary>
        /// 湿度
        /// </summary>
        public decimal Humidity;
 
        /// <summary>
        /// 当前选择的房间
        /// </summary>
        private static Room m_CurrentRoom = null;
        /// <summary>
        /// 当前选择的房间
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public static Room CurrentRoom
        {
            get
            {
                if (m_CurrentRoom == null && Lists.Count > 0)
                {
                    if (m_CurrentRoom == null) { m_CurrentRoom = Lists[0]; }
                    return Lists[0];
                }
                return m_CurrentRoom;
            }
            set { m_CurrentRoom = value; }
        }
 
        /// <summary>
        /// 房间里所有的设备列表
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<DeviceUI> DeviceUIList = new List<DeviceUI> { };
        /// <summary>
        ///设备文件路径列表
        /// </summary>
        public readonly List<string> DeviceUIFilePathList = new List<string>();
 
        /// <summary>
        /// 喜爱房间id
        /// </summary>
        public const string LoveRoomId= "Favorite";
 
        /// <summary>
        /// 是否是默认喜爱房间
        /// </summary>
        /// <value><c>true</c> if is love; otherwise, <c>false</c>.</value>
        [Newtonsoft.Json.JsonIgnore]
        public bool IsLove
        {
            get
            {
                return Id == LoveRoomId;
            }
        }
 
        /// <summary>
        /// 是否是分享过来的房间
        /// 注:分享过来的房间不能删除,不能编辑该房间,不能对设备(功能)、场景进行增删改
        /// </summary>
        public bool IsSharedRoom = false;
 
        /// <summary>
        /// 获取喜爱房间的所有设备路径
        /// </summary>
        /// <value>The love room device list.</value>
        [Newtonsoft.Json.JsonIgnore]
        public static List<string> LoveRoomDeviceUIFilePathList
        {
            get
            {
                if (Lists.Count == 0)
                {
                    return new List<string> { };
                }
                return CurrentRoom.GetLoveRoom().DeviceUIFilePathList;
            }
        }
 
        /// <summary>
        /// 所有房间的所有设备类型
        /// </summary>
        /// <value>All room device type list.</value>
        [Newtonsoft.Json.JsonIgnore]
        public static List<DeviceType> AllRoomDeviceTypeList
        {
            get
            {
                var typeList = new List<DeviceType> { };
                foreach (var deviceUI in AllRoomDeviceUIList)
                {
                    if (deviceUI == null || deviceUI.CommonDevice == null)
                    {
                        continue;
                    }
                    if (!typeList.Contains(deviceUI.CommonDevice.Type))
                    {
                        typeList.Add(deviceUI.CommonDevice.Type);
                    }
                }
                return typeList;
            }
        }
 
        /// <summary>
        /// 获取所有房间的所有场景
        /// </summary>
        /// <value>All room scene UIL ist.</value>
        [Newtonsoft.Json.JsonIgnore]
        public static List<SceneUI> AllRoomSceneUIList
        {
            get
            {
                var sceneList = new List<SceneUI> { };
                foreach (var r in Shared.Common.Room.Lists)
                {
                    if(r.IsLove)
                    {
                        continue;
                    }
                    if (r.SceneUIList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var sceneUI in r.SceneUIList)
                    {
                        if (sceneUI == null)
                        {
                            continue;
                        }
                        sceneList.Add(sceneUI);
                    }
                }
                return sceneList;
            }
        }
 
        /// <summary>
        /// 获取所有房间的所有场景路径
        /// </summary>
        /// <value>All room scene UIL ist.</value>
        [Newtonsoft.Json.JsonIgnore]
        public  List<string> AllRoomSceneUIFilepathList
        {
            get
            {
                var pathList = new List<string> { };
                foreach (var r in Lists)
                {
                    if(r.IsLove)
                    {
                        continue;
                    }
 
                    if (r.SceneUIFilePathList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var path in r.SceneUIFilePathList)
                    {
                        pathList.Add(path);
                    }
                }
                return pathList;
            }
        }
 
        /// <summary>
        /// 场景列表---不再序列化
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public List<SceneUI> SceneUIList = new List<SceneUI> { };
        /// <summary>
        ///场景文件列表
        /// </summary>
        public readonly List<string> SceneUIFilePathList = new List<string>();
 
        /// <summary>
        /// 所有的房间信息
        /// </summary>
        public static List<Room> Lists = new List<Room>();
 
        /// <summary>
        /// 获取所有房间的所有设备
        /// </summary>
        /// <value>All room device UIL ist.</value>
        [Newtonsoft.Json.JsonIgnore]
        public static List<DeviceUI> AllRoomDeviceUIList
        {
            get
            {
                List<DeviceUI> deviceList = new List<DeviceUI>();
                for (int i = 0; i < Lists.Count; i++)
                {
                    var room = Lists[i];
                    if (room.IsSharedRoom || room.IsLove)
                    {
                        continue;
                    }
                    if (room.DeviceUIList.Count == 0)
                    {
                        continue;
                    }
                    for (int j = 0; j < room.DeviceUIList.Count; j++)
                    {
                        var device = room.DeviceUIList[j];
                        if (device == null || device.CommonDevice == null)
                        {
                            continue;
                        }
                        if (deviceList.Find((obj) => obj.FileName == device.FileName) == null)
                        {
                            deviceList.Add(device);
                        }
                    }
                }
                return deviceList;
            }
        }
 
        #endregion
 
        #region ◆ 构造方法________________________
 
        /// <summary>
        /// 构造方法
        /// </summary>
        static Room()
        {
            InitAllRoom();
        }
 
        #endregion
 
        #region ◆ 初始化__________________________
 
        /// <summary>
        /// 初始化房间信息
        /// 从文件中全部读取所有的房间数据到内存
        /// </summary>
        public static void InitAllRoom()
        {
            Lists.Clear();
            if (Config.Instance.Home.RoomFilePathList.Contains("Room_Favorite.json") == false)
            {
                //默认添加喜爱的房间--禁止修改房间名
                var love = new Room { Name = Language.StringByID(R.MyInternationalizationString.Favorite), BackgroundImage = "RoomIcon/0.JPG", Id = LoveRoomId };
                love.Save(false);
                //添加到house 房间路径列表
                var currentHome = Config.Instance.Home;
                currentHome.RoomFilePathList.Insert(0, love.FileName);
                currentHome.Save(false);
            }
            foreach (var roomFilePath in Config.Instance.Home.RoomFilePathList)
            {
                var room = GetRoomByFilePath(roomFilePath);
 
                if (null != room)
                {
                    if (room.IsSharedRoom)
                    {
                        room.Name = $"{room.Name}";
                    }
                    Lists.Add(room);
 
                }
            }
 
            Config.Instance.Home.InitFloor();
 
            CurrentRoom.RefreshRoomListView();
        }
 
        /// <summary>
        /// 刷新房间视图列表
        /// </summary>
        public void RefreshRoomListView()
        {
            Application.RunOnMainThread(() =>
            {
                Phone.Device.Room.RoomManagement.Instance.Show();
            });
        }
 
        /// <summary>
        /// 从本地重新加载全部的房间
        /// </summary>
        public static void RefreshAllRoomByLocation()
        {
            var homeTemp = Config.Instance.Home;
            homeTemp.RoomFilePathList.Clear();
 
            var listFile = Global.FileListByHomeId();
 
            //我的喜爱的房间必须要在第0位才行
            string fRoom = "Room_Favorite.json";
            if (listFile.Contains(fRoom) == true)
            {
                listFile.Remove(fRoom);
                homeTemp.RoomFilePathList.Add(fRoom);
            }
 
            var listRoomFile = new List<string>();
            foreach (string fileName in listFile)
            {
                if (fileName.StartsWith("Room_"))
                {
                    homeTemp.RoomFilePathList.Add(fileName);
                    listRoomFile.Add(fileName);
                }
            }
            //检测楼层数据的合法性
            CheckFloorData(listRoomFile);
 
            homeTemp.Save(false);
            InitAllRoom();
        }
 
        /// <summary>
        /// 检测楼层数据的合法性
        /// </summary>
        /// <param name="listRoomFile"></param>
        private static void CheckFloorData(List<string> listRoomFile)
        {
            for (int i = 0; i < listRoomFile.Count; i++)
            {
                try
                {
                    var byteData = Global.ReadFileByHomeId(listRoomFile[i]);
                    string valueData = System.Text.Encoding.UTF8.GetString(byteData);
                    var roomTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Room>(valueData);
 
                    //检测多个手机来回创建,然后又删除之后,楼层数据不能保证100%同步的问题
                    if (roomTemp.FloorId != string.Empty && Config.Instance.Home.FloorDics.ContainsKey(roomTemp.FloorId) == false)
                    {
                        //未知楼层
                        Config.Instance.Home.FloorDics[roomTemp.FloorId] = Language.StringByID(R.MyInternationalizationString.uUnKnownFloor);
                    }
                }
                catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
            }
        }
 
        #endregion
 
        #region ◆ 添加房间_________________________
 
        /// <summary>
        /// 增加房间
        /// </summary>
        /// <returns><c>true</c>, if room was added, <c>false</c> otherwise.</returns>
        /// <param name="room">Room.</param>
        public bool AddRoom(Room room)
        {
            if (string.IsNullOrEmpty(room.FileName) || Global.IsExistsByHomeId(room.FileName))
            {
                return false;
            }
            if (Config.Instance.Home.RoomFilePathList.Contains(room.FileName))
            {
                return false;
            }
            Lists.Add(room);
            var r = Config.Instance.Home.AddRoomListFilePath(room.FileName);
            if (r == false)
            {
                return false;
            }
            Save();
            HdlAutoBackupLogic.AddOrEditorFile(room.FileName);
            CurrentRoom.RefreshRoomListView();
            return true;
        }
 
        #endregion
 
        #region ◆ 删除房间_________________________
 
        /// <summary>
        /// 删除房间
        /// </summary>
        public bool Remove(string roomFilePath)
        {
            var room = GetRoomByFilePath(roomFilePath);
            if (null == room)
            {
                return false;
            }
            //删除来自拍照或者系统图库的房间背景图片
            if (room.BackgroundImageType == 1 || room.BackgroundImageType == 2)
            {
                //删除掉原来的自定义图片
                if (Global.IsExistsByHomeId(room.BackgroundImage) == true)
                {
                    Global.DeleteFilebyHomeId(room.BackgroundImage);
                    //删除备份
                    HdlAutoBackupLogic.DeleteFile(room.BackgroundImage);
                }
            }
            //我的喜爱
            var loveRoom = this.GetLoveRoom();
            if (loveRoom != null)
            {
                //移除我的喜爱里面的设备
                for (int i = 0; i < room.DeviceUIFilePathList.Count; i++)
                {
                    loveRoom.DeviceUIFilePathList.Remove(room.DeviceUIFilePathList[i]);
                    loveRoom.DeviceUIList.RemoveAll((obj) => { return room.DeviceUIFilePathList[i] == obj.FileName; });
                }
                //移除我的喜爱里面的场景
                for (int i = 0; i < room.SceneUIFilePathList.Count; i++)
                {
                    loveRoom.SceneUIFilePathList.Remove(room.SceneUIFilePathList[i]);
                    loveRoom.SceneUIList.RemoveAll((obj) => { return room.SceneUIFilePathList[i] == obj.FileName; });
                }
                loveRoom.Save(false);
            }
 
            if (Global.IsExistsByHomeId(roomFilePath) == false)
            {
                return false;
            }
            Config.Instance.Home.RemoveRoomListFilePath(roomFilePath);
            //删除文件
            Global.DeleteFilebyHomeId(roomFilePath);
            Lists.Remove(room);
            HdlAutoBackupLogic.DeleteFile(roomFilePath);
 
            CurrentRoom.RefreshRoomListView();
 
            return true;
        }
 
        #endregion
 
        #region ◆ 获取房间________________________
 
        /// <summary>
        /// 获取喜爱房间
        /// </summary>
        /// <returns></returns>
        public Room GetLoveRoom()
        {
            return CurrentRoom.GetRoomById(LoveRoomId);
        }
 
        /// <summary>
        /// 通过路径获取房间
        /// </summary>
        /// <returns>The room by file path.</returns>
        /// <param name="roomFilePath">Room file path.</param>
        public static Room GetRoomByFilePath(string roomFilePath)
        {
            try
            {
                var roomFile = Global.ReadFileByHomeId(roomFilePath);
                var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(System.Text.Encoding.UTF8.GetString(roomFile));
 
                if (null == nowRoom)
                {
                    System.Console.WriteLine("房间文件路径不对,文件路径为:" + roomFilePath);
                    return null;
                }
 
                var beforeRoom = Lists.Find((obj) => obj.Id == nowRoom.Id);
                if (beforeRoom != null)
                {
                    var tempDeviceUIList = new List<DeviceUI>();
                    tempDeviceUIList.AddRange(beforeRoom.DeviceUIList);
                    var tempSceneUIList = new List<SceneUI>();
                    tempSceneUIList.AddRange(beforeRoom.SceneUIList);
                    //设备(deviceUI)
                    beforeRoom.DeviceUIList.Clear();
                    foreach (var deviceFilePath in beforeRoom.DeviceUIFilePathList)
                    {
                        var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceFilePath));
                        var tempDeviceUI = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo);
                        if (tempDeviceUI != null)
                        {
                            var delCommon = tempDeviceUIList.Find((obj) => obj.CommonDevice != null && tempDeviceUI.CommonDevice != null && obj.CommonDevice.Type == tempDeviceUI.CommonDevice.Type && obj.CommonDevice.CommonDeviceAddrEpoint == tempDeviceUI.CommonDevice.CommonDeviceAddrEpoint);
                            if (delCommon != null)
                            {
                                beforeRoom.DeviceUIList.Add(delCommon);
                            }
                            else
                            {
                                beforeRoom.AddDevice(deviceFilePath);
                            }
                        }
                    }
                    //场景(SceneUI)
                    beforeRoom.SceneUIList.Clear();
                    foreach (var sceneFilePath in beforeRoom.SceneUIFilePathList)
                    {
                        var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneFilePath));
                        var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo);
                        if (tempSceneUI != null)
                        {
                            var scene = tempSceneUIList.Find((obj) => obj.FileName == tempSceneUI.FileName);
                            if (scene != null)
                            {
                                beforeRoom.SceneUIList.Add(scene);
                            }
                            else
                            {
                                beforeRoom.AddScene(scene);
                            }
                        }
                    }
 
                    return beforeRoom;
                }
 
                //设备(deviceUI)
                nowRoom.DeviceUIList.Clear();
                foreach (var deviceFilePath in nowRoom.DeviceUIFilePathList)
                {
                    var tempCommon = LocalDevice.Current.GetDeviceUI(deviceFilePath);
                    if (tempCommon == null || tempCommon.CommonDevice == null)
                    {
                        continue;
                    }
                    nowRoom.DeviceUIList.Add(tempCommon);
                }
                //场景(SceneUI)
                nowRoom.SceneUIList.Clear();
                foreach (var sceneUIFilePath in nowRoom.SceneUIFilePathList)
                {
                    var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(sceneUIFilePath));
                    var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo);
                    if (tempScene == null)
                    {
                        continue;
                    }
                    nowRoom.SceneUIList.Add(tempScene);
                }
                return nowRoom;
            }
            catch(Exception ex)
            {
                return null;
            }
        }
 
        /// <summary>
        /// 根据房间Id,获取房间对象
        /// </summary>
        /// <returns>The room by name.</returns>
        /// <param name="roomId">房间ID</param>
        public Room GetRoomById(string roomId)
        {
            if (string.IsNullOrEmpty(roomId))
            {
                return null;
            }
            return Lists.Find((obj) => obj.Id == roomId);
        }
 
        /// <summary>
        /// 根据房间名字,获取房间对象
        /// </summary>
        /// <returns>The room by name.</returns>
        /// <param name="roomName">房间名</param>
        public Room GetRoomByName(string roomName)
        {
            return Lists.Find((obj) => obj.Name == roomName);
        }
 
        /// <summary>
        /// 根据设备获取房间名字(楼层+房间名)
        /// </summary>
        /// <returns>房间名</returns>
        /// <param name="device">设备对象</param>
        public string GetRoomNameByDevice(CommonDevice device)
        {
            var room = this.GetRoomByDevice(device);
            if (room == null)
            {
                //未分配区域
                return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
            }
            if (Config.Instance.Home.FloorDics.ContainsKey(room.FloorId) == true)
            {
                //(楼层+房间名)
                return Config.Instance.Home.FloorDics[room.FloorId] + " " + room.Name;
            }
            return room.Name;
        }
 
        /// <summary>
        /// 获取设备所在的房间
        /// </summary>
        /// <returns>The room by device.</returns>
        /// <param name="device">设备对象</param>
        public Room GetRoomByDevice(CommonDevice device)
        {
            string deviceFile = device.FilePath;
            return Lists.Find((obj) => obj.IsLove == false && obj.DeviceUIFilePathList.Contains(deviceFile));
        }
 
        /// <summary>
        /// 通过场景id获取房间名
        /// </summary>
        /// <returns>The room name by scene identifier.</returns>
        /// <param name="sceneId">Scene identifier.</param>
        public string GetRoomNameBySceneId(int sceneId)
        {
            var room = GetRoomBySceneId(sceneId);
            if (room == null)
            {
                return null;
            }
            return room.Name;
        }
 
        /// <summary>
        /// 通过场景id获取房间对象
        /// </summary>
        /// <returns>The room  by scene identifier.</returns>
        /// <param name="sceneId">Scene identifier.</param>
        public Room GetRoomBySceneId(int sceneId)
        {
            foreach (var r in Lists)
            {
                if(r.IsLove)
                {
                    continue;
                }
                foreach (var scene in r.SceneUIList)
                {
                    if (scene.Id == sceneId)
                    {
                        return r;
                    }
                }
            }
            return null;
        }
 
        /// <summary>
        /// 获取当前楼层的房间
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Room> GetRoomsByFloorId(string id)
        {
            try
            {
                if (Lists == null || Lists.Count == 0 || Lists.Count == 1)
                {
                    return null;
                }
                if (Config.Instance.Home.FloorDics.Count == 0)
                {
                    return Lists;
                }
                return Lists.FindAll((obj) => obj.FloorId == id);
            }
            catch(Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                return null;
            }
 
        }
        /// <summary>
        /// 获取当前楼层的房间名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<string> GetRoomNamesByFloorId(string id)
        {
            List<string> names = new List<string> { };
            foreach (var r in Lists)
            {
                if (r.FloorId == id)
                {
                    names.Add(r.Name);
                }
            }
            return names;
        }
 
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  List<Room> GetRoomsByFloorIdAppendLoveRoom(string id)
        {
            if (Config.Instance.Home.FloorDics.Count == 0)
            {
                return Lists;
            }
            var r= Lists.FindAll((obj) => obj.FloorId == id);
            r.Insert(0, GetLoveRoom());
            return r;
        }
 
        /// <summary>
        /// 获取当前楼层的房间(拼接了【常用】在第一位)
        /// </summary>
        /// <returns></returns>
        public  List<Room> GetRoomsByCurrentFloorIdAppendLoveRoom()
        {
            if(Config.Instance.Home.FloorDics.Count==0)
            {
                return Lists;
            }
            var r = Lists.FindAll((obj) => obj.FloorId == Config.Instance.Home.CurrentFloorId);
            r.Insert(0, GetLoveRoom());
            return r;
        }
 
        #endregion
 
        #region ◆ 房间方法________________________
 
        /// <summary>
        /// 设备的房间变更
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="roomId">新房间Id</param>
        /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param>
        public void ChangedRoom(CommonDevice device, string roomId, bool saveRealRoom = true)
        {
            //房间是否修改
            if (this.IsRoomChanged(device, roomId) == false)
            {
                return;
            }
            //从原来的房间移除设备
            this.DeleteDevice(device);
 
            //添加到新的房间
            var room = this.GetRoomById(roomId);
            if (room != null)
            {
                room.AddDevice(device, saveRealRoom);
            }
        }
 
        /// <summary>
        /// 房间名字是否有修改
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="roomId">新房间Id</param>
        /// <returns></returns>
        public bool IsRoomChanged(CommonDevice device, string roomId)
        {
            var room = this.GetRoomByDevice(device);
            if (room == null || room.Id != roomId)
            {
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 获取房间所在区域
        /// 楼层,房间名
        /// </summary>
        /// <returns></returns>
        public string GetZoneName()
        {
            if (string.IsNullOrEmpty(FloorId))
            {
                return Name;
            }
            var floorName = Config.Instance.Home.GetFloorNameById(FloorId);
            if (floorName == null)
            {
                return Name;
            }
            return $"{floorName},{Name}";
        }
 
        #endregion
 
        #region ◆ 更新房间_________________________
 
        /// <summary>
        /// Updates the memorry.
        /// </summary>
        /// <param name="roomFilePath">Room file path.</param>
        public static void UpdateMemorry(string roomFilePath)
        {
            GetRoomByFilePath(roomFilePath);
        }
 
        #endregion
 
        #region ◆ 房间背景图的相关___________________
 
        /// <summary>
        /// 移动背景图片到住宅目录下
        /// </summary>
        /// <param name="oldFile">需要移动的文件(直接文件名)</param>
        /// <param name="newFile">要移动到的位置-(包含住宅路径:住宅/文件名)</param>
        public void MoveBackGroundIamageFileToDirectory(string oldFile, string newFile)
        {
            try
            {
                var newPath = System.IO.Path.Combine(Config.Instance.FullPath, newFile);
                var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath,oldFile);
                Global.MoveFileToDirectory(path, newPath);
                //备份
                Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(oldFile);
                //Save();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("移动图片异常 " + ex.Message);
            }
        }
 
        #endregion
 
        #region ◆ 添加设备________________________
 
        /// <summary>
        /// 添加设备(此方法目前只给【我的喜爱】使用)
        /// </summary>
        /// <param name="deviceUIFilePath">Device UIF ile path.</param>
        public void AddDevice(string deviceUIFilePath)
        {
            if (string.IsNullOrEmpty(deviceUIFilePath))
            {
                return;
            }
            var deviceUI = Common.LocalDevice.Current.GetDeviceUI(deviceUIFilePath);
            if (null == deviceUI.CommonDevice)
            {
                //当前对象数据无效
                return;
            }
            if (!DeviceUIFilePathList.Contains(deviceUIFilePath) && !DeviceUIList.Contains(deviceUI))
            {
                DeviceUIFilePathList.Add(deviceUIFilePath);
                DeviceUIList.Add(deviceUI);
            }
            //保存到本地
            Save();
        }
 
        /// <summary>
        /// 添加设备(此方法目前只给Room里面使用)
        /// </summary>
        /// <param name="device">要添加的设备对象</param>
        /// <param name="saveRealRoom">是否修改真实物理设备的房间,不出意外,这个值默认为true即可</param>
        public void AddDevice(CommonDevice device, bool saveRealRoom)
        {
            if (device == null)
            {
                return;
            }
            //设备信息保存到本地
            device.Save();
 
            var deviceUI = Common.LocalDevice.Current.GetDeviceUI(device);
            if (DeviceUIFilePathList.Contains(deviceUI.FileName) == false)
            {
                DeviceUIFilePathList.Add(deviceUI.FileName);
                DeviceUIList.Add(deviceUI);
                //保存到本地
                Save();
 
                if (saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
                {
                    //如果只有一个回路,则修改真实物理设备的房间
                    LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, this.Id, false);
                }
            }
        }
 
        #endregion
 
        #region ◆ 删除设备_________________________
        /// <summary>
        /// 删除功能-设备
        /// </summary>
        /// <param name="deviceUIFilePath">Device UIF ile path.</param>
        public void DeleteDevice(string deviceUIFilePath)
        {
            if (deviceUIFilePath == null) return;
            if (DeviceUIFilePathList.Contains(deviceUIFilePath))
            {
                DeviceUIFilePathList.Remove(deviceUIFilePath);
                DeviceUIList.RemoveAll((obj) => obj.FileName == deviceUIFilePath);
                Save();
            }
        }
 
        /// <summary>
        /// 删除设备
        /// </summary>
        /// <param name="device">要删除的设备对象</param>
        public void DeleteDevice(CommonDevice device)
        {
            if (device == null)
            {
                return;
            }
            //根据设备,获取所在的房间
            var room = this.GetRoomByDevice(device);
            if (room == null)
            {
                return;
            }
            string deviceFile = device.FilePath;
            //移除缓存
            if (room.DeviceUIFilePathList.Contains(deviceFile) == false)
            {
                return;
            }
            room.DeviceUIFilePathList.Remove(deviceFile);
 
            room.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
            room.Save();
            //更改自动备份
            HdlAutoBackupLogic.AddOrEditorFile(room.FileName);
 
            //递归:删除掉以前的旧数据导致的多个房间的问题
            this.DeleteDevice(device);
        }
 
        /// <summary>
        /// 删除我的喜爱的设备
        /// </summary>
        /// <param name="device">要删除的设备对象</param>
        public void DeleteLoveDevice(CommonDevice device)
        {
            if (device == null)
            {
                return;
            }
            //我的喜爱
            var loveRoom = this.GetLoveRoom();
            if (loveRoom != null)
            {
                string deviceFile = device.FilePath;
                //移除缓存
                if (loveRoom.DeviceUIFilePathList.Contains(deviceFile) == false)
                {
                    return;
                }
                loveRoom.DeviceUIFilePathList.Remove(deviceFile);
                loveRoom.DeviceUIList.RemoveAll((obj) => obj.FileName == deviceFile);
            }
        }
 
        #endregion
 
        #region ◆ 获取设备_________________________
 
        /// <summary>
        /// 根据设备获取它的UI对象,如果不存在则新建
        /// </summary>
        /// <returns>The device user interface.</returns>
        /// <param name="device">设备对象</param>
        public DeviceUI GetDeviceUI(CommonDevice device)
        {
            return Common.LocalDevice.Current.GetDeviceUI(device);
        }
 
        /// <summary>
        /// 获取当前房间下的全部设备
        /// </summary>
        /// <returns></returns>
        public List<CommonDevice> GetRoomListDevice()
        {
            var listDevice = new List<CommonDevice>();
            foreach (var device in this.DeviceUIList)
            {
                if (device == null || device.CommonDevice == null)
                {
                    continue;
                }
                listDevice.Add(device.CommonDevice);
            }
            return listDevice;
        }
 
        /// <summary>
        /// 获取房间设备类型
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public static List<DeviceType> GetdeviceTypes(Room room)
        {
            List<DeviceType> typeList = new List<DeviceType> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI.CommonDevice.Type))
                {
                    typeList.Add(deviceUI.CommonDevice.Type);
                }
            }
            return typeList;
        }
 
        /// <summary>
        /// 获取该类型的设备
        /// </summary>
        /// <param name="room"></param>
        /// <param name="deviceType"></param>
        /// <returns></returns>
        public static List<DeviceUI> GetDeviceUIs(Room room ,DeviceType deviceType)
        {
            List<DeviceUI> typeList = new List<DeviceUI> { };
            foreach (var deviceUI in room.DeviceUIList)
            {
                if (deviceUI == null || deviceUI.CommonDevice == null)
                {
                    continue;
                }
                if(deviceUI.CommonDevice.Type!=deviceType)
                {
                    continue;
                }
                if (!typeList.Contains(deviceUI))
                {
                    typeList.Add(deviceUI);
                }
            }
            return typeList;
        }
 
        /// <summary>
        /// 获取未分配区域设备
        /// </summary>
        /// <returns></returns>
        public List<DeviceUI> GetUnalloctedDeviceUIs()
        {
            List<DeviceUI> deviceUIs = new List<DeviceUI> { };
            var dList = AllRoomDeviceUIList;
            var commonDeviceList = Common.LocalDevice.Current.listAllDevice;
            
            foreach (var device in commonDeviceList)
            {
                if (dList.Find((obj) => obj.CommonDevice.DeviceEpoint == device.DeviceEpoint && obj.CommonDevice.DeviceAddr == device.DeviceAddr) == null)
                {
                    deviceUIs.Add(Common.LocalDevice.Current.GetDeviceUI(device));
                }
            }
            if (deviceUIs.Count == 0)
            {
                return null;
            }
            return deviceUIs;
        }
 
        //public List<DeviceUI> GetUnalloctedDeviceUITypes
 
        #endregion
 
        #region ◆ 添加场景_________________________
 
        /// <summary>
        /// 添加场景  0失败 1成功  -1已经存在
        /// </summary>
        /// <returns>The scene.</returns>
        /// <param name="sceneName">Scene name.</param>
        /// <param name="sceneIconPath">背景图片,不包含住宅路径 如果iconPathType=1或者2 需要拼接住宅 变成 住宅/sceneIconPath</param>
        /// <param name="commons">Commons.</param>
        /// <param name="iconPathType">I场景背景图片来源类型 图片来源 0--本地图库 1--拍照 2--系统图库 默认0</param>
        public async System.Threading.Tasks.Task<int> AddScene(string sceneName, string sceneIconPath, List<ZigBee.Device.Scene.AddSceneMemberData> commons, int iconPathType)
        {
            //var scenes = GetSceneUIsByFloorId(FloorId);
            //if(scenes!=null && scenes.Count>0)
            //{
            //    if (scenes.Find(s => s.Name == sceneName) != null)
            //    {
            //        return -1;
            //    }
            //}
 
            var getSceneIdAllData = await ZigBee.Device.Scene.GetSceneNewIdAsync(sceneName);
            if (getSceneIdAllData == null || getSceneIdAllData.getSceneIdData == null)
            {
                return 0;
            }
            var getSceneIdData = getSceneIdAllData.getSceneIdData;
 
            bool result = true;
            foreach (var common in commons)
            {
                //添加新成员
                var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData
                {
                    Type = common.Type,
                    DeviceAddr = common.DeviceAddr,
                    Epoint = common.Epoint,
                    ScenesId = getSceneIdData.NewScenesId,
                    TaskList = common.TaskList,
                    DelayTime = common.DelayTime,
                    MemberNumber=common.MemberNumber,
                    ElseScenesId = common.ElseScenesId
                };
                //common.ScenesId = getSceneIdData.NewScenesId;
                //添加新成员 返回结果
                var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData);
                if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null)
                {
                    continue;
                }
                var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData;
                if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1)
                {
                    result = false;
                }
            }
            //加入成功
            if (result)
            {
                var sceneUI = new SceneUI
                {
                    Name = sceneName,
                    Id = getSceneIdData.NewScenesId,
                    IconPath = sceneIconPath,
                    IconPathType = iconPathType,
                    AddSceneMemberDataList= commons
                };
                sceneUI.Save();
                SceneUIList.Add(sceneUI);
                SceneUIFilePathList.Add(sceneUI.FileName);
                Save();
                return 1;
            }
            return 0;
        }
 
        /// <summary>
        /// 添加场景
        /// </summary>
        /// <param name="scene">Scene.</param>
        public void AddScene(SceneUI scene)
        {
            SceneUIList.Add(scene);
            SceneUIFilePathList.Add(scene.FileName);
            Save();
        }
 
        /// <summary>
        /// 删除场景
        /// </summary>
        /// <param name="scene"></param>
        public void DeleteScene(SceneUI scene)
        {
            var curScene = SceneUIList.Find((obj) => obj.Id == scene.Id);
            if (curScene == null)
            {
                return;
            }
            SceneUIList.Remove(curScene);
            SceneUIFilePathList.Remove(curScene.FileName);
            Save();
        }
 
        #endregion
 
        #region ◆ 设备是否收藏______________________
 
        /// <summary>
        /// 是否是收藏设备
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool IsCollectInRoom(string filePath)
        {
            if (GetLoveRoom().DeviceUIFilePathList.Find((obj) => obj == filePath) == null)
            {
                return false;
            }
            return true;
        }
        #endregion
 
        #region ◆ 修改场景________________________
 
        /// <summary>
        /// 修改场景设备 0失败 1成功
        /// </summary>
        /// <returns>The scene.</returns>
        /// <param name="sceneUI">Scene user interface.</param>
        /// <param name="sceneRemoveMemberData">Scene remove member data.</param>
        /// <param name="addCommons">Add commons.</param>
        public async System.Threading.Tasks.Task<int> ModifyScene(SceneUI sceneUI, Scene.SceneRemoveMemberData sceneRemoveMemberData, List<Scene.AddSceneMemberData> addCommons)
        {
            //if (AllRoomSceneUIList.Find(s => s.Name == sceneUI.Name) == null)
            //{
            //    return 0;
            //}
 
            bool result = true;
            //移除成员 返回结果
            var removeSceneMemberResponseAllData = await ZigBee.Device.Scene.RemoveSceneMemberAsync(sceneRemoveMemberData);
            if (removeSceneMemberResponseAllData == null || removeSceneMemberResponseAllData.removeSceneMemberResponseData == null)
            {
                return 0;
            }
            var removeSceneMemberResponseData = removeSceneMemberResponseAllData.removeSceneMemberResponseData;
            if (removeSceneMemberResponseData == null)
            {
                return 0;
            }
            if (removeSceneMemberResponseData.Result != 0)
            {
                result = false;
            }
            //添加
            foreach (var addCommon in addCommons)
            {
                //添加新成员
                var addSceneMemberData = new ZigBee.Device.Scene.AddSceneMemberData
                {
                    DeviceAddr = addCommon.DeviceAddr,
                    Type = addCommon.Type,
                    Epoint = addCommon.Epoint,
                    ScenesId = sceneUI.Id,
                    TaskList = addCommon.TaskList,
                    DelayTime = addCommon.DelayTime,
                    ElseScenesId = addCommon.ElseScenesId,
                    MemberNumber=addCommon.MemberNumber
                };
                //添加新成员 返回结果
                var addSceneMemberResponseAllData = await ZigBee.Device.Scene.AddSceneMemberAsync(addSceneMemberData);
                if (addSceneMemberResponseAllData == null || addSceneMemberResponseAllData.addSceneMemberResponseData == null)
                {
                    result = false;
                    System.Console.WriteLine("添加场景失败");
                    continue;
                }
                var addSceneMemberResponseData = addSceneMemberResponseAllData.addSceneMemberResponseData;
                if (addSceneMemberResponseData == null && addSceneMemberResponseData.Result != 1)
                {
                    result = false;
                }
            }
            //加入成功
            if (result)
            {
                sceneUI.AddSceneMemberDataList = addCommons;
                sceneUI.Save();
                if (IsLove == false)
                {
                    var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id);
                    if (curScene != null)
                    {
                        curScene.Name = sceneUI.Name;
                        curScene.IconPath = sceneUI.IconPath;
                        curScene.IconPathType = sceneUI.IconPathType;
                        curScene.AddSceneMemberDataList = sceneUI.AddSceneMemberDataList;
                        curScene.SceneDelayTime = sceneUI.SceneDelayTime;
                        curScene.Save(false);
                        Common.Room.CurrentRoom.GetLoveRoom().Save();
                    }
                }
                return 1;
            }
            return 0;
        }
 
        /// <summary>
        /// 设置、同步延时时间
        /// </summary>
        /// <param name="scene"></param>
        public void ModifySceneDelayTime(SceneUI scene)
        {
            if (IsLove)
            {
                foreach (var r in Lists)
                {
                    if (r.IsLove || r.SceneUIList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var sce in r.SceneUIList)
                    {
                        if (sce.Id == scene.Id)
                        {
                            sce.SceneDelayTime = scene.SceneDelayTime;
                            sce.Save(false);
                            r.Save(false);
                            break;
                        }
                    }
                }
            }
            else
            {
                var curScene = Common.Room.CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == scene.Id);
                if (curScene != null)
                {
                    curScene.SceneDelayTime = scene.SceneDelayTime;
                    curScene.Save(false);
                    Common.Room.CurrentRoom.GetLoveRoom().Save(false);
                }
            }
        }
 
        #endregion
 
        #region ◆ 删除场景________________________
 
        /// <summary>
        /// 移除场景--该仅进行了对本地场景数据的删除
        /// </summary>
        /// <param name="sceneUI">Scene user interface.</param>
        public void RemoveScene(SceneUI sceneUI)
        {
            if(Global.IsExistsByHomeId(sceneUI.FileName)==false)
            {
                return;
            }
 
            if (sceneUI.IconPathType == 1 || sceneUI.IconPathType == 2)
            {
                if (Global.IsExistsByHomeId(sceneUI.IconPath))
                {
                    Global.DeleteFilebyHomeId(sceneUI.IconPath);
                    HdlAutoBackupLogic.DeleteFile(sceneUI.IconPath);
                }
            }
 
            if (IsLove == false)
            {
                if (CurrentRoom.GetLoveRoom().SceneUIList.Find((obj) => obj.Id == sceneUI.Id) != null)
                {
                    CurrentRoom.GetLoveRoom().DeleteScene(sceneUI);
                }
            }
 
            SceneUIList.Remove(sceneUI);
            SceneUIFilePathList.Remove(sceneUI.FileName);
            Save();
 
            Global.DeleteFilebyHomeId(sceneUI.FileName);
            HdlAutoBackupLogic.DeleteFile(sceneUI.FileName);
        }
 
        #endregion
 
        #region ◆ 获取场景________________________
 
        /// <summary>
        /// 通过场景id获取场景
        /// </summary>
        /// <returns>The scene UIB y scene identifier.</returns>
        /// <param name="sceneId">Scene identifier.</param>
        public SceneUI GetSceneUIBySceneId(int sceneId)
        {
            foreach (var r in Lists)
            {
                if (r.IsLove)
                {
                    continue;
                }
                foreach (var sceneUI in r.SceneUIList)
                {
                    if (sceneUI.Id == sceneId)
                    {
                        return sceneUI;
                    }
                }
            }
            return null;
        }
 
        /// <summary>
        /// 获取该楼层所有场景
        /// </summary>
        /// <param name="floorId"></param>
        /// <returns></returns>
        public List<SceneUI> GetSameFloorScenes(string floorId)
        {
            List<SceneUI> sceneUIs = new List<SceneUI> { };
            var rooms= CurrentRoom.GetRoomsByFloorId(floorId);
            foreach(var r in rooms)
            {
                sceneUIs.AddRange(r.SceneUIList);
            }
            return sceneUIs;
        }
 
        /// <summary>
        /// 获取该楼层的场景
        /// </summary>
        /// <param name="floorId"></param>
        /// <returns></returns>
        public List<SceneUI> GetSceneUIsByFloorId(string floorId)
        {
            var rooms = GetRoomsByFloorId(floorId);
            if (rooms == null)
            {
                return null;
            }
            var sceneList = new List<SceneUI> { };
            foreach (var r in rooms)
            {
                if (r.SceneUIList.Count == 0)
                {
                    continue;
                }
                foreach (var sceneUI in r.SceneUIList)
                {
                    if (sceneUI == null)
                    {
                        continue;
                    }
                    sceneList.Add(sceneUI);
                }
            }
            return sceneList;
        }
 
        /// <summary>
        /// 获取未分配区域场景
        /// </summary>
        /// <returns></returns>
        public List<SceneUI> GetUnalloctedScenes()
        {
            List<SceneUI> sceneUIs = new List<SceneUI> { };
            var sList = AllRoomSceneUIFilepathList;
 
            List<string> sfile = new List<string> { };
            foreach (var path in Global.FileListByHomeId())
            {
                if (path.StartsWith("Scene_", StringComparison.Ordinal))
                {
                    sfile.Add(path);
                }
            }
            foreach (var path in sfile)
            {
                if (sList.Find((obj) => obj == path) == null)
                {
                    var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(path));
                    var tempSceneUI = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneUI>(jsonInfo);
                    if (tempSceneUI != null)
                    {
                        sceneUIs.Add(tempSceneUI);
                    }
                }
            }
            if (sceneUIs.Count == 0)
            {
                return null;
            }
            return sceneUIs;
        }
 
        #endregion
 
        #region ◆ 刷新场景_________________________
 
        /// <summary>
        /// 刷新房间的场景列表
        /// </summary>
        public async System.Threading.Tasks.Task<bool> RefreshSceneUIList()
        {
            bool result = true;
            var sceneList = await ZigBee.Device.Scene.GetSceneListAsync();
            if (sceneList == null)
            {
                return false;
            }
            List<int> sceneIDList = new List<int> { };
            foreach (var scene in sceneList)
            {
                if (scene == null)
                {
                    continue;
                }
                sceneIDList.Add(scene.ScenesId);
            }
            foreach (var r in Lists)
            {
                if(r.IsLove)
                {
                    continue;
                }
                if (r.SceneUIList == null || r.SceneUIList.Count == 0)
                {
                    continue;
                }
                foreach (var rScene in r.SceneUIList)
                {
                    if (rScene == null)
                    {
                        continue;
                    }
                    if (sceneIDList.Contains(rScene.Id) == false)
                    { 
                        r.RemoveScene(rScene);
                        result = true;
                    }
                }
            }
            return result;
        }
 
        #endregion
 
        #region ◆ 保存____________________________
 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="autoBackup">是否自动备份,默认true</param>
        public void Save(bool autoBackup = true)
        {
            //保存房间信息
            Global.WriteFileByBytesByHomeId(FileName, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)));
            if (autoBackup == true)
            {
                HdlAutoBackupLogic.AddOrEditorFile(FileName);
            }
        }
 
        #endregion
 
        #region ◆ 楼层和房间顺序相关_______________
 
        /// <summary>
        /// 根据楼层的主键获取排序后的房间列表
        /// </summary>
        /// <param name="i_floorKeys">楼层的主键</param>
        /// <param name="getShard">分享的房间是否也获取</param>
        /// <returns></returns>
        public List<Room> GetFloorSortRoom(string i_floorKeys, bool getShard = true)
        {
            Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>();
            //读取房间顺序
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            if (strData != null)
            {
                dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
            }
 
            var listRoomSort = new List<string>();
            if (dicAllSort.ContainsKey(i_floorKeys) == true)
            {
                listRoomSort = dicAllSort[i_floorKeys];
            }
            else
            {
                dicAllSort[i_floorKeys] = listRoomSort;
            }
 
            var dicRoom = new Dictionary<string, Common.Room>();
            foreach (var room in Common.Room.Lists)
            {
                if (room.FloorId != i_floorKeys || room.IsLove == true)
                {
                    //不是同一个楼层
                    continue;
                }
                if (listRoomSort.Contains(room.Id) == false)
                {
                    //新添加的房间
                    listRoomSort.Add(room.Id);
                }
                if (getShard == false && room.IsSharedRoom == true)
                {
                    //不要分享的房间
                    continue;
                }
                dicRoom[room.Id] = room;
            }
 
            var listSortRoom = new List<Room>();
            for (int i = 0; i < listRoomSort.Count; i++)
            {
                if (dicRoom.ContainsKey(listRoomSort[i]) == true)
                {
                    listSortRoom.Add(dicRoom[listRoomSort[i]]);
                }
            }
 
            //保存顺序
            UserCenterLogic.SaveFileContent(fullName, dicAllSort);
            return listSortRoom;
        }
 
        /// <summary>
        /// 保存房间的顺序
        /// </summary>
        /// <param name="i_floorKeys">楼层主键</param>
        /// <param name="listSort">房间顺序(房间的主键)</param>
        public void SaveRoomSort(string i_floorKeys, List<string> listSort)
        {
            Dictionary<string, List<string>> dicAllSort = new Dictionary<string, List<string>>();
            //读取房间顺序
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.RoomSortFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            if (strData != null)
            {
                dicAllSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
            }
 
            //保存顺序
            dicAllSort[i_floorKeys] = listSort;
            UserCenterLogic.SaveFileContent(fullName, dicAllSort);
            dicAllSort.Clear();
        }
 
        /// <summary>
        /// 获取排序后的楼层
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> GetFloorSortList()
        {
            //读取楼层顺序
            var listFloorSort = new List<string>();
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            if (strData != null)
            {
                listFloorSort = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(strData);
            }
            foreach (string keys in Common.Config.Instance.Home.FloorDics.Keys)
            {
                if (listFloorSort.Contains(keys) == false)
                {
                    //新添加的楼层
                    listFloorSort.Add(keys);
                }
            }
 
            var dic = new Dictionary<string, string>();
            for (int i = 0; i < listFloorSort.Count; i++)
            {
                if (Config.Instance.Home.FloorDics.ContainsKey(listFloorSort[i]) == true)
                {
                    dic[listFloorSort[i]] = Config.Instance.Home.FloorDics[listFloorSort[i]];
                }
            }
 
            //保存顺序
            UserCenterLogic.SaveFileContent(fullName, listFloorSort);
            return dic;
        }
 
        /// <summary>
        /// 保存楼层的顺序
        /// </summary>
        /// <param name="listSort">楼层的主键</param>
        public void SaveFloorSort(List<string> listSort)
        {
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.FloorSortFile);
            //保存顺序
            UserCenterLogic.SaveFileContent(fullName, listSort);
        }
 
        #endregion
 
        #region ◆ 克隆房间对象_____________________
 
        /// <summary>
        /// 克隆房间对象
        /// </summary>
        /// <returns></returns>
        public Room CloneRoomClass()
        {
            var newRoom = new Room();
            //克隆属性
            newRoom.Id = this.Id;
            newRoom.FloorId = this.FloorId;
            newRoom.TemperatrueDevice = this.TemperatrueDevice;
            newRoom.HumidityDevice = this.HumidityDevice;
            newRoom.Name = this.Name;
            newRoom.BackgroundImage = this.BackgroundImage;
            newRoom.BackgroundImageType = this.BackgroundImageType;
 
            return newRoom;
        }
 
        #endregion
 
    }
}