Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        private void GetAllHanziDetailsFromJuHeApi()
        {
            var filePath   = @"F:\OneDrive\WorkArea\工作项\汉字\汉字列表.txt";
            var hanziLines = File.ReadAllLines(filePath);
            var hanziList  = hanziLines.Where(i => !string.IsNullOrWhiteSpace(i)).ToList();

            var searchedContent = new List <string>();

            foreach (var hanzi in hanziList)
            {
                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}";

                searchedContent.Add(content);
            }

            var newfilePath = @"F:\OneDrive\WorkArea\工作项\汉字\汉字列表New.txt";

            File.WriteAllLines(newfilePath, searchedContent);
        }