//测试 private void button7_Click(object sender, EventArgs e) { var a1 = CoreConvert.ObjToJsonData(DateTime.Now); var a2 = CoreConvert.JsonDataToObj(a1, typeof(DateTime)); MessageBox.Show(a2.ToString()); }
public static bool IsTokenValid() { try { var userInfoJson = CoreEncrypt.AesDecrypt(AuthHelper.GetAuth(), GlobalConst.AesKey); var userInfo = CoreConvert.JsonToObj <UserInfo>(userInfoJson); var text = CoreEncrypt.AesDecrypt(userInfo.Token, CoreEncrypt.Md5(userInfo.UserName)); var expiredTime = DateTime.Parse(text); return(expiredTime >= DateTime.UtcNow); } catch (Exception ex) { CoreLog.Error(ex); return(false); } }
public static WsSoap CreateWsService(string url = null, int timeoutSeconds = 60) { try { var client = new WsSoapClient(); client.Endpoint.Address = new EndpointAddress(url ?? GlobalVar.ServiceBaseUrl); var userInfo = GlobalVar.UserInfo ?? new UserInfo(); var userInfoJson = CoreConvert.ObjToJson(userInfo); var authorization = CoreEncrypt.AesEncrypt(userInfoJson, GlobalConst.AesKey); client.Endpoint.Behaviors.Add(AuthHelper.CreateAuthHeaderBehavior(authorization)); if (client.Endpoint.Binding == null) { return(client); } client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 0, timeoutSeconds); client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, timeoutSeconds); return(client); } catch (Exception e) { CoreLog.Error(e); throw new Exception("服务连接失败"); } }
public static RatingList ParseRfg(ref string text) { var result = new RatingList(); DateTime actualDate = CoreConvert.EmptyDate; if (!string.IsNullOrEmpty(text)) { string datePattern = "<h2 id=\"rating-name\">Текущий рейтинг лист.<br /> Рейтинг–лист по состоянию на "; int d = text.IndexOf(datePattern); if (d < 0) { datePattern = "Рейтинг-лист по состоянию на "; d = text.IndexOf(datePattern); } if (d < 0) { datePattern = "Рейтинг–лист по состоянию на "; d = text.IndexOf(datePattern); } if (d < 0) { datePattern = @"<div id=""leftcol"">"; d = text.IndexOf(datePattern); } /* * if (d > 0) * { * int dEnd = text.IndexOf(" года</h2>", d); * if (dEnd > d + datePattern.Length) * { * string date = text.Substring(d + datePattern.Length, dEnd - (d + datePattern.Length)); * if (!string.IsNullOrEmpty(date)) * { * string[] arr = date.Split(); * if (arr.Length > 1) * { * string m = null; * switch (arr[1]) * { * case "января": m = "01"; break; * case "февраля": m = "02"; break; * case "марта": m = "03"; break; * case "апреля": m = "04"; break; * case "мая": m = "05"; break; * case "июня": m = "06"; break; * case "июля": m = "07"; break; * case "августа": m = "08"; break; * case "сентября": m = "09"; break; * case "октября": m = "10"; break; * case "ноября": m = "11"; break; * case "декабря": m = "12"; break; * } * * if (!string.IsNullOrEmpty(m)) * result.Date = arr[0] + "." + m + "." + arr[2]; * } * } * } * } */ int p = text.IndexOf("<table", d); if (p >= 0) { int place = 1; int p2 = text.IndexOf("<td>1</td>", p); int pEnd = text.IndexOf("</tbody>", p2); do { if (p2 > p) { int p2End = text.IndexOf("</tr>", p2); if (p2End > p2) { RtItem rec = new RtItem(); for (int i = 0; i < 6; i++) { string s; int val; int p3 = text.IndexOf("<td", p2); if (p3 > -1) { int p3End = text.IndexOf(">", p3); int p4 = text.IndexOf(@"</td>", p3End); if (p4 > p3End) { switch (i) { case 0: //Place rec.Place = place++; break; case 1: //Name int p5 = text.IndexOf("<a", p3End); int p5a = text.IndexOf(">", p5); int p5End = text.IndexOf("</a>", p5); s = text.Substring(p5a + 1, p5End - p5a - 1); int j = s.IndexOf(' '); if (j > -1) { rec.LastName = s.Substring(0, j); rec.FirstName = s.Substring(j + 1); } else { rec.LastName = s; } break; case 2: //City s = text.Substring(p3End + 1, p4 - p3End - 1); val = 0; //Avoid mistakes in the table if (int.TryParse(s, out val)) { rec.Rating = val; } else { rec.City = s; } break; case 3: //Rating if (rec.Rating == 0) { s = text.Substring(p3End + 1, p4 - p3End - 1); val = 0; if (int.TryParse(s, out val)) { rec.Rating = val; } } break; case 4: //Diff break; case 5: //Date s = text.Substring(p3End + 1, p4 - p3End - 1); var date = CoreConvert.ToDate(s); rec.Date = CoreConvert.ToDateString(date); if (DateTime.Compare(date, actualDate) > 0) { actualDate = date; } break; } p2 = p4 + 1; } else { break; } } } result.Items.Add(rec); } else { break; } p2 = text.IndexOf("<tr>", p2); } else { break; } } while (p2 < pEnd || p2 == -1); } } result.Date = CoreConvert.ToDateString(actualDate); return(result); }