public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (result != null) { if (requestCode == APIRequest.requestCodeType.Register) { JsonObject json = JsonObject.Parse(result); if (!json.ContainsKey("error")) { Frame.Navigate(typeof(Login)); Frame.BackStack.Clear(); } else { ErrorField.Text = json.GetNamedString("error"); } } } else { var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Server request failed.")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Server is down or you lost internet connection.")); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); } }
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (result != null) { if (requestCode == APIRequest.requestCodeType.SetLimit) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { if (NavigateBack != null) { NavigateBack(); } } } } else { var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Server request failed.")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Server is down or you lost internet connection.")); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); } }
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (result != null) { if (requestCode == APIRequest.requestCodeType.Portfolio) { Items.Clear(); JsonArray json = JsonArray.Parse(result); foreach (var share in json) { JsonObject shareObj = share.GetObject(); string symbol = shareObj.GetNamedString("symbol"); string name = shareObj.GetNamedString("name"); double value = shareObj.GetNamedNumber("value"); bool isMain = shareObj.GetNamedBoolean("is_main"); Quotation q = new Quotation() { Name = name, Symbol = symbol, Value = value, IsMain = isMain }; Items.Add(q); } } else if (requestCode == APIRequest.requestCodeType.PortfolioAdd) { RefreshPortfolio(); } else if (requestCode == APIRequest.requestCodeType.UpdateUri) { // update sucessfull } else if (requestCode == APIRequest.requestCodeType.Logout) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); view.LogoutHandler(!json.ContainsKey("error")); } } else { var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Server request failed.")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Server is down or you lost internet connection.")); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); } }
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (result != null) { if (requestCode == APIRequest.requestCodeType.Login) { JsonObject json = JsonObject.Parse(result); if (!json.ContainsKey("error")) { var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; JsonObject user = json.GetNamedObject("user"); localSettings.Values["token"] = json.GetNamedString("token"); if (user.GetNamedValue("main_share").ValueType != JsonValueType.Null) { localSettings.Values["main_share"] = user.GetNamedNumber("main_share"); } localSettings.Values["username"] = user.GetNamedString("login"); Frame.Navigate(typeof(MainPage)); Frame.BackStack.Clear(); } else { ErrorField.Text = json.GetNamedString("error"); } } } else { var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Server request failed.")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Server is down or you lost internet connection.")); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); } }
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (requestCode == APIRequest.requestCodeType.AllShares) { if (result != null) { JsonArray json = JsonArray.Parse(result); foreach (var share in json) { JsonObject shareObj = share.GetObject(); string symbol = shareObj.GetNamedString("symbol"); string name = shareObj.GetNamedString("name"); Quotation q = new Quotation() { Name = name, Symbol = symbol }; allItems.Add(q); } } } }
public void onTaskCompleted(string result, APIRequest.requestCodeType requestCode) { if (result != null) { if (requestCode == APIRequest.requestCodeType.Share) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { Name = json.GetNamedString("name"); Value = json.GetNamedNumber("value"); Time = json.GetNamedString("time"); Date = json.GetNamedString("date"); if (json.GetNamedValue("limit_down").ValueType != JsonValueType.Null) { LimitDown = json.GetNamedNumber("limit_down"); } else { LimitDown = null; } if (json.GetNamedValue("limit_up").ValueType != JsonValueType.Null) { LimitUp = json.GetNamedNumber("limit_up"); } else { LimitUp = null; } Favorite = Convert.ToBoolean(json.GetNamedNumber("is_main")); } else { if (NavigatePortfolio != null) { NavigatePortfolio(); } } } else if (requestCode == APIRequest.requestCodeType.ShareEvolution) { ValuesEvolution.Clear(); Values2Evolution.Clear(); JsonArray json = JsonArray.Parse(result); //var i = 0; foreach (var point in json) { //i++; JsonObject jsonPoint = JsonObject.Parse(point.Stringify()); string date = jsonPoint.GetNamedString("date"); //date = date.Substring(5, date.Length - 5); double high = jsonPoint.GetNamedNumber("high"); double low = jsonPoint.GetNamedNumber("low"); var split = date.Split('-'); DateTime date2 = new DateTime(Int32.Parse(split[0]), Int32.Parse(split[1]), Int32.Parse(split[2])); ValuesEvolution.Add(new Tuple <DateTime, double>(date2, low)); Values2Evolution.Add(new Tuple <DateTime, double>(date2, high)); } } else if (requestCode == APIRequest.requestCodeType.Favorite) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { Favorite = true; } } else if (requestCode == APIRequest.requestCodeType.Unfavorite) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { Favorite = false; } } else if (requestCode == APIRequest.requestCodeType.ClearLimitUp) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { LimitUp = null; } } else if (requestCode == APIRequest.requestCodeType.ClearLimitDown) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { LimitDown = null; } } else if (requestCode == APIRequest.requestCodeType.PortfolioRemove) { JsonObject json = new JsonObject(); JsonObject.TryParse(result, out json); if (!json.ContainsKey("error")) { if (NavigatePortfolio != null) { NavigatePortfolio(); } } } } else { var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Server request failed.")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Server is down or you lost internet connection.")); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); } }