private void ToolStripMenuItem_testLockBlocks_Click(object sender, EventArgs e) { GetTagInfoResult result = _driver.GetTagInfo(GetCurrentReaderName(), null); MessageBox.Show(this, "初始芯片内容: " + result.ToString()); if (result.Value == -1) { return; } TagInfo new_chip = result.TagInfo.Clone(); new_chip.Bytes = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00"); new_chip.LockStatus = "ll....www"; NormalResult write_result = _driver.WriteTagInfo(GetCurrentReaderName(), result.TagInfo, new_chip); MessageBox.Show(this, write_result.ToString()); }
// 2020/9/17 public static void BeginUpdate( TimeSpan firstDelay, TimeSpan idleLength, CancellationToken token, delegate_showText func_showText) { if (ApplicationDeployment.IsNetworkDeployed == false) { return; } Task.Factory.StartNew(async() => { try { // 第一次延迟 await Task.Delay(firstDelay, token); while (token.IsCancellationRequested == false) { // -1 出错 // 0 没有发现更新 // 1 已经更新,重启可使用新版本 NormalResult result = ClientInfo.InstallUpdateSync(); WriteInfoLog($"后台 ClickOnce 自动更新返回: {result.ToString()}"); if (result.Value == -1) { func_showText?.Invoke("自动更新出错: " + result.ErrorInfo, 2); } else if (result.Value == 1) { func_showText?.Invoke(result.ErrorInfo, 1); return; // 只要更新了一次就返回 } else if (string.IsNullOrEmpty(result.ErrorInfo) == false) { func_showText?.Invoke(result.ErrorInfo, 0); } // 以后的每次延迟 await Task.Delay(idleLength, token); } } catch (OperationCanceledException) { } catch (Exception ex) { WriteErrorLog($"后台 ClickOnce 自动更新出现异常: {ExceptionUtil.GetDebugText(ex)}"); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
// 启动一般监控任务 public static void StartMonitorTask() { if (_monitorTask != null) { return; } CancellationToken token = App.CancelToken; token.Register(() => { _eventMonitor.Set(); }); _monitorTask = Task.Factory.StartNew(async() => { WpfClientInfo.WriteInfoLog("全局监控专用线程开始"); try { while (token.IsCancellationRequested == false) { // await Task.Delay(TimeSpan.FromSeconds(10)); _eventMonitor.WaitOne(_monitorIdleLength); token.ThrowIfCancellationRequested(); // 检查小票打印机状态 var check_result = CheckPosPrinter(); if (check_result.Value == -1) { App.SetError("printer", "小票打印机状态异常"); } else if (StringUtil.IsInList("paperout", check_result.ErrorCode)) { App.SetError("printer", "小票打印机缺纸"); } else if (StringUtil.IsInList("paperwillout", check_result.ErrorCode)) { App.SetError("printer", "小票打印机即将缺纸"); } else { App.SetError("printer", null); } // 检查升级绿色 dp2ssl if (_needReboot == false && StringUtil.IsDevelopMode() == false && ApplicationDeployment.IsNetworkDeployed == false && DateTime.Now - _lastUpdateTime > _updatePeriod) { WpfClientInfo.WriteInfoLog("开始自动检查升级"); // result.Value: // -1 出错 // 0 经过检查发现没有必要升级 // 1 成功 // 2 成功,但需要立即重新启动计算机才能让复制的文件生效 var update_result = await GreenInstall.GreenInstaller.InstallFromWeb(GreenInstall.GreenInstaller.dp2ssl_weburl, // "http://dp2003.com/dp2ssl/v1_dev", "c:\\dp2ssl", "delayExtract,updateGreenSetupExe,clearStateFile,debugInfo", //true, //true, token, null); if (update_result.Value == -1) { WpfClientInfo.WriteErrorLog($"自动检查升级出错: {update_result.ErrorInfo}"); } else { WpfClientInfo.WriteInfoLog($"结束自动检查升级 update_result:{update_result.ToString()}"); } // 2020/9/1 WpfClientInfo.WriteInfoLog($"InstallFromWeb() 调试信息如下:\r\n{update_result.DebugInfo}"); if (update_result.Value == 1 || update_result.Value == 2) { if (update_result.Value == 1) { App.TriggerUpdated("重启 dp2ssl(greensetup) 可使用新版本"); PageShelf.TrySetMessage(null, "dp2SSL 升级文件已经下载成功,下次重启 dp2ssl(greensetup) 时可自动升级到新版本"); } else if (update_result.Value == 2) { _needReboot = true; App.TriggerUpdated("重启计算机可使用新版本"); PageShelf.TrySetMessage(null, "dp2SSL 升级文件已经下载成功,下次重启计算机时可自动升级到新版本"); } } _lastUpdateTime = DateTime.Now; } // 2020/9/15 // 检查升级 ClickOnce dp2ssl if (StringUtil.IsDevelopMode() == false && ApplicationDeployment.IsNetworkDeployed == true && DateTime.Now - _lastUpdateTime > _updatePeriod) { try { // result.Value: // -1 出错 // 0 没有发现新版本 // 1 发现新版本,重启后可以使用新版本 NormalResult result = WpfClientInfo.InstallUpdateSync(); WpfClientInfo.WriteInfoLog($"ClickOnce 后台升级 dp2ssl 返回: {result.ToString()}"); if (result.Value == -1) { WpfClientInfo.WriteErrorLog($"升级出错: {result.ErrorInfo}"); } else if (result.Value == 1) { WpfClientInfo.WriteInfoLog($"升级成功: {result.ErrorInfo}"); App.TriggerUpdated(result.ErrorInfo); // MessageBox.Show(result.ErrorInfo); } else if (string.IsNullOrEmpty(result.ErrorInfo) == false) { WpfClientInfo.WriteInfoLog($"{result.ErrorInfo}"); } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"后台 ClickOnce 自动升级出现异常: {ExceptionUtil.GetDebugText(ex)}"); } _lastUpdateTime = DateTime.Now; } } _monitorTask = null; } catch (OperationCanceledException) { } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"全局监控专用线程出现异常: {ExceptionUtil.GetDebugText(ex)}"); App.SetError("global_monitor", $"全局监控专用线程出现异常: {ex.Message}"); } finally { WpfClientInfo.WriteInfoLog("全局监控专用线程结束"); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
private void ToolStripMenuItem_testWriteContentToNewChip_Click(object sender, EventArgs e) { #if NO // 准备好一个芯片内容 byte[] data = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00" ); // 测试 BlockRange.GetBlockRanges() List <BlockRange> ranges = BlockRange.GetBlockRanges( data, "ll....lll", 4); Debug.Assert(ranges[0].BlockCount == 2); Debug.Assert(ranges[0].Locked == true); Debug.Assert(ranges[0].Bytes.SequenceEqual( Element.FromHexString( @"91 00 05 1c be 99 1a 14" ) )); Debug.Assert(ranges[1].BlockCount == 4); Debug.Assert(ranges[1].Locked == false); Debug.Assert(ranges[1].Bytes.SequenceEqual( Element.FromHexString( @"02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6" ) )); Debug.Assert(ranges[2].BlockCount == 3); Debug.Assert(ranges[2].Locked == true); Debug.Assert(ranges[2].Bytes.SequenceEqual( Element.FromHexString( @"83 02 07 ac c0 9e ba a0 6f 6b 00 00" ) )); #endif GetTagInfoResult result = _driver.GetTagInfo(GetCurrentReaderName(), null); MessageBox.Show(this, "初始芯片内容: " + result.ToString()); TagInfo new_chip = result.TagInfo.Clone(); new_chip.Bytes = Element.FromHexString( @"91 00 05 1c be 99 1a 14 02 01 d0 14 02 04 b3 46 07 44 1c b6 e2 e3 35 d6 83 02 07 ac c0 9e ba a0 6f 6b 00 00"); new_chip.LockStatus = "ww....www"; NormalResult write_result = _driver.WriteTagInfo(GetCurrentReaderName(), result.TagInfo, new_chip); MessageBox.Show(this, write_result.ToString()); }