private void Heart(object state) { var heartData = GetHeartData(); CAjax ajax = new CAjax(); ajax.postJSON("/api/terminal/active/" + Config.SourceId, heartData, (jsonString) => { var data = ajax.Deserialize(jsonString); if (ajax.getIntValue(data, "code") == 200) { var rst = ajax.getValue(data, "rst"); if (rst != null) { UpdateConfig(rst, ajax, "adsTime", "180"); UpdateConfig(rst, ajax, "password", "8888"); UpdateConfig(rst, ajax, "shutdownTime", "1260"); UpdateConfig(rst, ajax, "name", MachineInfo.HostName); // 定时关机 var shutdownTime = Config.ShutdownTime; var now = DateTime.Now; var minutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute; if (Math.Abs(minutes - shutdownTime) * 60 * 1000 <= HEART_INTVAL * 1.5) { Application.Exit(); return; } string lastVersion = ajax.getStringValue(rst, "lastVersion", "0.0.0"); // 检查版本 if (this.FormatVersion(lastVersion) > this.FormatVersion(Config.Version)) { _webCom.ExecuteScriptAsync("window.__stopAds()"); // 下载更新 this._heartTimer.Dispose(); // 停止心跳 this._heartTimer = null; SafeBeginUpdate(); } } } }, null); }
private void SplashForm_Load(object sender, EventArgs e) { this.SetMessage("正在请求服务器..."); string url = "/api/release/last/" + Config.SourceId + "/" + Config.Version; CAjax ajax = new CAjax(); ajax.getJSON(url, (jsonString) => { var data = ajax.Deserialize(jsonString); if (ajax.getIntValue(data, "code") == 200) { var rst = ajax.getValue(data, "rst"); if (rst != null) { var releaseVersion = ajax.getStringValue(rst, "releaseVersion"); if (FormatVersion(releaseVersion) > FormatVersion(Config.Version)) { this.SetMessageSafe("准备下载最新的资源..."); var zipUrl = Config.getFullUrl("/" + ajax.getStringValue(rst, "releaseFile")); var localPath = Path.Combine(Config.H5Path, "update.zip"); if (!Directory.Exists(Config.H5Path)) { Directory.CreateDirectory(Config.H5Path); } this.DownloadFile(zipUrl, localPath, (isSuccess) => { if (isSuccess) { this.SetMessageSafe("准备解压资源..."); this.UnZipFile(localPath, Config.H5Path, (unzipSuccess) => { if (unzipSuccess) { Config.Version = releaseVersion; this.SetMessageSafe("更新最新的资源成功..."); } else { this.SetMessageSafe("更新最新的资源失败..."); } this.SetupMainSafe(); }); } else { this.SetMessageSafe("下载最新资源失败..."); this.SetupMainSafe(); } }); } else { this.SetMessageSafe("已经是最新版本了..."); this.SetupMainSafe(); } } else { this.SetMessageSafe("请求服务器失败..."); this.SetupMainSafe(); } } else { this.SetMessageSafe("请求服务器失败..."); this.SetupMainSafe(); } }, (error) => { this.SetMessageSafe("请求服务器失败..."); this.SetupMainSafe(); }); }