// 第二阶段:填充图书信息的 PII 和 Title 字段 void FillBookFields() { #if NO RfidChannel channel = RFID.StartRfidChannel(App.RfidUrl, out string strError); if (channel == null) { throw new Exception(strError); } #endif try { foreach (Entity entity in _entities) { if (_cancelRefresh == null || _cancelRefresh.IsCancellationRequested) { return; } if (entity.FillFinished == true) { continue; } //if (string.IsNullOrEmpty(entity.Error) == false) // continue; // 获得 PII // 注:如果 PII 为空,文字重要填入 "(空)" if (string.IsNullOrEmpty(entity.PII)) { // var result = channel.Object.GetTagInfo("*", entity.UID); var result = GetTagInfo(_rfidChannel, entity.UID); if (result.Value == -1) { entity.SetError(result.ErrorInfo); continue; } Debug.Assert(result.TagInfo != null); entity.TagInfo = result.TagInfo; LogicChip chip = LogicChip.From(result.TagInfo.Bytes, (int)result.TagInfo.BlockSize, "" // tag.TagInfo.LockStatus ); string pii = chip.FindElement(ElementOID.PII)?.Text; entity.PII = GetCaption(pii); } // 获得 Title // 注:如果 Title 为空,文字中要填入 "(空)" if (string.IsNullOrEmpty(entity.Title) && string.IsNullOrEmpty(entity.PII) == false && entity.PII != "(空)") { var result = GetEntityData(entity.PII, out string title, out string item_xml, out string item_recpath); if (result.Value == -1) { entity.SetError(result.ErrorInfo); continue; } entity.Title = GetCaption(title); // entity.ItemXml = item_xml; entity.SetData(item_recpath, item_xml); } entity.SetError(null); entity.FillFinished = true; } booksControl.SetBorrowable(); } catch (Exception ex) { #if NO this.error.Text = ex.Message; this.error.Visibility = Visibility.Visible; #endif this.Error = ex.Message; } finally { #if NO RFID.EndRfidChannel(channel); #endif } }
// 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)); } }