| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Http;
- using System.Configuration;
- using System.Windows.Forms;
- using System.Net;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using HXX.Scanner.Common;
- using HXX.Scanner.Biz;
- namespace HXX.Scanner.Starter
- {
- class biz
- {
- public static async Task<ResponseEntity<entity_upgrade_info>> get_version_info()
- {
- ResponseEntity<entity_upgrade_info> result = new ResponseEntity<entity_upgrade_info>();
- try
- {
- ServicePointManager.SecurityProtocol =
- SecurityProtocolType.Ssl3 |
- SecurityProtocolType.Tls |
- SecurityProtocolType.Tls11 |
- SecurityProtocolType.Tls12;
- var url = GetConfig().AppSettings.Settings["url_upgrade_formal"].Value;
- //var url = "https://dev3.k12100.net/teaching/api/v1/client/find_last_version";
-
- HttpResponseMessage response = await new HttpClient().GetAsync(url);
- response.EnsureSuccessStatusCode();
- var http_response = await response.Content.ReadAsStringAsync();
- var data = JsonConvert.DeserializeObject<entity_upgrade_info>(http_response);
-
- if (data.code == 200 || data.code == 500 || data.code == 401)
- {
- if (data.data != null)
- {
- result.Status = 1;
- result.Message = "ok";
- result.Data = data;
- }
- else
- {
- result.Status = 0;
- result.Message = "获取升级信息失败";
- result.Data = data;
- }
- }
- else
- {
- result.Status = 0;
- result.Message = "获取升级信息失败";
- result.Data = data;
- }
- }
- catch (Exception ee)
- {
- result.Status = 0;
- result.Message = "获取升级信息失败" + Environment.NewLine + ee.Message;
- }
- return result;
- }
- public static bool check_new_version(entity_sub_upgrade_info info)
- {
- string str_current_version = GetConfig().AppSettings.Settings["appVersion"].Value;
- string str_server_version = info.version;
- info.current_version = str_current_version;
- Version v1 = new Version(str_current_version);
- Version v2 = new Version(str_server_version);
- if (v2 > v1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static Configuration GetConfig()
- {
- string Path = System.IO.Directory.GetCurrentDirectory();
-
- string FullName = Path + @"\HXXScannerClient.exe.config";
-
- ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
-
- fileMap.ExeConfigFilename = FullName;
- Configuration cfg = null;
- try
- {
- cfg = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
- }
- catch
- {
- }
- return cfg;
- }
- }
- }
|