public void SaveHanzi(HanziInfo hanziInfo) { _hanziCache.ExecuteTransaction(hanziDb => { hanziDb.Insert(hanziInfo); }); }
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var worker = (BackgroundWorker)sender; var workerModel = (Tuple <string, List <string> >)e.Argument; List <HanziInfo> hanziInfos = new List <HanziInfo>(); HanziSqlliteHelper hanziSqlliteHelper = new HanziSqlliteHelper(workerModel.Item1); int rowIndex = 1; foreach (var hanzi in workerModel.Item2) { var result = HanziApiHelper.FindHanzi(hanzi); if (result == null) { continue; } var radical = result.Radical == "难检字" ? string.Empty : result.Radical; var biHuaCode = string.Empty; var bihuaCodeStr = result?.SimpleDetailContent.FirstOrDefault(i => i.Contains("笔顺编号:")); if (!string.IsNullOrWhiteSpace(bihuaCodeStr)) { biHuaCode = bihuaCodeStr.Replace("笔顺编号:", ""); } //var content = $"{hanzi}|{result.Pinyin}|{radical}|{result.Bihua}|{result.WuBi}|{biHuaCode}"; Match match = Regex.Match(biHuaCode, "\\d+"); if (match.Success) { biHuaCode = match.Value; } else if (!match.Success && int.TryParse(match.Value, out int biHuaCodeConvertResult)) { biHuaCode = biHuaCodeConvertResult == 0 ? string.Empty : biHuaCodeConvertResult.ToString(); } var hanziInfo = new HanziInfo() { ID = rowIndex, Hanzi = hanzi, Pinyin = result.Pinyin, Radical = radical == "难检字" ? string.Empty : radical, StrokeCount = Convert.ToInt32(result.Bihua), StrokeCode = biHuaCode, WuBi = result.WuBi, SimpleIntroduction = string.Join("\r\n", result.SimpleDetailContent), DetailIntroduction = string.Join("\r\n", result.DetailContent), }; hanziSqlliteHelper.SaveHanzi(hanziInfo); //报告进度 var progress = rowIndex * 100 / workerModel.Item2.Count; worker.ReportProgress(Convert.ToInt32(rowIndex)); rowIndex++; } e.Result = workerModel.Item1; }
public void UpdateHanziInfo(HanziInfo hanziInfo) { _hanziCache.ExecuteTransaction(hanziDb => { hanziDb.Update(hanziInfo); }); }