private async void GetCourseByDean() { BitmapImage bmp = new BitmapImage(); Stream stream = await WebConnection.Connect_for_stream("http://dean.pku.edu.cn/student/yanzheng.php?act=init"); if (stream == null) { Constants.BoxPage.ShowMessage("获取验证码失败!"); return; } var ran_stream = await Util.StreamToRandomAccessStream(stream); bmp.SetSource(ran_stream); IMGverify.Source = bmp; PRGRScourse.ProgressStart(); ContentDialogResult res = await DLGverify.ShowAsync(); if (res != ContentDialogResult.Primary) { this.IsEnabled = true; PRGRScourse.ProgressEnd(); return; } String str = await Dean.get_session_id(VerifyCode); if (str == "") { return; } /** * 下面这段注释的代码可能是用来获取自选课程的,不是dean */ //List<Parameters> list = new List<Parameters>(); //list.Add(new Parameters("token", Constants.token)); //list.Add(new Parameters("phpsessid", str)); //Parameters parameter = await WebConnection.Connect(Constants.domain + "/services/pkuhelper/course.php", list); Parameters parameter = await WebConnection.Connect("http://dean.pku.edu.cn/student/newXkInfo_1105.php?PHPSESSID=" + str, null); if (parameter != null && parameter.name == "200") { CourseUtil.DecodeDeanHtml(parameter.value); CourseUtil.SaveCourses("DeanCourses", CourseUtil.DeanCourses); if (Constants.CourseUseCustom) { await CourseUtil.GetCustomCourses(str); } ShowCourse(); this.IsEnabled = true; PRGRScourse.ProgressEnd(); } else { Util.DealWithDisconnect(parameter); this.IsEnabled = true; PRGRScourse.ProgressEnd(); } }
public static async Task GetBingToday() { try { String bing_url = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-cn"; Parameters result1 = await WebConnection.Connect(bing_url, null); if (result1.name != "200") { return; } JsonObject info_json = JsonObject.Parse(result1.value); JsonArray img_array = info_json.GetNamedArray("images", new JsonArray()); JsonObject img_info = img_array.GetObjectAt(0); String img_url = img_info.GetNamedString("url", ""); if (img_url.Equals("")) { img_url = "http://s.cn.bing.net" + img_info.GetNamedString("urlbase", ""); } if (img_url.Equals("http://s.cn.bing.net")) { return; } Stream img_stream = await WebConnection.Connect_for_stream(img_url); var img_acstr = await Util.StreamToRandomAccessStream(img_stream); try { var bing_bmp = new WriteableBitmap(1920, 1080); bing_bmp.SetSource(img_acstr); await SaveCacheBmp(bing_bmp); Editor.putString("bing_history", DateTime.Now.ToString()); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }
private async void get_image(String _image) { if (_image != null && !"".Equals(_image)) { try { img_name = _image; img_url = Constants.domain + "/services/image/" + _image + ".jpg"; thumb_img_url = Constants.domain + "/services/image/" + _image + "_thumb.jpg"; var stream1 = await WebConnection.Connect_for_stream(img_url); real_img = new WriteableBitmap(100, 100); real_img.SetSource(await Util.StreamToRandomAccessStream(stream1)); var stream2 = await WebConnection.Connect_for_stream(thumb_img_url); thumb_img = new BitmapImage(); thumb_img.SetSource(await Util.StreamToRandomAccessStream(stream2)); } catch (Exception e) { Debug.WriteLine("fail to get the LF image" + e.StackTrace); } } else { img_url = ""; thumb_img_url = ""; img_name = ""; StorageFile img_file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/hero_pku.png")); IRandomAccessStream input = await img_file.OpenReadAsync(); thumb_img = new BitmapImage(); thumb_img.SetSource(input); StorageFile img_file1 = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/hero_pku.png")); IRandomAccessStream input1 = await img_file.OpenReadAsync(); real_img = new WriteableBitmap(150, 180); real_img.SetSource(input1); } }
private async void other_init() { if (!((type == TYPE_IMAGE || type == TYPE_AUDIO) && !"".Equals(url))) { return; } if (type == TYPE_IMAGE) { writable_bitmap = new WriteableBitmap(100, 200); Stream stream = await WebConnection.Connect_for_stream(url); if (stream == null) { return; } var ran_stream = await Util.StreamToRandomAccessStream(stream); try { writable_bitmap.SetSource(ran_stream); } catch (Exception e)//这里未能明白什么造成了异常 { Debug.WriteLine("fail to get the hole image, at" + e.StackTrace); return; } } else { /*try * { * writable_bitmap = new WriteableBitmap(100, 200); * StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/audio_start.png")); * writable_bitmap.SetSource(await file.OpenReadAsync()); * } * catch(Exception e) * { * Debug.WriteLine("fail to set the audio image, at" + e.StackTrace); * return; * }*/ } }
public async void get_icon(String url) { Icon = new BitmapImage(); Stream stream = await WebConnection.Connect_for_stream(url); if (stream == null) { return; } var ran_stream = await Util.StreamToRandomAccessStream(stream); try { Icon.SetSource(ran_stream); } catch (Exception) { return; } }
private async void LoadImage(String imgName) { if (imgName.Equals("")) { return; } BmpSrc = new WriteableBitmap(100, 200); Stream stream = await WebConnection.Connect_for_stream(Constants.domain + "/pkuhelper/../static/message/image/" + imgName); try { var ran_stream = await Util.StreamToRandomAccessStream(stream); BmpSrc.SetSource(ran_stream); } catch (Exception e) { Debug.WriteLine("fail to get the chat image," + e.StackTrace); return; } }
private async void LSTVWinfo_ItemClick(object sender, ItemClickEventArgs e) { switch ((e.ClickedItem as UsualItemData).ID) { case 0: { FRAMEdetail.Navigate(typeof(ImageShowPage), new Parameters("北大地图", "ms-appx:///Assets/pkumap.jpg")); if (VSGinfo.CurrentState == narrow) { UpdateVisualState(narrow, null); } } break; case 1: { FRAMEdetail.Navigate(typeof(ImageShowPage), new Parameters("北京地铁图", "ms-appx:///Assets/subwaymap.jpg")); if (VSGinfo.CurrentState == narrow) { UpdateVisualState(narrow, null); } } break; case 2: { PRGRSinfo.ProgressStart(); await InfoUtil.GetCardAmount(); PRGRSinfo.ProgressEnd(); } break; case 3: { first : BitmapImage bmp = new BitmapImage(); Stream stream = await WebConnection.Connect_for_stream("http://dean.pku.edu.cn/student/yanzheng.php?act=init"); if (stream == null) { Constants.BoxPage.ShowMessage("获取验证码失败!"); return; } var ran_stream = await Util.StreamToRandomAccessStream(stream); bmp.SetSource(ran_stream); IMGverify.Source = bmp; if (DLGshowing) { return; } ContentDialogResult res = await DLGverify.ShowAsync(); if (res == ContentDialogResult.Primary) { String phpsessid = await Dean.get_session_id(verifyCode); if (phpsessid == "") { goto first; } PRGRSinfo.ProgressStart(); Parameters parameters = await WebConnection.Connect(Constants.domain + "/services/pkuhelper/allGrade.php?phpsessid=" + phpsessid, null); if (parameters.name != "200") { Util.DealWithDisconnect(parameters); PRGRSinfo.ProgressEnd(); } else { PRGRSinfo.ProgressEnd(); FRAMEdetail.Navigate(typeof(GradePage), parameters.value); if (VSGinfo.CurrentState == narrow) { UpdateVisualState(narrow, null); } } } } break; case 4: { FRAMEdetail.Navigate(typeof(SchoolCalendarPage)); if (VSGinfo.CurrentState == narrow) { UpdateVisualState(narrow, null); } } break; case 5: { FRAMEdetail.Navigate(typeof(PhoneList)); if (VSGinfo.CurrentState == narrow) { UpdateVisualState(narrow, null); } } break; } }