| | |
| | | { |
| | | public class GuideAddResidence : FrameLayout |
| | | { |
| | | public bool IsHideBack = false; |
| | | |
| | | |
| | | public GuideAddResidence () |
| | | { |
| | | BackgroundColor = SkinStyle.Current.MainColor; |
| | | } |
| | | |
| | | public void ShowHomeList (bool showDialog = true) |
| | | public void ShowHomeList (bool showDialog = false) |
| | | { |
| | | new System.Threading.Thread (() => { |
| | | bool needHide = true; |
| | |
| | | }); |
| | | } |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | UserConfig.Instance.CurrentRegion = responseDataObj.Find ((obj) => obj.Name == UserConfig.Instance.CurrentRegion.Name); |
| | | UserConfig.Instance.CurrentRegion = responseDataObj.Find ((obj) => obj.Id == UserConfig.Instance.CurrentRegion.Id); |
| | | } else { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | |
| | | }; |
| | | topView.AddChidren (ItemButton); |
| | | ItemButton.MouseUpEventHandler += (sender1, e1) => { |
| | | GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | //GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | GuideAddHomeDialog (new RegionInfoRes () { Id = "", Name = "" }, false); |
| | | }; |
| | | if (showDialog) { |
| | | if (!IsHideBack) { |
| | | var back = new Button () { |
| | | Height = Application.GetRealHeight (90), |
| | | Width = Application.GetRealWidth (85), |
| | |
| | | } |
| | | } catch { } |
| | | |
| | | if (UserConfig.Instance.GatewayList !=null && UserConfig.Instance.GatewayList.Count == 0) { |
| | | //if (UserConfig.Instance.GatewayList != null && UserConfig.Instance.GatewayList.Count == 0) { |
| | | // if (showDialog) { |
| | | // GuideAddHomeDialog (UserConfig.Instance.HomeLists [0], true); |
| | | // UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | | // } |
| | | //} |
| | | |
| | | if (!UserConfig.Instance.CheckHomeGateways()) { |
| | | if (showDialog) { |
| | | GuideAddHomeDialog (UserConfig.Instance.HomeLists [0], true); |
| | | UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | |
| | | }); |
| | | var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = password }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj); |
| | | var revertObj = MainPage.RequestHttps (API.Login, requestJson, false, false); |
| | | var revertObj = MainPage.RequestHttps (API.Login, requestJson); |
| | | if (revertObj.StateCode.ToUpper() == "SUCCESS") { |
| | | |
| | | var requestObj2 = new DelHomeObj () { HomeId = home.Id }; |
| | | var requestObj2 = new DelHomeObj () { |
| | | HomeId = home.Id, |
| | | LoginAccessToken = MainPage.LoginUser.LoginTokenString |
| | | }; |
| | | var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); |
| | | var revertObj2 = MainPage.RequestHttps (API.DelHome, requestJson2); |
| | | if (revertObj2.StateCode.ToUpper () == "SUCCESS") { |
| | |
| | | if (stateCodeStr == "NoLogin") { |
| | | mes = ErrorCode.NoLogin; |
| | | } else if (stateCodeStr == "CurrentHomeExixtsGatewayBind") { |
| | | mes = ErrorCode.HomeIdAndTokenNoConsistent; |
| | | mes = ErrorCode.CurrentHomeExixtsGatewayBind; |
| | | } else if (stateCodeStr == ErrorCode.NetworkError) { |
| | | mes = ErrorCode.NetworkError; |
| | | } else { |
| | |
| | | /// <param name="gatewayMAC">Gateway mac.</param> |
| | | void ChangeRegion (RegionInfoRes home, bool goHomePage = true) |
| | | { |
| | | if (home == null || string.IsNullOrEmpty (home.Id)) return; |
| | | |
| | | MainPage.Loading.Start ("Please wait..."); |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | try { |
| | | //if (home.RegionID != UserConfig.Instance.CurrentRegion.RegionID) { |
| | | var backuplist = IO.FileUtils.ReadFiles (); |
| | | int index = 0; |
| | | if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) { |
| | | if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Id)) { |
| | | UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0]; |
| | | } |
| | | string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Name); |
| | | string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Id); |
| | | IO.FileUtils.DeleteRegionFiles (oldRegionRootPath); |
| | | foreach (var fileName in backuplist) { |
| | | System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName); |
| | |
| | | }); |
| | | } |
| | | IO.FileUtils.DeleteAllFile (); |
| | | string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.Name); |
| | | string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.Id); |
| | | IO.FileUtils.RestoreRegionFiles (newRegionRootPath); |
| | | UserConfig.Instance.CurrentRegion = home; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | Room.InitAllRoom (); |
| | | Application.RunOnMainThread (() => { |
| | | ShowHomeList (); |
| | | ShowHomeList (false); |
| | | if (goHomePage) { |
| | | UserConfig.Instance.RefreshUserConfig (); |
| | | new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully), |
| | |
| | | } |
| | | if (isChangeName) { |
| | | home.Name = button.Text = etZoneName.Text; |
| | | var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = home.Name }; |
| | | var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = home.Name, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; |
| | | string urlHead = MainPage.RequestHttpsHost; |
| | | if (requestObj2.IsOtherAccountCtrl) { |
| | | urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; |
| | | requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken; |
| | | } |
| | | |
| | | var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2, urlHead); |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | return; |
| | | } |
| | | ChangeRegion (home, false); |
| | | var addGatewayDialog = new GuideAddGateway (); |
| | | if (guide) { |
| | | |
| | | //ShowHomeList (); |
| | | EditResidence (home, etZoneName.Text.Trim ()); |
| | | UserMiddle.guidePageView.AddChidren (addGatewayDialog); |
| | | addGatewayDialog.ShowPage (home);//guidePageView |
| | | UserMiddle.guidePageView.PageIndex = 1; |
| | | } else { |
| | | UserMiddle.SettingPageView.AddChidren (addGatewayDialog); |
| | | addGatewayDialog.ShowPage (home); |
| | | UserMiddle.SettingPageView.PageIndex = 2; |
| | | EditResidence (home, etZoneName.Text.Trim ()); |
| | | //UserMiddle.SettingPageView.AddChidren (addGatewayDialog); |
| | | //addGatewayDialog.ShowPage (home); |
| | | //UserMiddle.SettingPageView.PageIndex = 2; |
| | | } |
| | | }; |
| | | |
| | |
| | | return false; |
| | | } |
| | | } else { |
| | | var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = home.Name }; |
| | | var requestObj2 = new EditHomeObj () { HomeId = home.Id, Name = home.Name, LoginAccessToken = MainPage.LoginUser.LoginTokenString }; |
| | | string urlHead = MainPage.RequestHttpsHost; |
| | | if (requestObj2.IsOtherAccountCtrl) { |
| | | urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl; |
| | | requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken; |
| | | } |
| | | var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2); |
| | | var revertObj2 = MainPage.RequestHttps (API.EditHome, requestJson2, urlHead); |
| | | IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.Name, home.Name); |
| | | if (revertObj2.StateCode.ToUpper() != "SUCCESS") { |
| | | ShowEditHomeErrorInfo (revertObj2.StateCode); |
| | | return false; |
| | | } |
| | | } |
| | | UserConfig.Instance.CurrentRegion = home; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | |
| | | ShowHomeList (false); |
| | | //2020-01-09 去掉切换住宅 |
| | | //UserConfig.Instance.CurrentRegion = home; |
| | | //UserConfig.Instance.SaveUserConfig (); |
| | | } |
| | | if (Room.Lists.FindAll ((obj) => obj.Name == "Living Room" || obj.Name == "Bedroom").Count == 0) { |
| | | Room room = new Room (); |