#pragma warning disable VSTHRD100 // 避免使用 Async Void 方法 private async void PageShelf_Loaded(object sender, RoutedEventArgs e) #pragma warning restore VSTHRD100 // 避免使用 Async Void 方法 { FingerprintManager.SetError += FingerprintManager_SetError; FingerprintManager.Touched += FingerprintManager_Touched; App.TagChanged += CurrentApp_TagChanged; RfidManager.ListLocks += RfidManager_ListLocks; RfidManager.ClearCache(); // 注:将来也许可以通过(RFID 以外的)其他方式输入图书号码 if (string.IsNullOrEmpty(RfidManager.Url)) { this.SetGlobalError("rfid", "尚未配置 RFID 中心 URL"); } _layer = AdornerLayer.GetAdornerLayer(this.mainGrid); _adorner = new LayoutAdorner(this); { List <string> style = new List <string>(); if (string.IsNullOrEmpty(App.RfidUrl) == false) { style.Add("rfid"); } if (string.IsNullOrEmpty(App.FingerprintUrl) == false) { style.Add("fingerprint"); } if (string.IsNullOrEmpty(App.FaceUrl) == false) { style.Add("face"); } this.patronControl.SetStartMessage(StringUtil.MakePathList(style)); } // RfidManager.LockCommands = DoorControl.GetLockCommands(); await FillAsync(new CancellationToken()); }
internal void InitializeLayer(Visual visual) { _layer = AdornerLayer.GetAdornerLayer(visual); _adorner = new LayoutAdorner(this); }
// EventProxy eventProxy; private void PageBorrow_Loaded(object sender, RoutedEventArgs e) { // throw new Exception("test"); _layer = AdornerLayer.GetAdornerLayer(this.mainGrid); _adorner = new LayoutAdorner(this); // 准备指纹通道 List <string> errors = new List <string>(); if (string.IsNullOrEmpty(App.FingerprintUrl) == false) { #if NO eventProxy = new EventProxy(); eventProxy.MessageArrived += new MessageArrivedEvent(eventProxy_MessageArrived); #endif _fingerprintChannel = FingerPrint.StartFingerprintChannel( App.FingerprintUrl, out string strError); if (_fingerprintChannel == null) { errors.Add($"启动指纹通道时出错: {strError}"); } // https://stackoverflow.com/questions/7608826/how-to-remote-events-in-net-remoting #if NO _fingerprintChannel.Object.MessageArrived += new MessageArrivedEvent(eventProxy.LocallyHandleMessageArrived); #endif try { _fingerprintChannel.Object.GetMessage("clear"); _fingerprintChannel.Started = true; } catch (Exception ex) { if (ex is RemotingException && (uint)ex.HResult == 0x8013150b) { errors.Add($"启动指纹通道时出错: “指纹中心”({App.FingerprintUrl})没有响应"); } else { errors.Add($"启动指纹通道时出错(2): {ex.Message}"); } } } // 准备 RFID 通道 if (string.IsNullOrEmpty(App.RfidUrl) == false) { _rfidChannel = RFID.StartRfidChannel( App.RfidUrl, out string strError); if (_rfidChannel == null) { errors.Add($"启动 RFID 通道时出错: {strError}"); } try { var result = _rfidChannel.Object.ListReaders(); // TODO: 某处界面可以显示当前连接的读卡器名字 // 看看是否有至少一个读卡器 if (result.Readers.Length == 0) { errors.Add("当前指纹中心没有任何连接的读卡器。请检查读卡器是否正确连接"); } else { _rfidChannel.Started = true; } } catch (Exception ex) { if (ex is RemotingException && (uint)ex.HResult == 0x8013150b) { errors.Add($"启动 RFID 通道时出错: “RFID-中心”({App.RfidUrl})没有响应"); } else { errors.Add($"启动 RFID 通道时出错: {ex.Message}"); } } } else { errors.Add($"尚未配置 RFID 接口 URL"); } if (errors.Count > 0) { this.Error = StringUtil.MakePathList(errors, "; "); } // https://stackoverflow.com/questions/13396582/wpf-user-control-throws-design-time-exception if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) { _timer = new System.Threading.Timer( new System.Threading.TimerCallback(timerCallback), null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)); } }