public static async Task <IPGWMsg> DoConnection(IPGW_type connectType, String hintString = "") { if (connectType == IPGW_type.None) { return(null); } String type = "connect"; String free = "2"; if (connectType == IPGW_type.ConnectNofree) { free = "1"; } else if (connectType == IPGW_type.Disconnect) { type = "disconnect"; } else if (connectType == IPGW_type.DisconnectAll) { type = "disconnectall"; } List <Parameters> paramList = new List <Parameters>(); paramList.Add(new Parameters("uid", Constants.username)); paramList.Add(new Parameters("password", Constants.password)); paramList.Add(new Parameters("operation", type)); paramList.Add(new Parameters("range", free)); paramList.Add(new Parameters("timeout", "-1")); Parameters result = await WebConnection.Connect("https://its.pku.edu.cn:5428/ipgatewayofpku", paramList); if (!"200".Equals(result.name)) { Util.DealWithDisconnect(result); return(null); } Dictionary <String, String> map = GetReturnMsg(result.value); if (!map.ContainsKey("SUCCESS")) { return(null); } String successMsg = map["SUCCESS"]; bool success = "YES".Equals(successMsg); String title = "", content = ""; switch (connectType) { case IPGW_type.ConnectFree: { if (success) { title = "连接免费地址成功"; } else { title = map["REASON"]; } String scope = ""; if ("f".Equals(map["SCOPE"].Trim())) { scope = "免费地址"; } else if ("international".Equals(map["SCOPE"].Trim())) { scope = "收费地址"; } content = scope + "\n" + "IP: " + map["IP"] + "\n当前连接数:" + map["CONNECTIONS"] + "\n" + "已用时长: " + map["FR_TIME"] + "\n" + "账户余额:" + map["BALANCE"]; } break; case IPGW_type.ConnectNofree: { if (success) { title = "连接收费地址成功"; } else { title = map["REASON"]; } String scope = ""; if ("f".Equals(map["SCOPE"].Trim())) { scope = "免费地址"; } else if ("international".Equals(map["SCOPE"].Trim())) { scope = "收费地址"; } content = scope + "\n" + "IP: " + map["IP"] + "\n当前连接数:" + map["CONNECTIONS"] + "\n" + "已用时长: " + map["FR_TIME"] + "\n" + "账户余额:" + map["BALANCE"]; /*if (free.Equals("1")) * { * Boolean whether_get_bing = false; * String his_str = Editor.getString("bing_history", ""); * try * { * if (!his_str.Equals("")) * { * DateTime history = DateTime.Parse(his_str); * int span = DateTime.Now.Day - history.Day; * if (span >= 1 || span < 0) whether_get_bing = true; * } * else whether_get_bing = true; * } * catch { } * if (whether_get_bing) * { * await GetBingToday(); * } * }*/ } break; case IPGW_type.Disconnect: { if (success) { title = "断开连接成功"; } else { title = "断开连接失败"; content = map["REASON"]; } } break; case IPGW_type.DisconnectAll: { if (success) { title = "断开全部连接成功"; } else { title = "断开全部连接失败"; content = map["REASON"]; } } break; } return(new IPGWMsg(success, title, content, connectType)); }
private async void DoConnection(IPGW_type connectType, String hintString) { String type = "connect"; String free = "2"; if (connectType == IPGW_type.ConnectNofree) { free = "1"; } else if (connectType == IPGW_type.Disconnect) { type = "disconnect"; } else if (connectType == IPGW_type.DisconnectAll) { type = "disconnectall"; } //if (!Constants.isLogin()) ;//日后加入登录内容 List <Parameters> paramList = new List <Parameters>(); /** * 这两句仅用于测试!!! * 必须改掉! */ //Constants.username = "******"; //Constants.password = "******"; paramList.Add(new Parameters("uid", Constants.username)); paramList.Add(new Parameters("password", Constants.password)); paramList.Add(new Parameters("operation", type)); paramList.Add(new Parameters("range", free)); paramList.Add(new Parameters("timeout", "-1")); Reset(); PageStatus = IPGWstatus.Connecting; STRBDconnectEnd.Begin(); Parameters parameter = await WebConnection.Connect("https://its.pku.edu.cn:5428/ipgatewayofpku", paramList); if (!"200".Equals(parameter.name)) { if ("-1".Equals(parameter.name)) { Constants.BoxPage.ShowMessage("无法连接网络"); } else { Constants.BoxPage.ShowMessage("无法连接到服务器 (HTTP " + parameter.name + ")"); } } else { Dictionary <String, String> map = GetReturnMsg(parameter.value); if (!map.ContainsKey("SUCCESS")) { Constants.BoxPage.ShowMessage("网关连接失败,请重试"); STRBDconnecting.Stop(); return; } String successMsg = map["SUCCESS"]; Boolean success = "YES".Equals(successMsg); if (connectType == IPGW_type.ConnectFree || connectType == IPGW_type.ConnectNofree) { if (success) { String scope = ""; if ("f".Equals(map["SCOPE"].Trim())) { scope = "免费地址"; } else if ("international".Equals(map["SCOPE"].Trim())) { scope = "收费地址"; } hintString = scope + "\r\n" + "IP: " + map["IP"] + "\r\n当前连接数:" + map["CONNECTIONS"] + "\r\n" + "已用时长: " + map["FR_TIME"] + "\r\n" + "账户余额:" + map["BALANCE"]; if (free.Equals("1")) { Boolean whether_get_bing = false; String his_str = Editor.getString("bing_history", ""); try { if (!his_str.Equals("")) { DateTime history = DateTime.Parse(his_str); int span = DateTime.Now.Day - history.Day; if (span >= 1 || span < 0) { whether_get_bing = true; } } else { whether_get_bing = true; } } catch { } if (whether_get_bing) { await GetBingToday(); } } // 显示对话框 //两个Lib的函数?仍然没看懂 Constants.BoxPage.ShowMessage(hintString, "连接状态:已连接"); } else { Constants.BoxPage.ShowMessage(map["REASON"], "连接失败"); //一个Lib的函数,未实现 } STRBDconnecting.Stop(); return; } if (connectType == IPGW_type.Disconnect) { if (success) { Constants.BoxPage.ShowMessage("", "断开连接成功"); } else { Constants.BoxPage.ShowMessage(map["REASON"], "断开连接失败"); STRBDconnecting.Stop(); return; } } if (connectType == IPGW_type.DisconnectAll) { if (success) { Constants.BoxPage.ShowMessage("", "断开全部连接成功"); } else { Constants.BoxPage.ShowMessage(map["REASON"], "断开全部连接失败"); STRBDconnecting.Stop(); 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; } }
private async Task <List <LostFoundInfo> > execute_load_more() { String type_str = "", token = ""; switch (type) { case LFstatus.Lost: { type_str = "lost"; } break; case LFstatus.Found: { type_str = "found"; } break; case LFstatus.My: { token = Constants.token; } break; default: break; } Parameters result = await WebConnection.Connect(Constants.domain + "/services/LFList.php?type=" + type_str + "&page=" + (current_page).ToString() + "&token=" + token, new List <Parameters>()); if (result.name != "200") { return(null); } JsonObject json; JsonArray data; try { json = JsonObject.Parse(result.value); data = json.GetNamedArray("data"); } catch (Exception) { return(null); } List <LostFoundInfo> more_infos = new List <LostFoundInfo>(); if (type != LFstatus.My) { try { Boolean bmore = json.GetNamedBoolean("more"); if (!bmore) { has_more_items = false; } } catch (Exception) { } } foreach (var info in data) { try { JsonObject data_obj = info.GetObject(); int tid = int.Parse(data_obj.GetNamedString("id")); if (type == LFstatus.My) { foreach (var temp in this) { if (temp.id == tid) { HasMoreItems = false; return(null); } } } String tname = data_obj.GetNamedString("name"); String tlost_or_found = data_obj.GetNamedString("lost_or_found"); String ttypr = data_obj.GetNamedString("type"); String tdetail = data_obj.GetNamedString("detail"); long tpost_time = long.Parse(data_obj.GetNamedString("post_time")); long taction_time = long.Parse(data_obj.GetNamedString("action_time")); String timage = data_obj.GetNamedString("image"); String tposter_uid = data_obj.GetNamedString("poster_uid"); String tposter_phone = data_obj.GetNamedString("poster_phone"); String tposter_name = data_obj.GetNamedString("poster_name"); String tposter_college = data_obj.GetNamedString("poster_college"); LostFoundInfo temp_info = new LostFoundInfo(tid, tname, tlost_or_found, ttypr, tdetail, tpost_time, taction_time, timage, tposter_uid, tposter_phone , tposter_name, tposter_college); if (type == LFstatus.My) { temp_info.mine = true; } more_infos.Add(temp_info); } catch { } } return(more_infos); }
private async Task <List <NoticeInfo> > execute_load_more() { String url = Constants.domain + "/pkuhelper/nc/fetch.php?token=" + Constants.token; url = url + "&p=" + (current_page + 1).ToString() + "&platform=Android"; if (type == ONE) { url = url + "&sid=" + sid.ToString(); } Parameters param = await WebConnection.Connect(url, new List <Parameters>()); if (param.name != "200") { return(null); } else { try { JsonObject jsonObject = JsonObject.Parse(param.value); int code = (int)jsonObject.GetNamedNumber("code"); if (code == 1) { Constants.BoxPage.ShowMessage("您还没有设置订阅源!请设置订阅源"); return(null); } JsonArray array = jsonObject.GetNamedArray("data"); List <NoticeInfo> more_infos = new List <NoticeInfo>(); foreach (var info in array) { JsonObject obj = info.GetObject(); String tTitle = obj.GetNamedString("title"); int tnid = int.Parse(obj.GetNamedString("nid")); String turl = obj.GetNamedString("url"); int tsid = int.Parse(obj.GetNamedString("sid")); String tsubscribe = obj.GetNamedString("subscribe"); long ttime = long.Parse(obj.GetNamedString("time")); NoticeInfo temp_info = new NoticeInfo(tnid, tTitle, tsid, turl, tsubscribe, ttime); if (NcSourceQuery.nc_sources != null) { try { NcSourceInfo temp_source; if (NcSourceQuery.nc_sources.TryGetValue(tsid.ToString(), out temp_source)) { temp_info.SourceIcon = temp_source.Icon; temp_info.SourceName = temp_source.Name; } else { temp_info.SourceIcon = null; temp_info.SourceName = "Unknown source name"; } } catch (Exception e) { Debug.WriteLine(e.StackTrace); } } more_infos.Add(temp_info); } return(more_infos); } catch (Exception e) { Debug.WriteLine(e.StackTrace); return(null); } } }