// 2020/9/17 public static void BeginUpdate( TimeSpan firstDelay, TimeSpan idleLength, CancellationToken token, delegate_showText func_showText) { if (ApplicationDeployment.IsNetworkDeployed == false) { return; } Task.Factory.StartNew(async() => { try { // 第一次延迟 await Task.Delay(firstDelay, token); while (token.IsCancellationRequested == false) { // -1 出错 // 0 没有发现更新 // 1 已经更新,重启可使用新版本 NormalResult result = ClientInfo.InstallUpdateSync(); WriteInfoLog($"后台 ClickOnce 自动更新返回: {result.ToString()}"); if (result.Value == -1) { func_showText?.Invoke("自动更新出错: " + result.ErrorInfo, 2); } else if (result.Value == 1) { func_showText?.Invoke(result.ErrorInfo, 1); return; // 只要更新了一次就返回 } else if (string.IsNullOrEmpty(result.ErrorInfo) == false) { func_showText?.Invoke(result.ErrorInfo, 0); } // 以后的每次延迟 await Task.Delay(idleLength, token); } } catch (OperationCanceledException) { } catch (Exception ex) { WriteErrorLog($"后台 ClickOnce 自动更新出现异常: {ExceptionUtil.GetDebugText(ex)}"); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
// parameters: // uid_table 返回 UID --> PII 对照表 public static NormalResult DownloadUidTable( List <string> item_dbnames, Hashtable uid_table, delegate_showText func_showProgress, // Delegate_writeLog writeLog, CancellationToken token) { WpfClientInfo.WriteInfoLog($"开始下载全部册记录到本地缓存"); LibraryChannel channel = App.CurrentApp.GetChannel(); var old_timeout = channel.Timeout; channel.Timeout = TimeSpan.FromMinutes(5); // 设置 5 分钟。因为册记录检索需要一定时间 try { if (item_dbnames == null) { long lRet = channel.GetSystemParameter( null, "item", "dbnames", out string strValue, out string strError); if (lRet == -1) { return new NormalResult { Value = -1, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() } } ; item_dbnames = StringUtil.SplitList(strValue); StringUtil.RemoveBlank(ref item_dbnames); } foreach (string dbName in item_dbnames) { func_showProgress?.Invoke($"正在从 {dbName} 获取信息 ..."); int nRedoCount = 0; REDO: if (token.IsCancellationRequested) { return new NormalResult { Value = -1, ErrorInfo = "用户中断" } } ; // 检索全部读者库记录 long lRet = channel.SearchItem(null, dbName, // "<all>", "", -1, "__id", "left", "zh", null, // strResultSetName "", // strSearchStyle "", // strOutputStyle out string strError); if (lRet == -1) { WpfClientInfo.WriteErrorLog($"SearchItem() 出错, strError={strError}, channel.ErrorCode={channel.ErrorCode}"); // 一次重试机会 if (lRet == -1 && (channel.ErrorCode == ErrorCode.RequestCanceled || channel.ErrorCode == ErrorCode.RequestError) && nRedoCount < 2) { nRedoCount++; goto REDO; } return(new NormalResult { Value = -1, ErrorInfo = strError, ErrorCode = channel.ErrorCode.ToString() }); } long hitcount = lRet; WpfClientInfo.WriteInfoLog($"{dbName} 共检索命中册记录 {hitcount} 条"); // 把超时时间改短一点 channel.Timeout = TimeSpan.FromSeconds(20); DateTime search_time = DateTime.Now; int skip_count = 0; int error_count = 0; if (hitcount > 0) { string strStyle = "id,cols,format:@coldef:*/barcode|*/location|*/uid"; // 获取和存储记录 ResultSetLoader loader = new ResultSetLoader(channel, null, null, strStyle, // $"id,xml,timestamp", "zh"); // loader.Prompt += this.Loader_Prompt; int i = 0; foreach (DigitalPlatform.LibraryClient.localhost.Record record in loader) { if (token.IsCancellationRequested) { return new NormalResult { Value = -1, ErrorInfo = "用户中断" } } ; if (record.Cols != null) { string barcode = ""; if (record.Cols.Length > 0) { barcode = record.Cols[0]; } string location = ""; if (record.Cols.Length > 1) { location = record.Cols[1]; } string uid = ""; if (record.Cols.Length > 2) { uid = record.Cols[2]; } if (string.IsNullOrEmpty(barcode) == false && string.IsNullOrEmpty(uid) == false) { uid_table[uid] = barcode; } } i++; } } WpfClientInfo.WriteInfoLog($"dbName='{dbName}'。skip_count={skip_count}, error_count={error_count}"); } return(new NormalResult { Value = uid_table.Count, }); } catch (Exception ex) { WpfClientInfo.WriteErrorLog($"DownloadItemRecordAsync() 出现异常:{ExceptionUtil.GetDebugText(ex)}"); return(new NormalResult { Value = -1, ErrorInfo = $"DownloadItemRecordAsync() 出现异常:{ex.Message}" }); } finally { channel.Timeout = old_timeout; App.CurrentApp.ReturnChannel(channel); WpfClientInfo.WriteInfoLog($"结束下载全部读者记录到本地缓存"); } }