async void LoadList(int p = -1) { Tools.rootPage.ShowProgressBar(); if (p == 1) { string url = isFollowList ? $"/user/followList?uid={uid}&page={p}" : $"/user/fansList?uid={uid}&page={p}"; string r = await Tools.GetJson(url); JsonArray array = Tools.GetDataArray(r); if (array != null && array.Count > 0) { firstItem = array.First().GetObject()["fuid"].GetNumber(); lastItem = array.Last().GetObject()["fuid"].GetNumber(); if (infos.Count > 0) { var d = (from a in infos from b in array where a.UserName == b.GetObject()[isFollowList ? "fusername" : "username"].GetString() select a).ToArray(); foreach (var item in d) { infos.Remove(item); } } for (int i = 0; i < array.Count; i++) { IJsonValue t = isFollowList ? array[i].GetObject()["fUserInfo"] : array[i].GetObject()["userInfo"]; infos.Insert(i, new UserViewModel(t)); } } } else if (p == -1) { string url = isFollowList ? $"/user/followList?uid={uid}&page={++page}&firstItem={firstItem}&lastItem={lastItem}" : $"/user/fansList?uid={uid}&page={++page}&firstItem={firstItem}&lastItem={lastItem}"; string r = await Tools.GetJson(url); JsonArray array = Tools.GetDataArray(r); if (array != null && array.Count > 0) { lastItem = array.Last().GetObject()["fuid"].GetNumber(); for (int i = 0; i < array.Count; i++) { IJsonValue t = isFollowList ? array[i].GetObject()["fUserInfo"] : array[i].GetObject()["userInfo"]; infos.Add(new UserViewModel(t)); } } else { page--; } } Tools.rootPage.HideProgressBar(); }
public ThreadContainer GetThreadData(string board, int id) { APIResponse response = LoadAPI(string.Format("{0}://a.4cdn.org/{1}/thread/{2}.json", Common.HttpPrefix, board, id)); switch (response.Error) { case APIResponse.ErrorType.NoError: ThreadContainer tc = null; JsonObject list = JsonConvert.Import <JsonObject>(response.Data); //if (list == null) //{ // FlushAPI(string.Format("http://a.4cdn.org/{0}/thread/{1}.json", board, id)); // return GetThreadData(board, id); //} if (list.Names.Cast <string>().Contains("posts")) { JsonArray data = list["posts"] as JsonArray; tc = new ThreadContainer(ParseThread((JsonObject)data.First(), board)); for (int index = 1; index < data.Count; index++) { tc.AddReply(ParseReply((JsonObject)data[index], board)); } } return(tc); case APIResponse.ErrorType.NotFound: throw new Exception("404"); case APIResponse.ErrorType.Other: throw new Exception(response.Data); default: return(null); } }
/* * async void GetVScrollViewer() * { * while (VScrollViewer is null) * { * await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, * () => VScrollViewer = (VisualTreeHelper.GetChild(listView, 0) as FrameworkElement)?.FindName("ScrollViewer") as ScrollViewer); * await Task.Delay(1000); * } * VScrollViewer.ViewChanged += ScrollViewer_ViewChanged; * }*/ public async void LoadProfile() { ImageSource getImage(string uri) { if (Settings.GetBoolen("IsNoPicsMode")) { if (Settings.GetBoolen("IsDarkMode")) { return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder_night.png")) { DecodePixelHeight = 150, DecodePixelWidth = 150 } } ; else { return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder.png")) { DecodePixelHeight = 150, DecodePixelWidth = 150 } }; } return(new BitmapImage(new Uri(uri))); } string result = await Tools.GetJson("/user/space?uid=" + uid); JsonObject detail = Tools.GetJSonObject(result); if (detail != null) { UserDetailGrid.DataContext = new { UserFaceUrl = detail["userAvatar"].GetString(), UserFace = getImage(detail["userAvatar"].GetString()), UserName = detail["username"].GetString(), FollowNum = detail["follow"].GetNumber(), FansNum = detail["fans"].GetNumber(), Level = detail["level"].GetNumber(), bio = detail["bio"].GetString(), BackgroundUrl = detail["cover"].GetString(), Background = new ImageBrush { ImageSource = getImage(detail["cover"].GetString()), Stretch = Stretch.UniformToFill }, verify_title = detail["verify_title"].GetString(), gender = detail["gender"].GetNumber() == 1 ? "♂" : (detail["gender"].GetNumber() == 0 ? "♀" : string.Empty), city = $"{detail["province"].GetString()} {detail["city"].GetString()}", astro = detail["astro"].GetString(), logintime = $"{Tools.ConvertTime(detail["logintime"].GetNumber())}活跃" }; titleBar.Title = detail["username"].GetString(); ListHeader.DataContext = new { FeedNum = detail["feed"].GetNumber() }; } } async void ReadNextPageFeeds() { string str = await Tools.GetJson($"/user/feedList?uid={uid}&page={++page}&firstItem={firstItem}&lastItem={lastItem}"); JsonArray Root = Tools.GetDataArray(str); if (Root != null && Root.Count != 0) { if (page == 1) { firstItem = Root.First().GetObject()["id"].GetNumber(); } lastItem = Root.Last().GetObject()["id"].GetNumber(); foreach (var i in Root) { FeedsCollection.Add(new FeedViewModel(i)); } } else { page--; } }
private async void Button_Click(object sender, RoutedEventArgs e) { Geopoint lastPoint = new Geopoint(new BasicGeoposition()), currentPoint; Windows.UI.Core.DispatchedHandler actualizarTextBox = async() => { HttpClient client = new HttpClient(); HttpResponseMessage stream = await client.GetAsync(urlInicial + lugarIncialTextBox.Text + urlMedio + lugarFinalTextBox.Text + urlFinal); //Si ha obtenido una ruta como respuesta, escribe en el mapa if (stream.IsSuccessStatusCode) { String str = await stream.Content.ReadAsStringAsync(); JsonValue jsonValue = JsonValue.Parse(str); arrayRuta = jsonValue.GetObject().GetNamedArray("resourceSets").GetObjectAt(0).GetNamedArray("resources").GetObjectAt(0).GetNamedArray("routeLegs").GetObjectAt(0).GetNamedArray("itineraryItems"); //Bucle que dibuja cada punto de la ruta y la ruta entre el punto actual y el anterior en el mapa var first = arrayRuta.First(); foreach (var puntoRuta in arrayRuta) { PuntoBing puntoBing = obtenerPunto(puntoRuta.GetObject()); currentPoint = geopositionPoint(puntoBing.Latitude, puntoBing.Longitude); string nombres = ""; foreach (string nombre in puntoBing.Nombre) { nombres = nombres + Environment.NewLine + nombre; } mapIconRuta = new MapIcon { Location = currentPoint, Title = nombres }; mapView.MapElements.Add(mapIconRuta); puntos.Add(puntoBing); escribePunto(puntoBing); //Si el punto actual es el último, pasa a ser el actual en el código if (!puntoRuta.Equals(first)) { // Obtiene la ruta entre el punto anterior y el actual. MapRouteFinderResult routeResult = await MapRouteFinder.GetDrivingRouteAsync( startPoint : lastPoint, endPoint : currentPoint, optimization : MapRouteOptimization.Time, restrictions : MapRouteRestrictions.None); if (routeResult.Status == MapRouteFinderStatus.Success) { // Usa la ruta para inicializar MapRouteView. MapRouteView viewOfRoute = new MapRouteView(routeResult.Route); viewOfRoute.RouteColor = Colors.Yellow; viewOfRoute.OutlineColor = Colors.Black; // Añade el nuevo MapRouteView al conjunto de rutas // de MapControl. mapView.Routes.Add(viewOfRoute); //El punto actual se convierte en el anterior lastPoint = currentPoint; } } else { lastPoint = currentPoint; } } } else { rutaTextBox.Text = "Mal"; } }; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, actualizarTextBox); }
private UserInfoStruct ParseResults(JsonArray ResultsArray) { UserInfoStruct UserInfo = new UserInfoStruct(); //Parse Results JsonObject ResultsObj = (JsonObject)ResultsArray.First(); UserInfo.Uid = long.Parse(ResultsObj["uid"].ToString()); UserInfo.Name = ResultsObj["name"].ToString(); UserInfo.Pic_Big_Url = ResultsObj["pic_big"].ToString(); UserInfo.Pic_Big_Url = Helpers.CleanHttps(UserInfo.Pic_Big_Url); UserInfo.Pic_Sqaure_Url = ResultsObj["pic_square"].ToString(); UserInfo.Pic_Sqaure_Url = Helpers.CleanHttps(UserInfo.Pic_Sqaure_Url); UserInfo.Profile_Url = ResultsObj["profile_url"].ToString(); UserInfo.Profile_Url = Helpers.CleanHttps(UserInfo.Profile_Url); return UserInfo; }
public async void LoadDyhDetail() { ImageSource getImage(string uri) { if (Settings.GetBoolen("IsNoPicsMode")) { if (Settings.GetBoolen("IsDarkMode")) { return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder_night.png")) { DecodePixelHeight = 150, DecodePixelWidth = 150 } } ; else { return new BitmapImage(new Uri("ms-appx:/Assets/img_placeholder.png")) { DecodePixelHeight = 150, DecodePixelWidth = 150 } }; } return(new BitmapImage(new Uri(uri))); } string r = await Tools.GetJson($"/dyh/detail?dyhId={id}"); JsonObject detail = Tools.GetJSonObject(r); if (detail != null) { if (detail["is_open_discuss"].GetNumber() == 1) { MainPivot.IsLocked = false; } TitleBar.Title = detail["title"].GetString(); bool showUserButton = detail["uid"].GetNumber() != 0; DetailGrid.DataContext = new { Logo = getImage(detail["logo"].GetString()), Title = detail["title"].GetString(), Description = detail["description"].GetString(), FollowNum = detail["follownum"].GetNumber(), ShowUserButton = showUserButton ? Visibility.Visible : Visibility.Collapsed, url = showUserButton ? detail["userInfo"].GetObject()["url"].GetString() : string.Empty, UserName = showUserButton ? detail["userInfo"].GetObject()["username"].GetString() : string.Empty, UserAvatar = showUserButton ? getImage(detail["userInfo"].GetObject()["userSmallAvatar"].ToString().Replace("\"", string.Empty)) : new BitmapImage() }; } } async void LoadFeeds(int p = -1) { string r = await Tools.GetJson($"/dyhArticle/list?dyhId={id}&type={(MainPivot.SelectedIndex == 0 ? "all" : "square")}&page={(p == -1 ? ++page[MainPivot.SelectedIndex] : p)}{(firstItem[MainPivot.SelectedIndex] == 0 ? string.Empty : $"&firstItem={firstItem[MainPivot.SelectedIndex]}")}{((lastItem[MainPivot.SelectedIndex] == 0) ? string.Empty : $" & lastItem ={ lastItem[MainPivot.SelectedIndex]}")}"); JsonArray Root = Tools.GetDataArray(r); if (Root != null && Root.Count != 0) { if (page[MainPivot.SelectedIndex] == 1) { firstItem[MainPivot.SelectedIndex] = Root.First().GetObject().TryGetValue("articleId", out IJsonValue value1) ? value1.GetNumber() : Root.First().GetObject()["id"].GetNumber(); lastItem[MainPivot.SelectedIndex] = Root.Last().GetObject().TryGetValue("articleId", out IJsonValue value2) ? value2.GetNumber() : Root.Last().GetObject()["id"].GetNumber(); } foreach (var i in Root) { FeedsCollection[MainPivot.SelectedIndex].Add(new FeedViewModel(i, FeedDisplayMode.notShowDyhName)); } } else { page[MainPivot.SelectedIndex]--; } }
public async Task Seed() { context.Database.EnsureCreated(); var user = await userManager.FindByNameAsync("casandrahuzum"); if (user == null) { user = new User() { FirstName = "Casandra", LastName = "Huzum", UserName = "******" }; var result = await userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Failed to create defaul user!"); } } if (context.Breeds.Any() || context.Characteristics.Any() || context.Questions.Any()) { return; } ICollection <Characteristic> characteristics = new List <Characteristic>(); ICollection <Breed> breeds = new List <Breed>(); string filepath = Path.Combine(hosting.ContentRootPath, "Data/characteristics.json"); string jsonText = File.ReadAllText(filepath); JsonArray jsonArray = (JsonArray)JsonValue.Parse(jsonText); JsonObject firstObject = (JsonObject)jsonArray.First(); foreach (string key in firstObject.Keys.Where(key => key != "Name")) { characteristics.Add(new Characteristic() { Name = key }); } foreach (JsonObject jsonObject in jsonArray) { ICollection <BreedCharacteristic> breedCharacteristics = new List <BreedCharacteristic>(); foreach (Characteristic characteristic in characteristics) { breedCharacteristics.Add(new BreedCharacteristic() { Characteristic = characteristic, Score = jsonObject[characteristic.Name] }); } breeds.Add(new Breed() { Name = jsonObject["Name"], BreedCharacteristics = breedCharacteristics }); } ICollection <Question> questions = new List <Question>(); string filepathQuestions = Path.Combine(hosting.ContentRootPath, "Data/questions.json"); string jsonTextQuestions = File.ReadAllText(filepathQuestions); JsonArray jsonArrayQuestions = (JsonArray)JsonValue.Parse(jsonTextQuestions); foreach (JsonObject jsonObject in jsonArrayQuestions) { ICollection <Answer> answers = new List <Answer>(); JsonArray jsonAnswers = (JsonArray)jsonObject["Answers"]; foreach (JsonObject jsonAnswer in jsonAnswers) { ICollection <AnswerCharacteristic> answerCharacteristics = new List <AnswerCharacteristic>(); JsonArray jsonCharacteristics = (JsonArray)jsonAnswer["Characteristics"]; foreach (JsonObject jsonCharacteristic in jsonCharacteristics) { answerCharacteristics.Add(new AnswerCharacteristic() { Score = jsonCharacteristic["Score"], Characteristic = characteristics.Where(c => c.Name == jsonCharacteristic["CharacteristicName"]).First() }); } answers.Add(new Answer() { Sentence = jsonAnswer["Sentence"], AnswerCharacteristics = answerCharacteristics }); } questions.Add(new Question() { Sentence = jsonObject["Sentence"], Answers = answers }); } context.AddRange(characteristics); context.AddRange(breeds); context.AddRange(questions); context.SaveChanges(); }