biz.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net.Http;
  7. using System.Configuration;
  8. using System.Windows.Forms;
  9. using System.Net;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Linq;
  12. using HXX.Scanner.Common;
  13. using HXX.Scanner.Biz;
  14. namespace HXX.Scanner.Starter
  15. {
  16. class biz
  17. {
  18. public static async Task<ResponseEntity<entity_upgrade_info>> get_version_info()
  19. {
  20. ResponseEntity<entity_upgrade_info> result = new ResponseEntity<entity_upgrade_info>();
  21. try
  22. {
  23. ServicePointManager.SecurityProtocol =
  24. SecurityProtocolType.Ssl3 |
  25. SecurityProtocolType.Tls |
  26. SecurityProtocolType.Tls11 |
  27. SecurityProtocolType.Tls12;
  28. var url = GetConfig().AppSettings.Settings["url_upgrade_formal"].Value;
  29. //var url = "https://dev3.k12100.net/teaching/api/v1/client/find_last_version";
  30. HttpResponseMessage response = await new HttpClient().GetAsync(url);
  31. response.EnsureSuccessStatusCode();
  32. var http_response = await response.Content.ReadAsStringAsync();
  33. var data = JsonConvert.DeserializeObject<entity_upgrade_info>(http_response);
  34. if (data.code == 200 || data.code == 500 || data.code == 401)
  35. {
  36. if (data.data != null)
  37. {
  38. result.Status = 1;
  39. result.Message = "ok";
  40. result.Data = data;
  41. }
  42. else
  43. {
  44. result.Status = 0;
  45. result.Message = "获取升级信息失败";
  46. result.Data = data;
  47. }
  48. }
  49. else
  50. {
  51. result.Status = 0;
  52. result.Message = "获取升级信息失败";
  53. result.Data = data;
  54. }
  55. }
  56. catch (Exception ee)
  57. {
  58. result.Status = 0;
  59. result.Message = "获取升级信息失败" + Environment.NewLine + ee.Message;
  60. }
  61. return result;
  62. }
  63. public static bool check_new_version(entity_sub_upgrade_info info)
  64. {
  65. string str_current_version = GetConfig().AppSettings.Settings["appVersion"].Value;
  66. string str_server_version = info.version;
  67. info.current_version = str_current_version;
  68. Version v1 = new Version(str_current_version);
  69. Version v2 = new Version(str_server_version);
  70. if (v2 > v1)
  71. {
  72. return true;
  73. }
  74. else
  75. {
  76. return false;
  77. }
  78. }
  79. public static Configuration GetConfig()
  80. {
  81. string Path = System.IO.Directory.GetCurrentDirectory();
  82. string FullName = Path + @"\HXXScannerClient.exe.config";
  83. ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
  84. fileMap.ExeConfigFilename = FullName;
  85. Configuration cfg = null;
  86. try
  87. {
  88. cfg = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
  89. }
  90. catch
  91. {
  92. }
  93. return cfg;
  94. }
  95. }
  96. }