wxr
2023-07-26 1018d2975dc7facf691307f7504b90f84e07a54b
迁移更新
1个文件已修改
146 ■■■■ 已修改文件
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs 146 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/MigrationServer.cs
@@ -19,7 +19,8 @@
        private bool finish = false;
#if DEBUG
        private string SeverAddr = "https://test-gz.hdlcontrol.com";
        //private string SeverAddr = "https://test-gz.hdlcontrol.com";
        private string SeverAddr = "https://bahrain-gateway.hdlcontrol.com";
#else
        private string SeverAddr = "https://bahrain-gateway.hdlcontrol.com";
#endif
@@ -188,16 +189,16 @@
 
                Account2New ("12345678");
                Home2New ();
                //迁移云端其他备份
                var moveCloudDataResult = MoveCloudBackup ();
                Application.RunOnMainThread (() => {
                    btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}";
                    btnTipMsg.TextColor = SkinStyle.Current.DelColor;
                    loading.Hide ();
                    return;
                });
                //Account2New ("12345678");
                //Home2New ();
                ////迁移云端其他备份
                //var moveCloudDataResult = MoveCloudBackup ();
                //Application.RunOnMainThread (() => {
                //    btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}";
                //    btnTipMsg.TextColor = SkinStyle.Current.DelColor;
                //    loading.Hide ();
                //    return;
                //});
#endif
                if (etPwd.Text.Trim() == "") {
@@ -688,8 +689,6 @@
                GatewayBase common = null;
                string gateWayString = "";
                if (gateWayList.Count > 0) {
                    foreach (var gatewayFileName in gateWayList) {
                        var tempStrings = gatewayFileName.Split ('_');
                        if (tempStrings [1].ToString () == DeviceType.OnePortBus.ToString () || tempStrings [1].ToString () == DeviceType.RCU.ToString () ||
@@ -898,6 +897,8 @@
                                //获取上网秘钥
                                var netKet = GetInternetAccessKey (common.MAC.Replace (".", ""));
                                if (!string.IsNullOrEmpty (netKet)) {
                                    Application.RunOnMainThread (() => {
                                        btnTipMsg.Text = "The Internet access key was obtained successfully. It is being written.";
@@ -928,6 +929,110 @@
                                            return;
                                        });
                                    }
#if DEBUG
                                    System.Threading.Thread.Sleep (5000);
#endif
                                    CommonPage.FindGateway = true;
                                    try {
                                        #region 搜索设备
                                        CommonPage.LocalPhoneFindDevice = true;
                                        CommonPage.RandomHigh = (byte)new Random ().Next (255);
                                        CommonPage.RandomLow = (byte)new Random ().Next (255);
                                        CommonPage.GateWayList.Clear ();
                                        CommonPage.FindGateway = true;
                                        //如果两次都没有数据反馈,就不读取
                                        int readCount = 2;
                                        while (0 < readCount) {
                                            readCount--;
                                            System.IO.MemoryStream ms = new System.IO.MemoryStream ();
                                            ms.WriteByte (CommonPage.RandomHigh);
                                            ms.WriteByte (CommonPage.RandomLow);
                                            List<Common> list = CommonPage.GateWayList;
                                            int tempCount = list.Count;
                                            string s = ";";
                                            for (int i = 0; i < list.Count; i++) {
                                                Common common2 = list [i];
                                                if (s.Contains (";" + common2.SubnetID.ToString () + ":" + common2.DeviceID.ToString ()))
                                                    continue;
                                                s += common2.SubnetID.ToString () + ":" + common2.DeviceID.ToString () + ";";
                                                ms.WriteByte (common2.SubnetID);
                                                ms.WriteByte (common2.DeviceID);
                                            }
                                            Control control = new Control ();
                                            Console.WriteLine ("组播搜索网关,搜索地址是:" + CommonPage.EndPoint.ToString () + "    " + CommonPage.GateWayList.Count);
                                            control.Send (new Target () {
                                                IPEndPoint = CommonPage.EndPoint,
                                                Command = Command.ReadGateway,
                                                SubnetID = 0xFF,
                                                DeviceID = 0xFF,
                                                AddData = ms.ToArray ()
                                            }, SendCount.Zero, false);
                                            Console.WriteLine ("广播搜索网关,搜索地址是:" + new Net.NetWiFi ().BroadcastIpAddress.ToString () + "    " + CommonPage.GateWayList.Count);
                                            control.Send (new Target () {
                                                IPEndPoint = new System.Net.IPEndPoint (new Net.NetWiFi ().BroadcastIpAddress, 6000),
                                                Command = Command.ReadGateway,
                                                SubnetID = 0xFF,
                                                DeviceID = 0xFF,
                                                AddData = ms.ToArray ()
                                            }, SendCount.Zero, false);
                                            System.Threading.Thread.Sleep (800);
                                            //如果数量不相等,就重置次数
                                            if (tempCount != CommonPage.GateWayList.Count) {
                                                readCount = 2;
                                            }
                                        }
                                        CommonPage.FindGateway = false;
                                        CommonPage.LocalPhoneFindDevice = false;
                                        #endregion
                                    } catch (Exception ex) {
                                        Console.WriteLine (ex.ToString ());
                                    } finally {
                                        if (CommonPage.GateWayList.Count > 0) {
                                            foreach (var gateway1 in CommonPage.GateWayList) {
                                                var bingResidenceIdBytes = Control.ControlBytesSendHasReturn (Command.Read_APP_Data_STORE_1D5C_CMD, common.SubnetID, common.DeviceID, new byte [] { });
                                                if (bingResidenceIdBytes == null) {
                                                    continue;
                                                }
                                                int bingResideceId = 0;
                                                for (int i = 0; i < bingResidenceIdBytes.Length; i++) {
                                                    bingResideceId += (int)(bingResidenceIdBytes [i] * Math.Pow (256, 3 - i));
                                                }
                                                if (bingResideceId != UserConfig.Instance.CurrentRegion.RegionID && bingResideceId != 0) {
                                                } else {
                                                    //写入上网秘钥
                                                    writeSecretKeyResult = WriteSecretKey (gateway1.SubnetID, gateway1.DeviceID, secretkeySendBytes);
                                                    if (writeSecretKeyResult) {
                                                        Application.RunOnMainThread (() => {
                                                            btnTipMsg.Text = "The Internet access key was written successfully.";
                                                        });
                                                    } else {
                                                        Application.RunOnMainThread (() => {
                                                            btnTipMsg.Text = "Failed to write Internet secret key.";
                                                            btnTipMsg.TextColor = SkinStyle.Current.DelColor;
                                                        });
                                                    }
#if DEBUG
                                                    System.Threading.Thread.Sleep (5000);
#endif
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    Application.RunOnMainThread (() => {
                                        btnTipMsg.Text = "Failed to obtain the Internet secret key. Please try again.";
@@ -937,7 +1042,6 @@
                                }
                                //写入mqtt域名信息
                                SetGateWayMqttUrlAddress (common.SubnetID, common.DeviceID);
                                //迁移网关
                                var moveGatewayResult = Gateway2New (common.MAC.Replace (".", ""), newHomeId, common.SubnetID);
@@ -956,12 +1060,14 @@
                                }
                                //迁移云端其他备份
                                var moveCloudDataResult = MoveCloudBackup ();
                                Application.RunOnMainThread (() => {
                                    btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}";
                                    btnTipMsg.TextColor = SkinStyle.Current.DelColor;
                                    loading.Hide ();
                                    return;
                                });
                                if (moveCloudDataResult != "0") {
                                    Application.RunOnMainThread (() => {
                                        btnTipMsg.Text = $"Failed to migrate cloud backup list.{moveCloudDataResult}";
                                        btnTipMsg.TextColor = SkinStyle.Current.DelColor;
                                        loading.Hide ();
                                        return;
                                    });
                                }
                                //创建迁移备份文件夹
                                var backId = moveFolder2New (newHomeId);
                                //迁移备份文件