using CsharpHttpHelper; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Api.Framework.Tools { public class UpdateClient { private static string ExecName = "FLSystem"; /// /// 获取云端的文件列表 /// public static string GetCloudFileHist() { try { int LastId = 1; try { var id = GetVersionId(); LastId = int.Parse(id); } catch (Exception) { LastId = 1; } var http = new HttpHelper(); var item = new HttpItem() { URL = "http://file.api.52cmg.cn/file/QueryHist?Name=" + HttpHelper.URLEncode(ExecName, Encoding.UTF8) + "&LastId=" + LastId, Timeout = 30000 }; var result = http.GetHtml(item).Html; var data = JObject.Parse(result); if ((bool)data["Ok"] && data["Data"] != null) { return ShowUpdate(data["Data"]); } } catch (Exception) { } return null; } private static IniHelper Ini { get; set; } public static string ShowUpdate(JToken jToken) { var strb = new StringBuilder(); try { foreach (var item in jToken) { strb.AppendLine(((DateTime)item["CreateTime"]).ToString("yyyy.MM.dd.HHmm")); strb.AppendLine(item["Message"].ToString()); strb.AppendLine(); } } catch (Exception ex) { } return strb.ToString(); } /// /// 版本数据id /// /// private static string GetVersionId() { Ini = new IniHelper(HttpExtend.MapFile("版本信息.ini")); return Ini.GetValue("Version", "Id"); } /// /// 版本号 /// /// public static string GetVersionName() { Ini = new IniHelper(HttpExtend.MapFile("版本信息.ini")); return DateTime.Parse(Ini.GetValue("Version", "CreateTime")).ToString("yyyy.MM.dd.HHmm"); } /// /// 版本信息 /// public class FileVersion { public int Id { get; set; } public string Name { get; set; } public bool IsEnable { get; set; } private string _Message; /// /// 更新的内容 /// public string Message { get { return ShowMessage(_Message); } set { _Message = value; } } public DateTime CreateTime { get; set; } private string ShowMessage(string Message) { try { var strb = new StringBuilder(); var UpdateContent = Message.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); strb.AppendLine($"{Name} - {CreateTime.ToString("yyyy.MM.dd.HHmmss")}"); strb.AppendLine(); for (int i = 0; i < UpdateContent.Length; i++) { strb.AppendLine(UpdateContent[i]); } } catch (Exception ex) { } return Message; } } } }