| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Net.Http; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.UI.CSS; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.UI.UI1Login |
| | | { |
| | | public partial class RegisterPage |
| | | { |
| | | |
| | | List<GlobalRegionListRes> serverList; |
| | | |
| | | /// <summary> |
| | | /// 加载事件列表 |
| | | /// </summary> |
| | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取服务器列表 |
| | | /// </summary> |
| | | void getServerList() |
| | | { |
| | | var waitPage = new Loading(); |
| | | bodyView.AddChidren(waitPage); |
| | | waitPage.Start(Language.StringByID(StringId.PleaseWait)); |
| | | |
| | | |
| | | System.Threading.Tasks.Task.Run(() => { |
| | | try |
| | | { |
| | | //string country = "CN"; |
| | | //try |
| | | //{ |
| | | // using (HttpClient client = new HttpClient()) |
| | | // { |
| | | // // 使用 ipinfo.io 获取位置信息 |
| | | // HttpResponseMessage response = await client.GetAsync("https://ipinfo.io/json"); |
| | | // if (response.IsSuccessStatusCode) |
| | | // { |
| | | // string json = await response.Content.ReadAsStringAsync(); |
| | | // JObject jsonObject = JObject.Parse(json); |
| | | // // 从返回的 JSON 中提取国家信息 |
| | | // country = jsonObject["country"].ToString(); |
| | | // } |
| | | // } |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // MainPage.Log("Error",$"Error fetching IP info: {ex.StackTrace}"); |
| | | //} |
| | | |
| | | serverList = new List<GlobalRegionListRes>(); |
| | | var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark }); |
| | | var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost); |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GlobalRegionListRes>>(revertObj.Data.ToString()); |
| | | if (responseDataObj != null) |
| | | { |
| | | serverList = responseDataObj; |
| | | if (serverList.Count > 0) |
| | | { |
| | | if (Language.CurrentLanguage == "Chinese")//if (country == "CN")// |
| | | { |
| | | var server = serverList.Find((obj) => obj.regionUrl.Contains("china-gateway")); |
| | | if (server != null) |
| | | { |
| | | OnAppConfig.Instance.GlobalRegion = server; |
| | | SetServerText(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var server = serverList.Find((obj) => obj.regionUrl.Contains("bahrain-gateway")); |
| | | if (server != null) |
| | | { |
| | | OnAppConfig.Instance.GlobalRegion = server; |
| | | SetServerText(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //提示错误 |
| | | IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log("Error", $"获取服务器异常:{ex.StackTrace}"); |
| | | } |
| | | finally |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | if (waitPage != null) |
| | | { |
| | | waitPage.RemoveFromParent(); |
| | | waitPage = null; |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | } |