public void setName(string name, IJavascriptCallback callback) { if (name == Config.TerminalName) { callback.ExecuteAsync(true); return; } string parmasString = string.Format("code={0}&name={1}", MachineInfo.MachineCode, name); CAjax ajax = new CAjax(); ajax.postJSON("/api/terminal/name", parmasString, (jsonString) => { var data = ajax.Deserialize(jsonString); if (ajax.getIntValue(data, "code") == 200) { Config.TerminalName = name; callback.ExecuteAsync(true); } else { callback.ExecuteAsync(false, "修改名称失败,请稍后再试"); } }, (msg) => { callback.ExecuteAsync(false, "网络请求错误,请稍后再试"); }, "PATCH"); callback.ExecuteAsync(true); }
private void UpdateConfig(object obj, CAjax ajax, string key, string defaultValue) { var currentvalue = Config.getValue(key, defaultValue); var value = ajax.getStringValue(obj, key, currentvalue); Config.setValue(key, value); }
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(); }); }