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); }
public void register(string sn, IJavascriptCallback callback) { if (!MachineInfo.CheckSN(sn)) { callback.ExecuteAsync(false, "注册码不能用"); return; } string parmasString = string.Format("code={0}&sn={1}", MachineInfo.MachineCode, sn); CAjax ajax = new CAjax(); ajax.postJSON("/api/terminal/register", parmasString, (jsonString) => { var data = ajax.Deserialize(jsonString); if (ajax.getIntValue(data, "code") == 200) { Config.SN = sn; (MainForm.ActiveForm as MainForm).HideSNLabel(); callback.ExecuteAsync(true); } else { callback.ExecuteAsync(false, "注册失败,请稍后再试"); } }, (msg) => { callback.ExecuteAsync(false, "网络请求错误,请稍后再试"); }, "PATCH"); callback.ExecuteAsync(true); }
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); }