public CaptchaPage(AccountModel account) { Resources = Styles.Styles.StyleDictionary; BoxView topSpacer = new BoxView { BackgroundColor = Color.Transparent, VerticalOptions = LayoutOptions.StartAndExpand, }; Entry answerEntry = new Entry { Placeholder = "Answer", Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.EntryStyle.ToString()], VerticalOptions = LayoutOptions.CenterAndExpand, }; Button answerButton = new Button { Text = "Answer", Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.RegularButton.ToString()], VerticalOptions = LayoutOptions.EndAndExpand, }; var mainLayout = new StackLayout { Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.MainLayout.ToString()], Children = { topSpacer, captchaImage, answerEntry, answerButton } }; Content = mainLayout; if (Device.OS == TargetPlatform.iOS) { mainLayout.Padding = new Thickness (0, 20, 0, 0); } answerButton.Clicked += async (sender, e) =>{ if (answerEntry.Text.Length > 0) { answerButton.IsEnabled = false; var s = new LacunaExpress.Data.Server(); var json = Captcha.Solve(account.SessionID, guid, answerEntry.Text); var response = await s.GetHttpResultStringAsyncAsString(account.Server, Captcha.url, json); if (response != null) { var r = Newtonsoft.Json.JsonConvert.DeserializeObject<CaptchaResponse>(response); if(r.result==1){ var oldacnt = account; account.CaptchaLastRenewed = DateTime.Now; AccountManager accountMan = new AccountManager(); accountMan.ModifyAccountAsync(account, oldacnt); await Navigation.PopModalAsync(); } else { answerButton.IsEnabled = true; GetCaptcha(account); answerEntry.Text = ""; } } else { answerButton.IsEnabled = true; GetCaptcha(account); answerEntry.Text = ""; } } }; this.Appearing += async (sender, e) => { var captchaValidUntil = DateTime.Now.AddMinutes(-25); if (account.CaptchaLastRenewed > captchaValidUntil) { await Navigation.PopModalAsync(); }else { GetCaptcha(account); } }; }
async Task<bool> LoadPage(Boolean typeStation){ AccountManager accountMan = new AccountManager(); account = await accountMan.GetActiveAccountAsync(); var originalAccount = account; if (typeStation) { bodyList.Clear(); foreach(var s in account.Stations.Keys) { var json = LacunaExpanseAPIWrapper.Body.GetBuildings(1, account.SessionID, s); var server = new LacunaExpress.Data.Server(); var response = await server.GetHttpResultAsync(account.Server, LacunaExpanseAPIWrapper.Body.url, json); if (response.result != null) { BodyStatusModel bdy = new BodyStatusModel(); bdy.response = response; bdy.Name = response.result.status.body.name; bdy.Star = response.result.status.body.star_name; bdy.Zone = response.result.status.body.zone; bdy.X = response.result.status.body.x; bdy.Y = response.result.status.body.y; if (!Scripts.StatusCheckers.StationOk(response)) { bdy.Status = "Warning"; notifyAllianceOfStations.IsVisible = true; warningStations.Add(bdy.Name +"{ Planet "+bdy.Name+" "+ response.result.status.body.id+" }"); } bodyList.Add(bdy); if (response.result.buildings != null) { foreach(var b in response.result.buildings) { if (account.Parliaments == null) account.Parliaments = new List<BuildingCache>(); if(b.Value.url.Contains(Parliament.URL)) account.Parliaments.Add(new BuildingCache { planetID = b.Value.name, buildingID = b.Key, level = Convert.ToInt16(b.Value.level) }); } //var parliament = (from p in response.result.buildings // where p.Value.url.Contains(Parliament.URL) // select new { id = p.Key, level = p.Value.level, }).First(); //account.Parliaments.Add(new BuildingCache { planetID = bdy.Name, buildingID = parliament.id, level = Convert.ToInt16(parliament.level) }); } } } if(account.Parliaments.Count >0) accountMan.ModifyAccountAsync(account, originalAccount); } else { bodyList.Clear(); foreach (var c in account.Colonies.Keys) { var json = LacunaExpanseAPIWrapper.Body.GetBuildings(1, account.SessionID, c); var s = new LacunaExpress.Data.Server(); var response = await s.GetHttpResultAsync(account.Server, LacunaExpanseAPIWrapper.Body.url, json); if (response.result != null) { BodyStatusModel bdy = new BodyStatusModel(); bdy.response = response; bdy.Name = response.result.status.body.name; bdy.Star = response.result.status.body.star_name; bdy.Zone = response.result.status.body.zone; bdy.X = response.result.status.body.x; bdy.Y = response.result.status.body.y; if (!Scripts.StatusCheckers.PlanetOk(response)) bdy.Status = "Warning"; bodyList.Add(bdy); } //BodyStatus bodyresult = response.result.Bodies; //(BodyStatus)bodyresult = } } return true; }