void ProcessTag(TagAndData tag) { var entity = InventoryData.AddEntity(tag, out bool isNewly); var info = entity.Tag as ProcessInfo; if (info == null) { info = new ProcessInfo(); entity.Tag = info; } if (isNewly) { App.Invoke(new Action(() => { _entities.Add(entity); })); } if (string.IsNullOrEmpty(entity.PII) == false && string.IsNullOrEmpty(info.State)) { info.State = "processing"; InventoryData.AppendList(entity); InventoryData.ActivateInventory(); } }
// SetBorrowed("") 可以清除列表 public void SetBorrowed(string patron_xml) { _borrowedEntities.Clear(); if (string.IsNullOrEmpty(patron_xml) == false) { XmlDocument dom = new XmlDocument(); dom.LoadXml(patron_xml); // 用 hashtable 保存一下每个 entity 的原始序 // Hashtable originIndexTable = new Hashtable(); int i = 0; // 插入位置 // List<Entity> entities = new List<Entity>(); XmlNodeList borrows = dom.DocumentElement.SelectNodes("borrows/borrow"); foreach (XmlElement borrow in borrows) { string barcode = borrow.GetAttribute("barcode"); string oi = borrow.GetAttribute("oi"); string overflow = borrow.GetAttribute("overflow"); // 2020/7/26 string borrowInfo = null; { string borrowDate = borrow.GetAttribute("borrowDate"); string returningDate = borrow.GetAttribute("returningDate"); string period = borrow.GetAttribute("borrowPeriod"); if (string.IsNullOrEmpty(borrowDate)) { borrowInfo = null; } else { borrowInfo = $"借书日期:\t{Entity.ToDate(borrowDate)}\n期限:\t\t{period}\n应还日期:\t{Entity.ToDate(returningDate)}"; } } var new_entity = new Entity { PII = barcode, OI = oi, // 2020/9/8 Container = _borrowedEntities, BorrowInfo = borrowInfo }; // 2020/4/17 不用排序,在添加时临时决定是插入到前部还是追加 if (IsState(new_entity, "overflow") == true || string.IsNullOrEmpty(overflow) == false) { SetState(new_entity, "overflow"); _borrowedEntities.Insert(i++, new_entity); } else { _borrowedEntities.Add(new_entity); } } } }
// 初始化时列出当前馆藏地应有的全部图书 // 本函数中,只给 Entity 对象里面设置好了 PII,其他成员尚未设置 static void FillLocationBooks(EntityCollection entities, string location, CancellationToken token) { var channel = App.CurrentApp.GetChannel(); try { long lRet = channel.SearchItem(null, "<全部>", location, 5000, "馆藏地点", "exact", "zh", "shelfResultset", "", "", out string strError); if (lRet == -1) { throw new ChannelException(channel.ErrorCode, strError); } string strStyle = "id,cols,format:@coldef:*/barcode|*/borrower"; ResultSetLoader loader = new ResultSetLoader(channel, null, "shelfResultset", strStyle, "zh"); foreach (DigitalPlatform.LibraryClient.localhost.Record record in loader) { token.ThrowIfCancellationRequested(); string pii = record.Cols[0]; Application.Current.Dispatcher.Invoke(new Action(() => { entities.Add(pii); })); } } finally { App.CurrentApp.ReturnChannel(channel); } }
public void SetBorrowed(string patron_xml) { _borrowedEntities.Clear(); XmlDocument dom = new XmlDocument(); dom.LoadXml(patron_xml); XmlNodeList borrows = dom.DocumentElement.SelectNodes("borrows/borrow"); foreach (XmlElement borrow in borrows) { string barcode = borrow.GetAttribute("barcode"); _borrowedEntities.Add(new Entity { PII = barcode, Container = _borrowedEntities }); } }
// SetBorrowed("") 可以清除列表 public void SetBorrowed(string patron_xml) { _borrowedEntities.Clear(); if (string.IsNullOrEmpty(patron_xml) == false) { XmlDocument dom = new XmlDocument(); dom.LoadXml(patron_xml); // 用 hashtable 保存一下每个 entity 的原始序 // Hashtable originIndexTable = new Hashtable(); int i = 0; // 插入位置 // List<Entity> entities = new List<Entity>(); XmlNodeList borrows = dom.DocumentElement.SelectNodes("borrows/borrow"); foreach (XmlElement borrow in borrows) { string barcode = borrow.GetAttribute("barcode"); string overflow = borrow.GetAttribute("overflow"); var new_entity = new Entity { PII = barcode, Container = _borrowedEntities }; // 2020/4/17 不用排序,在添加时临时决定是插入到前部还是追加 if (IsState(new_entity, "overflow") == true || string.IsNullOrEmpty(overflow) == false) { SetState(new_entity, "overflow"); _borrowedEntities.Insert(i++, new_entity); } else { _borrowedEntities.Add(new_entity); } } } }
// 筛选出需要 GetTagInfo() 的那些标签 async Task FilterTags(BaseChannel <IRfid> channel, List <TagAndData> tags) { // PII 尚为空的那些 entities List <Entity> empty_piis = new List <Entity>(); // 其他 entities List <Entity> rests = new List <Entity>(); foreach (var tag in tags) { var entity = InventoryData.AddEntity(tag, out bool isNewly); var info = entity.Tag as ProcessInfo; if (info == null) { info = new ProcessInfo(); entity.Tag = info; } if (isNewly) { App.Invoke(new Action(() => { _entities.Add(entity); })); } if (string.IsNullOrEmpty(entity.PII)) { empty_piis.Add(entity); } else { // 对 PII 不为空的,但有任务没有完成的,要加入列表寻求再次被后台处理 rests.Add(entity); /* * if (info.IsLocation == false) * { * InventoryData.AppendList(entity); * InventoryData.ActivateInventory(); * } */ } // 如果发现 PII 不为空的层架标,要用于切换当前 CurrentShelfNo if (info != null && info.IsLocation == true) { SwitchCurrentShelfNo(entity); if (isNewly == false) { App.Invoke(new Action(() => { _entities.MoveToTail(entity); })); } } } // 准备音阶 SoundMaker.InitialSequence(empty_piis.Count); bool speaked = false; // 集中 GetTagInfo() foreach (var entity in empty_piis) { var info = entity.Tag as ProcessInfo; SoundMaker.NextSound(); FillEntity(channel, entity, (e) => { // 说过一次便不再说 if (speaked == true) { return(false); } speaked = SpeakLocation(e); return(speaked); }); // 进入后台队列 if (string.IsNullOrEmpty(entity.PII) == false && info.IsLocation == false) { InventoryData.AppendList(entity); InventoryData.ActivateInventory(); } } // 停止音阶响声 SoundMaker.StopCurrent(); // 其余的也要进入后台队列 foreach (var entity in rests) { var info = entity.Tag as ProcessInfo; if (info.IsLocation == true) { continue; } // 尝试重新赋予目标 location 和 currentLocation,观察参数是否发生变化、重做后台任务 var old_targetLocation = info.TargetLocation; var old_targetShelfNo = info.TargetShelfNo; var old_targetCurrentLocation = info.TargetCurrentLocation; var result = SetTargetCurrentLocation(info); if (result.Value != -1) { if (old_targetLocation != info.TargetLocation || old_targetShelfNo != info.TargetShelfNo || old_targetCurrentLocation != info.TargetCurrentLocation) { // 删除条目,这样可以迫使用新 target 重做后台任务 info.SetTaskInfo("setLocation", null); // 视觉上移动到最末行,让操作者意识到发生了重做后台任务 App.Invoke(new Action(() => { _entities.MoveToTail(entity); })); } } if (string.IsNullOrEmpty(entity.PII) == false && info.IsLocation == false) { InventoryData.AppendList(entity); InventoryData.ActivateInventory(); } } // 2020/11/9 // 执行修改 EAS 任务 foreach (var entity in rests) { var info = entity.Tag as ProcessInfo; // 如果有以前尚未执行成功的修改 EAS 的任务,则尝试再执行一次 if (info != null && info.TargetEas != null && info.ContainTask("changeEAS") == true && info.IsTaskCompleted("changeEAS") == false) { try { if (info.TargetEas == "?") { await InventoryData.VerifyEasAsync(entity); } else { // TODO: 记载轮空和出错的次数。 // result.Value // -1 出错 // 0 标签不在读卡器上所有没有执行 // 1 成功执行修改 await InventoryData.TryChangeEasAsync(entity, info.TargetEas == "on"); } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"FilterTags() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); App.SetError("processing", $"FilterTags() 出现异常: {ex.Message}"); } } } }
// 筛选出需要 GetTagInfo() 的那些标签 void FilterTags(BaseChannel <IRfid> channel, List <TagAndData> tags) { List <Entity> entities1 = new List <Entity>(); List <Entity> all = new List <Entity>(); foreach (var tag in tags) { var entity = InventoryData.AddEntity(tag, out bool isNewly); var info = entity.Tag as ProcessInfo; if (info == null) { info = new ProcessInfo(); entity.Tag = info; } if (isNewly) { App.Invoke(new Action(() => { _entities.Add(entity); })); } if (string.IsNullOrEmpty(entity.PII)) { entities1.Add(entity); } all.Add(entity); } // 准备音阶 SoundMaker.InitialSequence(entities1.Count); bool speaked = false; // 集中 GetTagInfo() foreach (var entity in entities1) { SoundMaker.NextSound(); FillEntity(channel, entity, (e) => { // 说过一次便不再说 if (speaked == true) { return(false); } speaked = SpeakLocation(e); return(speaked); }); } // 停止音阶响声 SoundMaker.StopCurrent(); // 获取题名等 foreach (var entity in all) { var info = entity.Tag as ProcessInfo; if (string.IsNullOrEmpty(entity.PII) == false && string.IsNullOrEmpty(info.State)) { info.State = "processing"; // 正在获取册信息 InventoryData.AppendList(entity); InventoryData.ActivateInventory(); } } }