From a93db4940a37fd73a37dd9b237c16e744e36f9ea Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 30 八月 2022 10:24:45 +0800
Subject: [PATCH] 迁移升级网关之后修改网关子网号
---
Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs | 242 ++++++++++++++++++++++++++++++++++++------------
1 files changed, 180 insertions(+), 62 deletions(-)
diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs
index 626e0ad..2101637 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/User/UserSettingView.cs
@@ -73,7 +73,7 @@
Height = Application.GetRealHeight (50),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
- Text = MainPage.LoginUser.Name == "" ? Language.StringByID(R.MyInternationalizationString.Account) : MainPage.LoginUser.Name,
+ Text = MainPage.LoginUser.Name == "" ? Language.StringByID (R.MyInternationalizationString.Account) : MainPage.LoginUser.Name,
//TextID = R.MyInternationalizationString.Account
};
topUserMsgView.AddChidren (btnUserName);
@@ -101,7 +101,7 @@
};
topUserMsgView.AddChidren (btnTopUserMsgRight);
-
+
EventHandler<MouseEventArgs> accountEventHandler = (sender, e) => {
new AccountLogin ().Show ();
};
@@ -208,44 +208,6 @@
#endregion
- #region ---鏁版嵁鎺ユ敹---
- //if (MainPage.LoginUser.AccountType == 2 || MainPage.LoginUser.AccountString == @"464027401@qq.com") {
- // var DataReceptionView = new FrameLayout () {
- // Width = Application.GetRealWidth (640),
- // Height = Application.GetRealHeight (100),
- // BackgroundColor = SkinStyle.Current.ViewColor
- // };
- // UserMiddle.SettingView.AddChidren (DataReceptionView);
- // var btnDataReceptionIcon = new Button () {
- // X = Application.GetRealWidth (30),
- // Gravity = Gravity.CenterVertical,
- // Width = Application.GetRealWidth (75),
- // Height = Application.GetRealHeight (75),
- // UnSelectedImagePath = "AccountSettings/DataShared.png"
- // };
- // DataReceptionView.AddChidren (btnDataReceptionIcon);
- // var btnDataReceptionTitle = new Button () {
- // X = Application.GetRealWidth (125),
- // TextAlignment = TextAlignment.CenterLeft,
- // TextID = R.MyInternationalizationString.DataReception,
- // TextColor = SkinStyle.Current.TextColor1,
- // };
- // DataReceptionView.AddChidren (btnDataReceptionTitle);
- // EventHandler<MouseEventArgs> DataReceptionEventHandler = (sender, e) => {
- // GoData ();
- // };
- // DataReceptionView.MouseUpEventHandler += DataReceptionEventHandler;
- // btnDataReceptionIcon.MouseUpEventHandler += DataReceptionEventHandler;
- // btnDataReceptionTitle.MouseUpEventHandler += DataReceptionEventHandler;
- // Button btnNull3 = new Button () {
- // BackgroundColor = SkinStyle.Current.MainColor,
- // Height = Application.GetRealHeight (5)
- // };
- // UserMiddle.SettingView.AddChidren (btnNull3);
- //}
- #endregion
-
-
#region ---msg---
//FrameLayout WarningMsgView = new FrameLayout () {
// Width = Application.GetRealWidth (640),
@@ -343,7 +305,7 @@
Gravity = Gravity.CenterVertical,
Width = Application.GetRealWidth (75),
Height = Application.GetRealHeight (75),
- UnSelectedImagePath = "CrabtreeAdd/Alexa.png",
+ UnSelectedImagePath = "CrabtreeAdd/Alexa.png",
};
AlexaView.AddChidren (btnAlexaIcon);
@@ -390,7 +352,7 @@
Button btnSubaccountTitle = new Button () {
X = Application.GetRealWidth (125),
TextAlignment = TextAlignment.CenterLeft,
- Text= "User Management",
+ Text = "User Management",
TextColor = SkinStyle.Current.TextColor1,
};
subaccountView.AddChidren (btnSubaccountTitle);
@@ -433,6 +395,45 @@
subaccountView.MouseUpEventHandler += SubaccountEventHandler;
btnSubaccountIcon.MouseUpEventHandler += SubaccountEventHandler;
btnSubaccountTitle.MouseUpEventHandler += SubaccountEventHandler;
+ }
+ #endregion
+
+
+ #region ---娴嬭瘯鎸夐挳---
+ //if (UserConfig.Instance.internetStatus == 2) {
+ if (true) {
+ var ConmmunicationTestView = new FrameLayout () {
+ Width = Application.GetRealWidth (640),
+ Height = Application.GetRealHeight (100),
+ BackgroundColor = SkinStyle.Current.ViewColor
+ };
+ UserMiddle.SettingView.AddChidren (ConmmunicationTestView);
+ var btnConmmunicationTestIcon = new Button () {
+ X = Application.GetRealWidth (30),
+ Gravity = Gravity.CenterVertical,
+ Width = Application.GetRealWidth (75),
+ Height = Application.GetRealHeight (75),
+ UnSelectedImagePath = "AccountSettings/DataShared.png"
+ };
+ ConmmunicationTestView.AddChidren (btnConmmunicationTestIcon);
+ var btnConmmunicationTestTitle = new Button () {
+ X = Application.GetRealWidth (125),
+ TextAlignment = TextAlignment.CenterLeft,
+ Text = "Communication test",
+ TextColor = SkinStyle.Current.TextColor1,
+ };
+ ConmmunicationTestView.AddChidren (btnConmmunicationTestTitle);
+ EventHandler<MouseEventArgs> ConmmunicationTestEventHandler = (sender, e) => {
+ GoData ();
+ };
+ ConmmunicationTestView.MouseUpEventHandler += ConmmunicationTestEventHandler;
+ btnConmmunicationTestIcon.MouseUpEventHandler += ConmmunicationTestEventHandler;
+ btnConmmunicationTestTitle.MouseUpEventHandler += ConmmunicationTestEventHandler;
+ Button btnNull3 = new Button () {
+ BackgroundColor = SkinStyle.Current.MainColor,
+ Height = Application.GetRealHeight (5)
+ };
+ UserMiddle.SettingView.AddChidren (btnNull3);
}
#endregion
@@ -494,13 +495,48 @@
static void GoData ()
{
+
+ var localFileList = IO.FileUtils.ReadFiles ();
+ var gateWayList = localFileList.FindAll ((obj) => {
+ return (obj.StartsWith ("Equipment_")) && (
+ obj.Split ('_') [1].ToString () == DeviceType.OnePortBus.ToString () ||
+ obj.Split ('_') [1].ToString () == DeviceType.OnePortWirelessFR.ToString ());
+ });
+ GatewayBase common = null;
+ string gateWayString = "";
+ if (gateWayList.Count == 0) {
+ new Alert ("", "No gateway data was found on the phone.", "Close").Show ();
+ return;
+ }
+ if (gateWayList.Count > 0) {
+ foreach (var gatewayFileName in gateWayList) {
+ var tempStrings = gatewayFileName.Split ('_');
+ if (tempStrings [1].ToString () == DeviceType.OnePortBus.ToString () ||
+ tempStrings [1].ToString () == DeviceType.OnePortWirelessFR.ToString ()) {
+ gateWayString = CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (gatewayFileName));
+ common = Newtonsoft.Json.JsonConvert.DeserializeObject<GatewayBase> (gateWayString);
+
+ if (common.MAC.Replace (".", "") == UserConfig.Instance.GatewayMAC.Replace (".", "")) {
+ if (!string.IsNullOrEmpty (common.Remote_UserName) && !string.IsNullOrEmpty (common.Remote_Password) &&
+ !string.IsNullOrEmpty (common.Remote_GroupName) && !string.IsNullOrEmpty (common.Remote_ProjectName)) {
+ break;
+ }
+ }
+ common = null;
+ }
+ }
+ } else {
+ return;
+ }
+
+
Dialog dialog = new Dialog ();
FrameLayout MianBody = new FrameLayout ();
dialog.AddChidren (MianBody);
FrameLayout bodyView = new FrameLayout () {
Width = Application.GetRealWidth (500),
- Height = Application.GetRealHeight (430),
+ Height = Application.GetRealHeight (540),
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight (250),
Radius = 5,
@@ -516,6 +552,7 @@
TextSize = 18,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.DialogTextColor,
+ Text = "Conmmunication Test"
};
bodyView.AddChidren (topButton);
Button btnIP = new Button () {
@@ -529,30 +566,34 @@
};
bodyView.AddChidren (btnIP);
- EditText etIP = new EditText () {
+ Button btnLocalTest = new Button () {
+ Width = Application.GetRealWidth (400),
+ Height = Application.GetRealHeight (60),
+ X = Application.GetRealWidth (50),
+ Y = btnIP.Bottom,
+ TextAlignment = TextAlignment.CenterLeft,
+ TextColor = SkinStyle.Current.TextColor,
+ Enable = false,
+ IsMoreLines = true,
+ };
+ bodyView.AddChidren (btnLocalTest);
+
+
+ Button btnSeverTest = new Button () {
Width = Application.GetRealWidth (400),
Height = Application.GetRealHeight (80),
X = Application.GetRealWidth (50),
- Y = btnIP.Bottom,
- TextAlignment = TextAlignment.Center,
+ Y = btnLocalTest.Bottom + Application.GetRealHeight (30),
+ TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor,
- Radius = 5,
- BorderColor = SkinStyle.Current.BorderColor,
- BorderWidth = 2,
+ IsMoreLines = true,
Enable = false
};
- bodyView.AddChidren (etIP);
-
- CommonPage.InitHttpListener ();
- topButton.TextID = R.MyInternationalizationString.DataReception;
-
- string ipAddressString = new Net.NetWiFi ().IpAddress == null ? "null" : new Net.NetWiFi ().IpAddress.ToString ();
- btnIP.TextID = R.MyInternationalizationString.IPAddresses;
- etIP.Text = ipAddressString;
+ bodyView.AddChidren (btnSeverTest);
Button btnCloseSharing = new Button () {
X = Application.GetRealWidth (50),
- Y = etIP.Bottom + Application.GetRealHeight (40),
+ Y = btnSeverTest.Bottom + Application.GetRealHeight (40),
Width = Application.GetRealWidth (400),
Height = Application.GetRealHeight (80),
SelectedBackgroundColor = SkinStyle.Current.ButtonColor,
@@ -561,7 +602,7 @@
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 2,
- TextID = R.MyInternationalizationString.CloseDataSharing,
+ Text = "Close",
TextColor = SkinStyle.Current.DialogTextColor
};
bodyView.AddChidren (btnCloseSharing);
@@ -570,12 +611,89 @@
};
btnCloseSharing.MouseUpEventHandler += (sender2, e2) => {
btnCloseSharing.IsSelected = false;
- CommonPage.CloseHttpListener ();
- Room.InitAllRoom ();
dialog.Close ();
};
dialog.Show ();
- }
+ new System.Threading.Thread (() => {
+ Application.RunOnMainThread (() => {
+ MainPage.Loading.Start ();
+ });
+
+ //2020-07-23 杩炴帴WiFi鎵嶆娴嬫湰鍦�
+ if (UserConfig.Instance.internetStatus == 2) {
+ CommonPage.IsRemote = false;
+ CommonPage.FindGateway = true;
+ var result = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, common.SubnetID, common.DeviceID, new byte [] { }, false);
+ CommonPage.FindGateway = false;
+ if (result != null) {
+ Application.RunOnMainThread (() => {
+ btnLocalTest.Text = "Local UDP communication : succeeded.";
+ });
+ } else {
+ Application.RunOnMainThread (() => {
+ btnLocalTest.Text = "Local UDP communication : failed.";
+ });
+ }
+
+ }
+
+ //UDP communication to Sever : succeeded.
+ var gateWay = Newtonsoft.Json.JsonConvert.DeserializeObject<GatewayBase> (gateWayString);
+
+ try {
+ if (!SystemRemote.checeInternet ()) {
+ MainPage.AddTip (Language.StringByID (R.MyInternationalizationString.CheckInternet));
+ Application.RunOnMainThread (() => {
+ btnSeverTest.Text = "Http communication to Sever : failed.";
+ return;
+ });
+ } else {
+ CommonPage.IsRemote = true;
+
+ byte [] userNameBytes = CommonPage.MyEncodingGB2312.GetBytes (gateWay.Remote_UserName);
+ byte [] projectBytes = CommonPage.MyEncodingGB2312.GetBytes (gateWay.Remote_ProjectName);
+ byte [] firstBytes = new byte [28];
+ //鐢ㄦ埛鍚�
+ System.Array.Copy (userNameBytes, 0, firstBytes, 0, 8 < userNameBytes.Length ? 8 : userNameBytes.Length);
+ //宸ョ▼澶囨敞
+ System.Array.Copy (projectBytes, 0, firstBytes, 8, 20 < projectBytes.Length ? 20 : projectBytes.Length);
+
+ byte [] firstReturnBytes = Control.ControlBytesSendHasReturn (Command.RemoteFirst, 251, 251, firstBytes);
+ //杩炴帴涓嶅埌杩滅▼鏈嶅姟鍣�
+ if (firstReturnBytes == null) {
+ Application.RunOnMainThread (() => {
+ btnSeverTest.Text = "UDP communication to Sever : failed.";
+ return;
+ });
+ }
+ //浠庢湇鍔″櫒鑾峰彇鐢ㄦ埛杩滅▼杩炴帴鐨勪俊鎭�
+ else {
+ if (firstReturnBytes [0] == 0) {
+ Application.RunOnMainThread (() => {
+ btnSeverTest.Text = "Gateway UDP communication to Sever : failed.";
+ return;
+ });
+ } else {
+ Application.RunOnMainThread (() => {
+ btnSeverTest.Text = "UDP communication to Sever : succeeded.";
+ return;
+ });
+ }
+ }
+ //Application.RunOnMainThread (() => {
+ // btnSeverTest.Text = "UDP communication to Sever : succeeded.";
+ // return;
+ //});
+ }
+ } catch (Exception ex) {
+ Console.WriteLine (ex.Message);
+ } finally {
+ Application.RunOnMainThread (() => {
+ MainPage.Loading.Hide ();
+ });
+ }
+ }) { IsBackground = true }.Start ();
+ }
}
}
\ No newline at end of file
--
Gitblit v1.8.0