Exemple #1
0
        void PatronClear()
        {
            _patron.Clear();

            if (this.patronControl.BorrowedEntities.Count > 0)
            {
                if (!Application.Current.Dispatcher.CheckAccess())
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        this.patronControl.BorrowedEntities.Clear();
                    }));
                }
                else
                {
                    this.patronControl.BorrowedEntities.Clear();
                }
            }
        }
Exemple #2
0
        void Refresh()
        {
            if (_rfidChannel == null || _rfidChannel.Started == false)
            {
                return;
            }

            // 防止重入
            int v = Interlocked.Increment(ref this._inRefresh);

            if (v > 1)
            {
                Interlocked.Decrement(ref this._inRefresh);
                return;
            }

            _cancelRefresh = new CancellationTokenSource();
            try
            {
                // 获得所有协议类型的标签
                var result = _rfidChannel.Object.ListTags("*",
                                                          null
                                                          // "getTagInfo"
                                                          );

                List <OneTag> books   = new List <OneTag>();
                List <OneTag> patrons = new List <OneTag>();

                // 分离图书标签和读者卡标签
                foreach (OneTag tag in result.Results)
                {
                    if (tag.Protocol == InventoryInfo.ISO14443A)
                    {
                        patrons.Add(tag);
                    }
                    else if (tag.Protocol == InventoryInfo.ISO15693)
                    {
                        var gettaginfo_result = GetTagInfo(_rfidChannel, tag.UID);
                        if (gettaginfo_result.Value == -1)
                        {
                            this.Error = gettaginfo_result.ErrorInfo;
                            continue;
                        }
                        TagInfo info = gettaginfo_result.TagInfo;
                        // 观察 typeOfUsage 元素
                        var chip = LogicChip.From(info.Bytes,
                                                  (int)info.BlockSize,
                                                  "");
                        string typeOfUsage = chip.FindElement(ElementOID.TypeOfUsage)?.Text;
                        if (typeOfUsage != null && typeOfUsage.StartsWith("8"))
                        {
                            patrons.Add(tag);
                        }
                        else
                        {
                            books.Add(tag);
                        }
                    }
                    else
                    {
                        books.Add(tag);
                    }
                }

                List <Entity> new_entities = new List <Entity>();
                {
                    // 比较当前集合。对当前集合进行增删改
                    bool changed = false;
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        changed = _entities.Refresh(books, ref new_entities);
                    }));

                    if (_entities.Count == 0 &&
                        changed == true &&  // 限定为,当数量减少到 0 这一次,才进行清除
                        _patron.Source == "fingerprint")
                    {
                        _patron.Clear();
                    }
                }

                // 当列表为空的时候,主动清空一次 tag 缓存。这样读者可以用拿走全部标签一次的方法来迫使清除缓存(比如中途利用内务修改过 RFID 标签的 EAS)
                if (_entities.Count == 0 && _tagTable.Count > 0)
                {
                    ClearTagTable(null);
                }

                if (patrons.Count == 1)
                {
                    _patron.Source = "";
                }

                if (_patron.Source == "fingerprint")
                {
                }
                else
                {
                    if (patrons.Count > 1)
                    {
                        // 读卡器上放了多张读者卡
                        _patron.Error = "读卡器上放了多张读者卡。请拿走多余的";
                    }
                    if (patrons.Count == 1)
                    {
                        _patron.Fill(patrons[0]);
                    }
                    else
                    {
                        _patron.Clear();
                    }
                }


                GetPatronFromFingerprint();

                FillBookFields();
                FillPatronDetail();

                CheckEAS(new_entities);
            }
            catch (Exception ex)
            {
                this.Error = $"后台刷新过程出现异常: {ex.Message}";
                return;
            }
            finally
            {
                _cancelRefresh = null;
                Interlocked.Decrement(ref this._inRefresh);
            }
        }