public static async Task <NormalResult> RenewAsync(string patronBarcode, string itemBarcode) { try { using (var releaser = await _channelLimit.EnterAsync()) { SipChannel channel = await GetChannelAsync(); try { var result = await channel.RenewAsync(patronBarcode, itemBarcode); if (result.Value == -1) { return new NormalResult { Value = -1, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode } } ; if (result.Value == 0) { return new NormalResult { Value = -1, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode } } ; return(new NormalResult()); } finally { ReturnChannel(channel); } } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"RenewAsync() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); return(new GetEntityDataResult { Value = -1, ErrorInfo = $"RenewAsync() 出现异常: {ex.Message}", ErrorCode = ex.GetType().ToString() }); } }
static void ReturnChannel(SipChannel channel) { }
static async Task <NormalResult> DetectSipNetworkAsync() { /* * // testing * return new NormalResult { Value = 1 }; */ try { using (var releaser = await _channelLimit.EnterAsync()) { SipChannel channel = await GetChannelAsync(); try { // -1出错,0不在线,1正常 var result = await channel.ScStatusAsync(); if (result.Value == -1) { return new NormalResult { Value = -1, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode } } ; if (result.Value == 0) { return new NormalResult { Value = 0, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode } } ; return(new NormalResult { Value = result.Value, ErrorInfo = result.ErrorInfo, ErrorCode = result.ErrorCode }); } finally { ReturnChannel(channel); } } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"DetectSipNetworkAsync() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); return(new GetEntityDataResult { Value = -1, ErrorInfo = $"DetectSipNetworkAsync() 出现异常: {ex.Message}", ErrorCode = ex.GetType().ToString() }); } }
// return.Value: // -1 出错 // 0 读者记录没有找到 // 1 成功 public static async Task <GetReaderInfoResult> GetReaderInfoAsync(string pii) { try { using (var releaser = await _channelLimit.EnterAsync()) { SipChannel channel = await GetChannelAsync(); try { List <NormalResult> errors = new List <NormalResult>(); int nRedoCount = 0; REDO_GETITEMINFO: var get_result = await _channel.GetPatronInfoAsync(pii); if (get_result.Value == -1) { return new GetReaderInfoResult { Value = -1, ErrorInfo = get_result.ErrorInfo, ErrorCode = get_result.ErrorCode } } ; /* * else if (get_result.Result.CirculationStatus_2 == "01") * { * errors.Add(new NormalResult * { * Value = -1, * ErrorInfo = get_result.Result.AF_ScreenMessage_o, * ErrorCode = get_result.Result.CirculationStatus_2 * }); * } * else if (get_result.Result.CirculationStatus_2 == "13") * { * errors.Add(new NormalResult * { * Value = -1, * ErrorInfo = get_result.Result.AF_ScreenMessage_o, * ErrorCode = "itemNotFound" * }); * } */ else { XmlDocument readerdom = new XmlDocument(); readerdom.LoadXml("<root />"); // 证状态 string state = "***"; if (get_result.Result.BL_ValidPatron_o == "Y") { state = ""; } DomUtil.SetElementText(readerdom.DocumentElement, "state", state); // 读者证条码号 DomUtil.SetElementText(readerdom.DocumentElement, "barcode", get_result.Result.AA_PatronIdentifier_r); // 姓名 DomUtil.SetElementText(readerdom.DocumentElement, "name", get_result.Result.AE_PersonalName_r); // 可借册数 Patron.SetParamValue(readerdom.DocumentElement, "当前还可借", get_result.Result.BZ_HoldItemsLimit_o); Patron.SetParamValue(readerdom.DocumentElement, "可借总册数", get_result.Result.CB_ChargedItemsLimit_o); // 在借册 var root = readerdom.DocumentElement.AppendChild(readerdom.CreateElement("borrows")) as XmlElement; var items = get_result.Result.AU_ChargedItems_o; if (items != null) { foreach (var item in items) { if (item.Value == null) { continue; } var borrow = root.AppendChild(readerdom.CreateElement("borrow")) as XmlElement; borrow.SetAttribute("barcode", item.Value); } } return(new GetReaderInfoResult { Value = 1, ReaderXml = readerdom.OuterXml, RecPath = "", Timestamp = null }); } } finally { ReturnChannel(channel); } } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"GetEntGetReaderInfoAsyncityDataAsync() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); return(new GetReaderInfoResult { Value = -1, ErrorInfo = $"GetReaderInfoAsync() 出现异常: {ex.Message}", ErrorCode = ex.GetType().ToString() }); } }
// 获得册记录信息和书目摘要信息 // parameters: // style 风格。network 表示只从网络获取册记录;否则优先从本地获取,本地没有再从网络获取册记录。无论如何,书目摘要都是尽量从本地获取 // .Value // 0 没有找到 // 1 找到 public static async Task <GetEntityDataResult> GetEntityDataAsync(string pii, string style) { bool network = StringUtil.IsInList("network", style); try { using (var releaser = await _channelLimit.EnterAsync()) { SipChannel channel = await GetChannelAsync(); try { GetEntityDataResult result = null; List <NormalResult> errors = new List <NormalResult>(); EntityItem entity_record = null; // *** // 第一步:获取册记录 { // 再尝试从 dp2library 服务器获取 // TODO: ItemXml 和 BiblioSummary 可以考虑在本地缓存一段时间 int nRedoCount = 0; REDO_GETITEMINFO: var get_result = await _channel.GetItemInfoAsync("", pii); if (get_result.Value == -1) { errors.Add(new NormalResult { Value = -1, ErrorInfo = get_result.ErrorInfo, ErrorCode = get_result.ErrorCode }); } else if (get_result.Result.CirculationStatus_2 == "01") { errors.Add(new NormalResult { Value = -1, ErrorInfo = get_result.Result.AF_ScreenMessage_o, ErrorCode = get_result.Result.CirculationStatus_2 }); } else if (get_result.Result.CirculationStatus_2 == "13") { errors.Add(new NormalResult { Value = -1, ErrorInfo = get_result.Result.AF_ScreenMessage_o, ErrorCode = "itemNotFound" }); } else { XmlDocument itemdom = new XmlDocument(); itemdom.LoadXml("<root />"); string state = ""; if (get_result.Result.CirculationStatus_2 == "12") { state = "丢失"; } DomUtil.SetElementText(itemdom.DocumentElement, "state", state); DomUtil.SetElementText(itemdom.DocumentElement, "barcode", get_result.Result.AB_ItemIdentifier_r); DomUtil.SetElementText(itemdom.DocumentElement, "location", get_result.Result.AQ_PermanentLocation_o); DomUtil.SetElementText(itemdom.DocumentElement, "currentLocation", get_result.Result.AP_CurrentLocation_o); DomUtil.SetElementText(itemdom.DocumentElement, "accessNo", get_result.Result.CH_ItemProperties_o); // 借书时间 { string borrowDateString = get_result.Result.CM_HoldPickupDate_18; if (string.IsNullOrEmpty(borrowDateString) == false) { if (DateTime.TryParseExact(borrowDateString, "yyyyMMdd HHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime borrowDate)) { DomUtil.SetElementText(itemdom.DocumentElement, "borrowDate", DateTimeUtil.Rfc1123DateTimeStringEx(borrowDate)); DomUtil.SetElementText(itemdom.DocumentElement, "borrower", "***"); } else { // 报错,时间字符串格式错误,无法解析 } } } // 应还书时间 { string returnningDateString = get_result.Result.AH_DueDate_o; if (string.IsNullOrEmpty(returnningDateString) == false) { if (DateTime.TryParseExact(returnningDateString, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime returningDate)) { DomUtil.SetElementText(itemdom.DocumentElement, "returningDate", DateTimeUtil.Rfc1123DateTimeStringEx(returningDate)); } else { // 报错,时间字符串格式错误,无法解析 } } } result = new GetEntityDataResult { Value = 1, ItemXml = itemdom.OuterXml, ItemRecPath = get_result.Result.AB_ItemIdentifier_r, Title = get_result.Result.AJ_TitleIdentifier_r, }; /* * // 保存到本地数据库 * await AddOrUpdateAsync(context, new EntityItem * { * PII = pii, * Xml = item_xml, * RecPath = item_recpath, * Timestamp = timestamp, * }); */ } } // *** /// 第二步:获取书目摘要 // 完全成功 if (result != null && errors.Count == 0) { return(result); } if (result == null) { return new GetEntityDataResult { Value = errors[0].Value, ErrorInfo = errors[0].ErrorInfo, ErrorCode = errors[0].ErrorCode } } ; result.ErrorInfo = errors[0].ErrorInfo; result.ErrorCode = errors[0].ErrorCode; return(result); } finally { ReturnChannel(channel); } } } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"GetEntityDataAsync() 出现异常: {ExceptionUtil.GetDebugText(ex)}"); return(new GetEntityDataResult { Value = -1, ErrorInfo = $"GetEntityDataAsync() 出现异常: {ex.Message}", ErrorCode = ex.GetType().ToString() }); } }