JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Phone
{
    public class ScenePhoneMethod
    {
        bool showTip = true;
 
        /// <summary>
        /// 添加或者修改房间场景
        /// </summary>
        /// <param name="roomFilePath">Room name.</param>
        /// <param name="ds">代理方法,用来刷新界面</param>
        /// <param name="sceneFilePath">Scene.(为null是表示是增加场景)</param>
        public void AddOrUpdataSceneBaseMassage (string roomFilePath, string sceneFilePath = null, Action<string> action = null, Action actionRefreshRoom = null)
        {
            Room room = null;
            if (roomFilePath == Scene.GlobalSceneFilePath) {
                //GlobalScene
            } else {
                room = Room.GetRoomByFilePath (roomFilePath);
                if (room == null)
                    return;
            }
 
            var scene = Scene.GetSceneByFilePath (sceneFilePath);
            if (null == scene) {
                scene = new Scene ();
            }
 
            #region Load
            Dialog dialog = new Dialog ();
 
            FrameLayout dialogBodyView = new FrameLayout () {
                BackgroundColor = SkinStyle.Current.DialogColor,
                Width = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (740),
                Gravity = Gravity.Center,
                Radius = 5,
                BorderWidth = 0,
                BorderColor = SkinStyle.Current.Transparent
            };
            dialog.AddChidren (dialogBodyView);
 
            Button btnDialgoTitle = new Button () {
                Width = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (70),
                BackgroundColor = SkinStyle.Current.DialogTitle,
                TextID = R.MyInternationalizationString.AddNewRoom,
                TextAlignment = TextAlignment.Center,
                Gravity = Gravity.CenterHorizontal,
            };
            dialogBodyView.AddChidren (btnDialgoTitle);
            Button lblSceneText = new Button () {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight (80),
                Width = Application.GetRealWidth (450),
                Height = Application.GetRealHeight (50),
                TextID = R.MyInternationalizationString.RoomName,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor,
            };
            dialogBodyView.AddChidren (lblSceneText);
            EditText sceneTextBox = new EditText () {
                Gravity = Gravity.CenterHorizontal,
                Y = lblSceneText.Bottom + Application.GetRealHeight (10),
                Width = Application.GetRealWidth (450),
                Height = Application.GetRealHeight (60),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor,
                Text = scene.Name,
                Radius = 2,
                BorderColor = SkinStyle.Current.DialogTitle,
                BorderWidth = 1,
            };
            dialogBodyView.AddChidren (sceneTextBox);
            sceneTextBox.EditorEnterAction += (obj) => {
                Application.HideSoftInput ();
            };
 
            Button lblIcon = new Button () {
                Gravity = Gravity.CenterHorizontal,
                Y = sceneTextBox.Bottom + Application.GetRealHeight (10),
                Width = Application.GetRealWidth (450),
                Height = btnDialgoTitle.Height,
                TextID = R.MyInternationalizationString.Backgroud,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor,
            };
            dialogBodyView.AddChidren (lblIcon);
 
            var verIconLayout = new VerticalScrolViewLayout () {
                Gravity = Gravity.CenterHorizontal,
                Y = lblIcon.Bottom,
                Width = sceneTextBox.Width,
                Height = Application.GetRealHeight (200),
            };
            dialogBodyView.AddChidren (verIconLayout);
            var inVerFramelayout = new FrameLayout () {
                Width = lblIcon.Width,
                Height = Application.GetRealHeight (200),
            };
            verIconLayout.AddChidren (inVerFramelayout);
 
            var systempictureLayout = new FrameLayout {
                Height = Application.GetRealHeight (160),
                Y = Application.GetRealHeight (480),
            };
            dialogBodyView.AddChidren (systempictureLayout);
 
            var btnBG = new Button () {
                Width = Application.GetRealWidth (270),
                Height = LayoutParams.MatchParent,
                UnSelectedImagePath = scene.BackgroundImagePath,
 
            };
            inVerFramelayout.AddChidren (btnBG);
#if wallon
            btnBG.Gravity = Gravity.Center;
#else
            var btnTakePictrue = new Button () {
                Width = inVerFramelayout.Width - btnBG.Width,
                Height = inVerFramelayout.Height / 2,
                TextID = R.MyInternationalizationString.TakePhoto,
                TextColor = SkinStyle.Current.TextColor1,
                BackgroundColor = SkinStyle.Current.ButtonColor,
                X = btnBG.Right,
            };
            inVerFramelayout.AddChidren (btnTakePictrue);
            Guid guid = Guid.NewGuid ();
            btnTakePictrue.MouseUpEventHandler += (sender, e) => {
                guid = Guid.NewGuid ();
                Camera.TakePicture ((obj) => {
                    if (obj != null) {
                        btnBG.UnSelectedImagePath = guid.ToString();
                    }
                }, guid.ToString(),false);
            };
            Button btnLineP = new Button () {
                Width = btnTakePictrue.Width,
                Height = 1,
                BackgroundColor = SkinStyle.Current.Black50Transparent,
                X = btnBG.Right,
                Y = btnTakePictrue.Bottom,
            };
            inVerFramelayout.AddChidren (btnLineP);
            Button btnSelectPictrue = new Button () {
                Width = btnTakePictrue.Width,
                Height = btnTakePictrue.Height,
                TextColor = SkinStyle.Current.TextColor1,
                TextID = R.MyInternationalizationString.SelectPicture,
                BackgroundColor = SkinStyle.Current.ButtonColor,
                X = btnBG.Right,
                Y = btnLineP.Bottom,
            };
            inVerFramelayout.AddChidren (btnSelectPictrue);
            btnSelectPictrue.MouseUpEventHandler += (sender, e) => {
                guid = Guid.NewGuid ();
                Camera.SelectPicture ((obj) => {
                    if (obj != null) {
                        btnBG.UnSelectedImagePath = guid.ToString ();
                    }
                }, guid.ToString(), false);
            };
 
#endif
                var horizontalScrolViewLayout = new HorizontalScrolViewLayout () {
                Width = Application.GetRealWidth (450),
                Gravity = Gravity.CenterHorizontal,
            };
            systempictureLayout.AddChidren (horizontalScrolViewLayout);
            for (int i = 0; i < 22; i++) {
                Button butscene = new Button () {
                    Width = Application.GetRealWidth (200),
                    Height = LayoutParams.MatchParent,
                };
                butscene.MouseUpEventHandler += (sender, e) => {
                    btnBG.UnSelectedImagePath = butscene.UnSelectedImagePath;
                };
                butscene.UnSelectedImagePath = "Scene/s" + (i).ToString () + ".png";
 
                horizontalScrolViewLayout.AddChidren (butscene);
            }
            FrameLayout BottomView = new FrameLayout () {
                Y = dialogBodyView.Height - Application.GetRealHeight (90),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.DialogTitle,
            };
            dialogBodyView.AddChidren (BottomView);
            Button btnBack = new Button () {
                Width = Application.GetRealWidth (119),
                UnSelectedImagePath = "Item/PositioningDialogBack.png",
                SelectedImagePath = "Item/PositioningDialogBack.png",
            };
            BottomView.AddChidren (btnBack);
            btnBack.MouseUpEventHandler += (sender1, e1) => {
                dialog.Close ();
            };
            Button btnLineH = new Button () {
                Width = 1,
                Height = LayoutParams.MatchParent,
                BackgroundColor = SkinStyle.Current.White20Transparent,
                X = btnBack.Right,
            };
            BottomView.AddChidren (btnLineH);
 
            Button btnSave = new Button () {
                Width = Application.GetRealWidth (400),
                X = btnLineH.Right,
                TextID = R.MyInternationalizationString.SAVE,
                TextAlignment = TextAlignment.Center,
                Radius = 1,
            };
            BottomView.AddChidren (btnSave);
            #endregion
 
            btnDialgoTitle.TextID = R.MyInternationalizationString.AddNewScenes;
            lblSceneText.TextID = R.MyInternationalizationString.SceneName;
 
            if (roomFilePath == Scene.GlobalSceneFilePath) {
                var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
                if (!string.IsNullOrEmpty (sceneFilePath))
                    btnDialgoTitle.TextID = R.MyInternationalizationString.ChangeInformation;
 
                //增加或者修改场景
                btnSave.MouseUpEventHandler += (sender, e) => {
                    string newScenFilePath = "GlobalScene_" + sceneTextBox.Text.Trim ();
 
                    if (string.IsNullOrEmpty (sceneTextBox.Text.Trim ())) {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                        return;
                    }
 
                    //更改过场景图
                    if (btnBG.UnSelectedImagePath == "SecenPicture") {//将选择或拍摄的背景更改对应的名称保存下来
                        IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, "Image_" + newScenFilePath);
                        btnBG.UnSelectedImagePath = "Image_" + newScenFilePath;
                    }
                    scene.BackgroundImagePath = btnBG.UnSelectedImagePath;
                    scene.Name = sceneTextBox.Text.Trim ();
                    //新加场景
                    if (sceneFilePath == null) {
                        if (IO.FileUtils.Exists (newScenFilePath)) {
                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            return;
                        }
                        sceneFileList.Add (newScenFilePath);
                    } else {
                        //更改的场景名称已经存在
                        if (!sceneFileList.Contains (newScenFilePath) && IO.FileUtils.Exists (newScenFilePath)) {
                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            return;
                        }
 
                        //场景名更改
                        if (sceneFilePath != newScenFilePath) {
                            //如果是场景更改,那原文件名也需要更新
                            IO.FileUtils.ReNameFile (sceneFilePath, newScenFilePath);
                            for (int i = 0; i < sceneFileList.Count; i++) {
                                if (sceneFileList [i] == sceneFilePath) {
                                    sceneFileList [i] = newScenFilePath;
                                }
                            }
                        }
                    }
                    // 更新修改后的数据
                    IO.FileUtils.WriteFileByBytes (newScenFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (scene)));
                    IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
                    if (action != null) {
                        action (newScenFilePath);
                    }
                    dialog.Close ();
                };
            } else {
                if (!string.IsNullOrEmpty (sceneFilePath))
                    btnDialgoTitle.TextID = R.MyInternationalizationString.ChangeInformation;
                btnSave.Width = Application.GetRealWidth (400);
 
                //增加或者修改场景
                btnSave.MouseUpEventHandler += (sender, e) => {
                    string newScenFilePath = "RoomScene_" + room.Name + "_" + sceneTextBox.Text.Trim ();
 
                    if (string.IsNullOrEmpty (sceneTextBox.Text.Trim ())) {
                        new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                        return;
                    }
 
                    //更改过场景图
                    if (btnBG.UnSelectedImagePath == "SecenPicture") {//将选择或拍摄的背景更改对应的名称保存下来
                        IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, "Image_" + newScenFilePath);
                        btnBG.UnSelectedImagePath = "Image_" + newScenFilePath;
                        IO.FileUtils.WriteFileByBytes (sceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (scene)));
                    }
                    scene.BackgroundImagePath = btnBG.UnSelectedImagePath;
                    scene.Name = sceneTextBox.Text.Trim ();
                    //新加场景
                    if (sceneFilePath == null) {
                        if (IO.FileUtils.Exists (newScenFilePath)) {
                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            return;
                        }
                        room.SceneFilePathList.Add (newScenFilePath);
                    } else {
                        //更改的场景名称已经存在
                        if (!room.SceneFilePathList.Contains (newScenFilePath) && IO.FileUtils.Exists (newScenFilePath)) {
                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            return;
                        }
 
                        //场景名更改
                        if (sceneFilePath != newScenFilePath) {
                            //如果是场景更改,那原文件名也需要更新
                            IO.FileUtils.ReNameFile (sceneFilePath, newScenFilePath);
                            for (int i = 0; i < room.SceneFilePathList.Count; i++) {
                                if (room.SceneFilePathList [i] == sceneFilePath) {
                                    room.SceneFilePathList [i] = newScenFilePath;
                                }
                            }
                        }
                    }
                    // 更新修改后的数据
                    IO.FileUtils.WriteFileByBytes (newScenFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (scene)));
                    room.Save (roomFilePath);
 
                    Room.UpdateMemorry (roomFilePath);
 
                    //刷新当前房间的数据
                    if (action != null) {
                        action (newScenFilePath);
                    }
 
                    if (actionRefreshRoom != null) {
                        actionRefreshRoom ();
                    }
                    dialog.Close ();
                };
            }
            dialog.Show ();
        }
 
        public void ControlScene (string sceneFilePath)
        {
            var tempScene = Scene.GetSceneByFilePath (sceneFilePath);
            if (tempScene == null)
                return;
            showTip = true;
            new System.Threading.Thread (() => {
                int sceneDeviceCount = tempScene.DeviceFilePathList.Count;
                int controlDeviceIndex = 0;
 
                //if (!tempScene.busScene) {
                foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
                    controlDeviceIndex++;
                    //ControlSceneDevice (deviceFilePath, controlDeviceIndex, sceneDeviceCount);
                    //continue;
                    byte [] replyBytes = null;
                    var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                    if(common.Type == DeviceType.FanModule) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;//
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.WindSpeed });
                    } else if (common.Type == DeviceType.LightDimming) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;//
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.LightDALI) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDALI> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        Control.ControlBytesSend (Command.control_lamp_color_Temperature, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurTones_High, device.CurTones_Low }, SendCount.Zero);
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.LightMixDimming) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.PhysicsLoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.LightEnergySwitch) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.LightRGB) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device != null) {
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.DelayTimeHeigh,device.DelayTimeLow,
                                                    3,device.RStatus,device.GStatus,device.BStatus,0,0});
                        }
                    } else if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.LightMixSwitch) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.PhysicsLoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
                    } else if (common.Type == DeviceType.CurtainModel) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.Status });
                    } else if (common.Type == DeviceType.CurtainRoller) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
                    } else if (common.Type == DeviceType.CurtainTrietex) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
                    } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, device.SubnetID, device.DeviceID, new byte [] {
                                                device.LoopID,
                                                device.TemperatureMode,
                                                device.IndoorTemperature,
                                                device.CoolTemperature,
                                                device.HeatTemperature,
                                                device.AutoTemperature,
                                                device.ChuShiTemperature,
                                                device.RealModeAndFanSpeed,
                                                device.Power,
                                                device.SetMode,
                                                device.SetFanSpeed,
                                                device.SetTemperature,
                                                device.ShaoFanMode});
                    } else if (common.Type == DeviceType.ACPanel) {
                        var ac = Newtonsoft.Json.JsonConvert.DeserializeObject<ACPanel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (ac == null) {
                            continue;
                        }
                        byte modeKey = 4;
                        switch (ac.SetMode) {
                        //cooling
                        case 0:
                            modeKey = 4;
                            break;
                        //Heating
                        case 1:
                            modeKey = 7;
                            break;
                        //Fan
                        case 2:
                            modeKey = 2;
                            break;
                        //  Auto
                        case 3:
                            modeKey = 8;
                            break;
                        //Dry
                        case 4:
                            modeKey = 19;
                            break;
                        }
                        Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { modeKey, ac.SetTemperature, ac.LoopID });
                        Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 6, ac.SetMode, ac.LoopID });
                        Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 5, ac.SetFanSpeed, ac.LoopID });
                        Control.ControlBytesSend (Command.InstructionPanelKey, ac.SubnetID, ac.DeviceID, new byte [] { 3, ac.Power, ac.LoopID });
                    } else if (common.Type == DeviceType.FoolHeat) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID,
                                                                        new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature,
                               device.NightTemperature, device.AwayTemperature , 0, 0 });
 
                    } else if (common.Type == DeviceType.FanModule) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.WindSpeed });
                    } else if (common.Type == DeviceType.LogicModule) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] {
                            device.AreaID,device.AreaSceneID});
                    } else if (common.Type == DeviceType.UniversalDevice) {
                        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
                        if (device == null) {
                            continue;
                        }
                        replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, device.SubnetID, device.DeviceID, new byte [] { device.SendBytes [0], device.SendBytes [1] });
                    } else {
                        continue;
                    }
                    try {
                        if (showTip) {
                            if (replyBytes == null) {
                                Application.RunOnMainThread (() => {
                                    string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure);
                                    var btnTip = new Button () {
                                        Height = Application.GetRealHeight (140),
                                        Text = common.Name + tipString + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (),
                                        BackgroundColor = SkinStyle.Current.TitileView,
                                    };
                                    MainPage.MainFrameLayout.AddChidren (btnTip);
                                    btnTip.MouseUpEventHandler += (sender, e) => {
                                        btnTip.RemoveFromParent ();
                                    };
                                    new System.Threading.Thread (() => {
                                        System.Threading.Thread.Sleep (3000);
                                        Application.RunOnMainThread (() => {
                                            btnTip.RemoveFromParent ();
                                            showTip = false;
                                        });
                                    }) { IsBackground = true }.Start ();
                                });
                            }
                        }
                    } catch { }
                }
                //} else {
                if (tempScene.busScene) {
                    foreach (var common in tempScene.GlobalSceneDeviceList) {
                        //ControlBusSceneDevice (common);
                        //continue;
                        byte [] replyBytes = null;
                        switch (common.obj1) {
                        case 0://0   无效 Invalid
                            break;
                        case 85://0x55  场景 Scene ||0x0002
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 86://0x56  序列 Sequence ||0x001A
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSeries, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 88://0x58  通用开关 Universal Switch ||0xe01c
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 89: //0x59  单路调节 Single Channel Lighting Control  0031
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 92://0x5c  窗帘开关 Curtain Switch e3e0
                            replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 94://0x5e  GPRS控制 GPRS Control E3D4
                            replyBytes = Control.ControlBytesSendHasReturn (Command.GPRSControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 95://0x5f  面板控制 Panel Control e3d8
                            replyBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 100://0x64 广播场景 Broadcast Scene ||0x0002  
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 101://0x65 广播回路 Broadcast Channel 0031
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 102://0x66 消防模块 Security Module 011E
                            replyBytes = Control.ControlBytesSendHasReturn (Command.SecurityModule, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                        case 103://0x67 音乐播放 Music Control 0218
                            replyBytes = Control.ControlBytesSendHasReturn (Command.MusicControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            break;
                            //104 通用控制 Universal Control
                            //105 连接页 Link Page
                            //107 RGB调节 RGB Control
                            //108 红外控制 Infrared Control
                            //case 109://109 逻辑灯调节 Logic Light Adjust ||  0xE45E
                            //    replyBytes = Control.ControlBytesSendHasReturn (Command.LogicLightAdjust, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                            //    break;
                            //}
                            //110 逻辑场景 Logic Scene
                            //112 LCD & LED休眠 LCD & LED Sleep
                            //113 服务器控制   Server control
                        }
                    }
                }
            }) { IsBackground = true}.Start();
        }
 
 
 
        //public void ControlSceneDevice (string deviceFilePath, int controlDeviceIndex, int sceneDeviceCount)
        //{
        //    byte [] replyBytes = null;
        //    var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //    if (common.Type == DeviceType.LightDimming) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;//
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.LightDALI) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDALI> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.LightMixDimming) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.PhysicsLoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.LightEnergySwitch) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.LightRGB) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device != null) {
        //            replyBytes = Control.ControlBytesSendHasReturn (Command.SetLogicLoopColor, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, 254, device.DelayTimeHeigh,device.DelayTimeLow,
        //                                            3,device.RStatus,device.GStatus,device.BStatus,0,0});
        //        }
        //    } else if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.LightMixSwitch) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { device.PhysicsLoopID, device.CurrentBrightness, device.DelayTimeHeight, device.DelayTimeLow });
        //    } else if (common.Type == DeviceType.CurtainModel) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { device.LoopID, (byte)device.Status });
        //    } else if (common.Type == DeviceType.CurtainRoller) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
        //    } else if (common.Type == DeviceType.CurtainTrietex) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.Status });
        //    } else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetACMode, device.SubnetID, device.DeviceID, new byte [] {
        //                                        device.LoopID,
        //                                        device.TemperatureMode,
        //                                        device.IndoorTemperature,
        //                                        device.CoolTemperature,
        //                                        device.HeatTemperature,
        //                                        device.AutoTemperature,
        //                                        device.ChuShiTemperature,
        //                                        device.RealModeAndFanSpeed,
        //                                        device.Power,
        //                                        device.SetMode,
        //                                        device.SetFanSpeed,
        //                                        device.SetTemperature,
        //                                        device.ShaoFanMode});
        //    } else if (common.Type == DeviceType.FoolHeat) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID,
        //                                                        new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature,
        //                       device.NightTemperature, device.AwayTemperature , 0, 0 });
 
        //    } else if (common.Type == DeviceType.FanModule) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.WindSpeed });
        //    } else if (common.Type == DeviceType.LogicModule) {
        //        var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
        //        if (device == null) {
        //            return;
        //        }
        //        replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, device.SubnetID, device.DeviceID, new byte [] {
        //                    device.AreaID,device.AreaSceneID});
        //    }
        //    Application.RunOnMainThread (() => {
        //        try {
        //            if (showTip) {
        //                if (replyBytes == null) {
        //                    string tipString = Language.StringByID (R.MyInternationalizationString.ControlFailure);
        //                    var btnTip = new Button () {
        //                        Height = Application.GetRealHeight (140),
        //                        Text = common.Name + tipString + "..." + controlDeviceIndex.ToString () + @"/" + sceneDeviceCount.ToString (),
        //                        BackgroundColor = SkinStyle.Current.TitileView,
        //                    };
        //                    MainPage.MainFrameLayout.AddChidren (btnTip);
        //                    btnTip.MouseUpEventHandler += (sender, e) => {
        //                        MainPage.MainFrameLayout.Remove (btnTip);
        //                    };
        //                    System.Threading.Tasks.Task.Run (() => {
        //                        System.Threading.Thread.Sleep (3000);
        //                        Application.RunOnMainThread (() => {
        //                            MainPage.MainFrameLayout.Remove (btnTip);
        //                            showTip = false;
        //                        });
        //                    });
        //                }
        //            }
        //        } catch { }
        //    });
        //}
 
 
 
        public void ControlBusSceneDevice (Common common)
        {
            byte [] replyBytes = null;
 
            switch (common.obj1) {
            case 0://0   无效 Invalid
                break;
            case 85://0x55  场景 Scene ||0x0002
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 86://0x56  序列 Sequence ||0x001A
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetSeries, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 88://0x58  通用开关 Universal Switch ||0xe01c
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 89: //0x59  单路调节 Single Channel Lighting Control  0031
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 92://0x5c  窗帘开关 Curtain Switch e3e0
                replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 94://0x5e  GPRS控制 GPRS Control E3D4
                replyBytes = Control.ControlBytesSendHasReturn (Command.GPRSControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 95://0x5f  面板控制 Panel Control e3d8
                replyBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 100://0x64 广播场景 Broadcast Scene ||0x0002  
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 101://0x65 广播回路 Broadcast Channel 0031
                replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 102://0x66 消防模块 Security Module 011E
                replyBytes = Control.ControlBytesSendHasReturn (Command.SecurityModule, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
            case 103://0x67 音乐播放 Music Control 0218
                replyBytes = Control.ControlBytesSendHasReturn (Command.MusicControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                break;
                //104 通用控制 Universal Control
                //105 连接页 Link Page
                //107 RGB调节 RGB Control
                //108 红外控制 Infrared Control
                //case 109://109 逻辑灯调节 Logic Light Adjust || 0xE45E
                //    replyBytes = Control.ControlBytesSendHasReturn (Command.LogicLightAdjust, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
                //    break;
                //}
                //110 逻辑场景 Logic Scene
                //112 LCD & LED休眠 LCD & LED Sleep
                //113 服务器控制   Server control
            }
 
        }
 
 
        /// <summary>
        /// 添加或者修改高级网关场景
        /// </summary>
        /// <param name="roomFilePath">Room name.</param>
        /// <param name="ds">代理方法,用来刷新界面</param>
        /// <param name="sceneFilePath">Scene.(为null是表示是增加场景)</param>
        public static void AddOrUpdataSuperGateWaySceneBaseMassage (SuperGateWay.GateWay superGateWay, SuperGateWay.Scene scene, Action refreshAction)
        {
            if (scene == null) {
                scene = new SuperGateWay.Scene { };
            }
 
            #region Load
            var dialog = new Dialog () {
                BackgroundColor = 0xFFF5F6F7,
                Width = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (740),
            };
 
            var btnEquipmentTitle = new Button () {
                Width = Application.GetRealWidth (520),
                Height = Application.GetRealHeight (70),
                BackgroundColor = 0xFF484848,
                TextID = R.MyInternationalizationString.AddNewRoom,
                TextAlignment = TextAlignment.Center,
                Gravity = Gravity.CenterHorizontal,
            };
            dialog.AddChidren (btnEquipmentTitle);
 
            var lblTitleName = new Button () {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight (80),
                Width = Application.GetRealWidth (450),
                Height = Application.GetRealHeight (50),
                TextID = R.MyInternationalizationString.RoomName,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = 0xf01A1A1A,
            };
            dialog.AddChidren (lblTitleName);
 
            var sceneTextBox = new EditText () {
                Gravity = Gravity.CenterHorizontal,
                Y = lblTitleName.Bottom + Application.GetRealHeight (10),
                Width = Application.GetRealWidth (450),
                Height = Application.GetRealHeight (50),
                TextAlignment = TextAlignment.CenterLeft,
                UnSelectedImagePath = "Item/DialogTextBox.png",
                SelectedImagePath = "Item/DialogTextBox.png",
                TextColor = 0xf01A1A1A,
                Text = scene.name,
                BorderWidth = 1,
                BorderColor = 0xff505050,
                Radius = 1,
            };
            dialog.AddChidren (sceneTextBox);
 
            var lblIcon = new Button () {
                Gravity = Gravity.CenterHorizontal,
                Y = sceneTextBox.Bottom + Application.GetRealHeight (10),
                Width = Application.GetRealWidth (450),
                Height = btnEquipmentTitle.Height,
                TextID = R.MyInternationalizationString.Backgroud,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = 0xf01A1A1A,
            };
            dialog.AddChidren (lblIcon);
 
            var verIconLayout = new VerticalScrolViewLayout () {
                Gravity = Gravity.CenterHorizontal,
                Y = lblIcon.Y + lblIcon.Height + Application.GetRealHeight (5),
                Width = sceneTextBox.Width,
                Height = Application.GetRealHeight (200),
                BackgroundImagePath = "Item/RoomIconBackground.png",
            };
            var inVerFramelayout = new FrameLayout () {
                X = 0,
                Width = lblIcon.Width,
                Height = Application.GetRealHeight (200),
            };
            verIconLayout.AddChidren (inVerFramelayout);
            dialog.AddChidren (verIconLayout);
 
            var systempictureLayout = new FrameLayout {
                Height = Application.GetRealHeight (260),
                Y = Application.GetRealHeight (478),
            };
            dialog.AddChidren (systempictureLayout);
 
            var btnBG = new Button () {
                Width = Application.GetRealWidth (270),
                Height = LayoutParams.MatchParent,
                UnSelectedImagePath = scene.BackgoundImagePath,
            };
            inVerFramelayout.AddChidren (btnBG);
 
            var btnTakePictrue = new Button () {
                Width = inVerFramelayout.Width - btnBG.Width,
                Height = inVerFramelayout.Height / 3,
                TextID = R.MyInternationalizationString.TakePhoto,
                TextColor = 0xff000000,
                BackgroundColor = 0xF0D7D7D7,
                X = btnBG.Right,
            };
            inVerFramelayout.AddChidren (btnTakePictrue);
            ///照相点击事件
            Guid guid = Guid.NewGuid ();
            btnTakePictrue.MouseUpEventHandler += (sender, e) => {
                guid = Guid.NewGuid ();
                Camera.TakePicture ((obj) => {
                    if (obj != null) {
                        btnBG.UnSelectedImagePath = guid.ToString ();
                    }
                }, guid.ToString (), false);
            };
 
            var btnLineP = new Button () {
                Width = btnTakePictrue.Width,
                Height = 1,
                BackgroundColor = 0xF0FFFFFF,
                X = btnBG.Right,
                Y = btnTakePictrue.Bottom,
            };
            inVerFramelayout.AddChidren (btnLineP);
 
            var btnSelectPictrue = new Button () {
                Width = btnTakePictrue.Width,
                Height = btnTakePictrue.Height,
                TextColor = 0xff000000,
                TextID = R.MyInternationalizationString.SelectPicture,
                BackgroundColor = 0xF0D7D7D7,
                X = btnBG.Right,
                Y = btnLineP.Bottom,
            };
            inVerFramelayout.AddChidren (btnSelectPictrue);
            ///相册点击事件
            btnSelectPictrue.MouseUpEventHandler += (sender, e) => {
                guid = Guid.NewGuid ();
                Camera.SelectPicture ((obj) => {
                    if (obj != null) {
                        btnBG.UnSelectedImagePath = guid.ToString();
                    }
                }, guid.ToString(), false);
            };
 
            var btnLineS = new Button () {
                Width = btnTakePictrue.Width,
                Height = 1,
                BackgroundColor = 0xF0FFFFFF,
                X = btnBG.Right,
                Y = btnSelectPictrue.Bottom,
            };
            inVerFramelayout.AddChidren (btnLineS);
 
            var btnSelectsystemPictrue = new Button () {
                Width = btnTakePictrue.Width,
                Height = btnTakePictrue.Height,
                TextID = R.MyInternationalizationString.SystemPicture,
                TextColor = 0xff000000,
                BackgroundColor = 0xF0D7D7D7,
                X = btnBG.Right,
                Y = btnLineS.Bottom,
            };
            inVerFramelayout.AddChidren (btnSelectsystemPictrue);
 
            EventHandler<MouseEventArgs> handler = (sender1, e1) => {
                systempictureLayout.RemoveAll ();
                var horizontalScrolViewLayout = new HorizontalScrolViewLayout () {
                    Width = Application.GetRealWidth (500),
                    Height = Application.GetRealHeight (180),
                    Y = Application.GetRealHeight (10),
                    Gravity = Gravity.CenterHorizontal,
                };
                systempictureLayout.AddChidren (horizontalScrolViewLayout);
                for (int i = 0; i < 22; i++) {
                    var butscene = new Button () {
                        Width = Application.GetRealWidth (200),
                        Height = LayoutParams.MatchParent,
                    };
                    butscene.UnSelectedImagePath = "Scene/s" + (i).ToString () + ".png";
                    horizontalScrolViewLayout.AddChidren (butscene);
                    butscene.MouseUpEventHandler += (sender, e) => {
                        btnBG.UnSelectedImagePath = butscene.UnSelectedImagePath;
                    };
                }
            };
            btnSelectsystemPictrue.MouseUpEventHandler += handler;
 
            var BottomView = new FrameLayout () {
                Width = LayoutParams.MatchParent,
                Height = Application.GetRealHeight (90),
                BackgroundColor = 0xF0121212,
                Y = dialog.Height - Application.GetRealHeight (90),
            };
            dialog.AddChidren (BottomView);
            var btnBack = new Button () {
                Width = Application.GetRealWidth (119),
                Height = LayoutParams.MatchParent,
                UnSelectedImagePath = "Item/PositioningDialogBack.png",
                SelectedImagePath = "Item/PositioningDialogBack.png",
            };
            BottomView.AddChidren (btnBack);
            btnBack.MouseUpEventHandler += (sender1, e1) => {
                dialog.Close ();
            };
            var btnLineH = new Button () {
                Width = 1,
                Height = LayoutParams.MatchParent,
                BackgroundColor = 0xF0909090,
                X = btnBack.Right,
            };
            BottomView.AddChidren (btnLineH);
 
            var btnSave = new Button () {
                Width = Application.GetRealWidth (400),
                Height = LayoutParams.MatchParent,
                X = btnLineH.Right,
                TextID = R.MyInternationalizationString.SAVE,
                TextAlignment = TextAlignment.Center,
                Radius = 1,
            };
            BottomView.AddChidren (btnSave);
            #endregion
 
            btnEquipmentTitle.TextID = R.MyInternationalizationString.AddNewScenes;
            lblTitleName.TextID = R.MyInternationalizationString.SceneName;
 
            btnEquipmentTitle.TextID = R.MyInternationalizationString.ChangeInformation;
 
            ///增加或者修改场景
            btnSave.MouseUpEventHandler += (sender, e) => {
                if (string.IsNullOrEmpty (sceneTextBox.Text.Trim ())) {
                    new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterSceneName), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    return;
                }
                ///
                if (null != superGateWay.Scenes.Find ((obj) => obj != scene && obj.uid != scene.uid && obj.name == sceneTextBox.Text.Trim ())) {
                    new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                    return;
                }
                ///新场景名称
                scene.name = sceneTextBox.Text.Trim ();
                Action<SuperGateWay.Scene> a = (obj) => {
                    Application.RunOnMainThread (() => {
                        try {
                            //已经更改过的图片
                            if (btnBG.UnSelectedImagePath == "ScenePicture") {
                                Shared.IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, $"SuperGateWay_BackgoundImage_{scene.sid}");
                                btnBG.UnSelectedImagePath = $"SuperGateWay_BackgoundImage_{scene.sid}";
                            }
                            SuperGateWay.Scene.Add (scene.sid, btnBG.UnSelectedImagePath);
 
                            if (obj == null) {
                                return;
                            }
                            if (superGateWay.Scenes.Find ((o) => o.uid == obj.uid) == null) {
                                superGateWay.Scenes.Add (obj);
                            }
                        } catch { } finally {
                            Application.RunOnMainThread (() => {
                                dialog.Close ();
                                refreshAction ();
                            });
                        }
                    });
                };
 
                if (scene.sid == null) {
                    scene.sid = SuperGateWay.Scene.NewSid;
                    SuperGateWay.Control.AppendScene (scene, a);
                } else {
                    SuperGateWay.Control.ModifyScene (scene, a);
                }
 
                superGateWay.save ("SceneListFilePath");
            };
            dialog.Show ();
        }
 
    }
}