Esempio n. 1
0
        static async Task ProcessingAsync()
        {
            var list = CopyList();

            foreach (var entity in list)
            {
                // 获得册记录和书目摘要
                // .Value
                //      -1  出错
                //      0   没有找到
                //      1   找到
                var result = await LibraryChannelUtil.GetEntityDataAsync(entity.PII, "network");

                if (result.Value == -1)
                {
                    entity.AppendError(result.ErrorInfo, "red", result.ErrorCode);
                }
                else
                {
                    if (string.IsNullOrEmpty(result.Title) == false)
                    {
                        entity.Title = PageBorrow.GetCaption(result.Title);
                    }
                    if (string.IsNullOrEmpty(result.ItemXml) == false)
                    {
                        entity.SetData(result.ItemRecPath, result.ItemXml);
                    }
                }
            }

            // 把处理过的 entity 从 list 中移走
            RemoveList(list);
        }
Esempio n. 2
0
        // 第二阶段:填充图书信息的 PII 和 Title 字段
        async Task FillBookFields(BaseChannel <IRfid> channel,
                                  List <Entity> entities,
                                  CancellationToken token)
        {
            try
            {
                foreach (Entity entity in entities)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    if (entity.FillFinished == true)
                    {
                        continue;
                    }

                    // 获得 PII
                    // 注:如果 PII 为空,文字中要填入 "(空)"
                    if (string.IsNullOrEmpty(entity.PII))
                    {
                        if (entity.TagInfo == null)
                        {
                            continue;
                        }

                        Debug.Assert(entity.TagInfo != null);

                        LogicChip chip = LogicChip.From(entity.TagInfo.Bytes,
                                                        (int)entity.TagInfo.BlockSize,
                                                        "" // tag.TagInfo.LockStatus
                                                        );
                        string pii = chip.FindElement(ElementOID.PII)?.Text;
                        entity.PII = PageBorrow.GetCaption(pii);
                    }

                    // 获得 Title
                    // 注:如果 Title 为空,文字中要填入 "(空)"
                    if (string.IsNullOrEmpty(entity.Title) &&
                        string.IsNullOrEmpty(entity.PII) == false && entity.PII != "(空)")
                    {
                        GetEntityDataResult result = await
                                                     Task <GetEntityDataResult> .Run(() =>
                        {
                            return(GetEntityData(entity.PII));
                        });

                        if (result.Value == -1)
                        {
                            entity.SetError(result.ErrorInfo);
                            continue;
                        }
                        entity.Title = PageBorrow.GetCaption(result.Title);
                        entity.SetData(result.ItemRecPath, result.ItemXml);
                    }

                    entity.SetError(null);
                    entity.FillFinished = true;
                }

                booksControl.SetBorrowable();
            }
            catch (Exception ex)
            {
                SetGlobalError("current", ex.Message);
            }
        }