Ejemplo n.º 1
0
        public void GetPinyin()
        {
            var t = WordsHelper.GetAllPinyin('芃');

            Assert.AreEqual("Peng", t[0]);


            var b = WordsHelper.GetPinyin("摩擦棒");

            Assert.AreEqual("MoCaBang", b);

            b = WordsHelper.GetPinyin("秘鲁");
            Assert.AreEqual("BiLu", b);

            b = WordsHelper.GetPinyin("天行");
            Assert.AreEqual("TianXing", b);

            var py = WordsHelper.GetPinyin("快乐,乐清");

            Assert.AreEqual("KuaiLe,YueQing", py);

            py = WordsHelper.GetPinyin("快乐清理");
            Assert.AreEqual("KuaiLeQingLi", py);


            py = WordsHelper.GetPinyin("我爱中国");
            Assert.AreEqual("WoAiZhongGuo", py);

            py = WordsHelper.GetPinyin("我爱中国", ",");
            Assert.AreEqual("Wo,Ai,Zhong,Guo", py);

            py = WordsHelper.GetPinyin("我爱中国", true);
            Assert.AreEqual("WǒÀiZhōngGuó", py);

            py = WordsHelper.GetFirstPinyin("我爱中国");
            Assert.AreEqual("WAZG", py);

            var pys = WordsHelper.GetAllPinyin('传');

            Assert.AreEqual("Chuan", pys[0]);
            Assert.AreEqual("Zhuan", pys[1]);

            py = WordsHelper.GetPinyinForName("单一一");
            Assert.AreEqual("ShanYiYi", py);

            py = WordsHelper.GetPinyinForName("单一一", ",");
            Assert.AreEqual("Shan,Yi,Yi", py);

            py = WordsHelper.GetPinyinForName("单一一", true);
            Assert.AreEqual("ShànYīYī", py);

            py = WordsHelper.GetPinyinForName("张丽莎", false);
            Assert.AreEqual("ZhangLiSha", py);

            py = WordsHelper.GetPinyinForName("孟露", false);
            Assert.AreEqual("MengLu", py);


            WordsHelper.ClearCache();
        }
Ejemplo n.º 2
0
        public string Translate(string content)
        {
            if (_settings.ShouldUsePinyin)
            {
                var result = _cache[content] as string;
                if (result == null)
                {
                    if (WordsHelper.HasChinese(content))
                    {
                        result = WordsHelper.GetFirstPinyin(content);
                    }
                    else
                    {
                        result = content;
                    }
                    var policy = new CacheItemPolicy();
                    policy.SlidingExpiration = new TimeSpan(12, 0, 0);
                    _cache.Set(content, result, policy);
                }

                return(result);
            }

            return(content);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 结果管道
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public string ResultPipe(string result)
 {
     if (result.IsNullOrWhiteSpace())
     {
         return(result);
     }
     if (Reverse == "all")
     {
         result = ReverseStr(result);
     }
     else if (Reverse == "row")
     {
         result = ReverseStr(result, true);
     }
     if (WordsHelper.HasChinese(result))
     {
         if (ToTraditionalChinese)
         {
             result = WordsHelper.ToTraditionalChinese(result);
         }
         else if (ToSimplifiedChinese)
         {
             result = WordsHelper.ToSimplifiedChinese(result);
         }
         else if (ToPinyin != null)
         {
             result =
                 WordsHelper.GetPinyin(result, ToPinyin.Equals("tone", StringComparison.OrdinalIgnoreCase));
         }
         else if (ToFirstPinyin)
         {
             result = WordsHelper.GetFirstPinyin(result)?.ToLower();
         }
     }
     if (Lower)
     {
         result = result?.ToLower();
     }
     else if (Upper)
     {
         result = result?.ToUpper();
     }
     if (SpeakWithWhiteSpace)
     {
         result = ToSpeakWithWhiteSpace(result);
     }
     return(result);
 }
Ejemplo n.º 4
0
        public async Task Add(UserAddInput input)
        {
            var user = input.Adapt <SysUser>();

            user.FirstNameInitial = WordsHelper.GetFirstPinyin(user.Name.Substring(0, 1));
            user.PasswordLevel    = (PasswordLevel)H_Util.CheckPasswordLevel(user.Password);
            user.Password         = H_EncryptProvider.HMACSHA256(user.Password, _appSettings.Key.Sha256Key);
            user.Enabled          = true;

            var role = await _roleDomainService.Get(input.RoleId.Value);

            user.RoleId      = role.Id;
            user.RoleName    = role.Name;
            user.AuthNumbers = role.AuthNumbers;
            user.RoleLevel   = role.Level;

            await _userDomainService.Add(user);
        }
Ejemplo n.º 5
0
 public string GetFirstPinyin([FromBody] CommonRequestVm vm)
 {
     return(WordsHelper.GetFirstPinyin(vm.Source));
 }
Ejemplo n.º 6
0
 public string GetFirstPinyin(string source)
 {
     return(WordsHelper.GetFirstPinyin(source));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 导入excel
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public async Task Import(IFormFileCollection files)
        {
            H_AssertEx.That(files == null || files.Count == 0, "请选择Excel文件");

            //格式限制
            var allowType = new string[] { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" };

            H_AssertEx.That(files.Any(b => !allowType.Contains(b.ContentType)), "只能上传Excel文件");
            ////大小限制
            //if (files.Sum(b => b.Length) >= 1024 * 1024 * 4)
            //{

            //}

            var users = new List <SysUser>();

            foreach (IFormFile file in files)
            {
                string rootPath = _appSettings.FilePath.ImportExcelPath;

                H_File.CreateDirectory(rootPath);

                string filePath = Path.Combine(rootPath, file.FileName);

                using (var fs = System.IO.File.Create(filePath))
                {
                    // 复制文件
                    file.CopyTo(fs);
                    // 清空缓冲区数据
                    fs.Flush();
                }

                using (var ep = new ExcelPackage(new FileInfo(filePath)))
                {
                    var worksheet = ep.Workbook.Worksheets[0];
                    if (worksheet != null && worksheet.Cells[1, 1].Text.Trim() != "姓名")
                    {
                        throw new H_Exception("上传数据列名有误,请检查");
                    }
                    foreach (var ws in ep.Workbook.Worksheets)
                    {
                        int colStart = ws.Dimension.Start.Column;    //工作区开始列,start=1
                        int colEnd   = ws.Dimension.End.Column;      //工作区结束列
                        int rowStart = ws.Dimension.Start.Row;       //工作区开始行号,start=1
                        int rowEnd   = ws.Dimension.End.Row;         //工作区结束行号

                        for (int i = rowStart + 1; i <= rowEnd; i++) //第1行是列名,跳过
                        {
                            var user = new SysUser();
                            user.Name             = ws.Cells[i, colStart].Text;
                            user.FirstNameInitial = WordsHelper.GetFirstPinyin(user.Name.Substring(0, 1));
                            user.Password         = H_EncryptProvider.HMACSHA256("123456", _appSettings.Key.Sha256Key);
                            users.Add(user);
                        }
                    }
                }
            }

            if (users.Count == 0)
            {
                return;
            }

            await _userRep.InsertAsync(users);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // 转成简体
            var str = WordsHelper.ToSimplifiedChinese("壹佰贰拾叁億肆仟伍佰陆拾柒萬捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str);

            // 转成繁体
            var str2 = WordsHelper.ToTraditionalChinese("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str2);

            // 转成全角
            var str3 = WordsHelper.ToSBC("abcABC123");

            Console.WriteLine(str3);

            // 转成半角
            var str4 = WordsHelper.ToDBC("abcABC123");

            Console.WriteLine(str4);

            // 数字转成中文大写
            var str5 = WordsHelper.ToChineseRMB(12345678901.12);

            Console.WriteLine(str5);

            // 中文转成数字
            var str6 = WordsHelper.ToNumber("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str6);

            // 获取全拼
            var str7 = WordsHelper.GetPinyin("我爱中国");

            Console.WriteLine(str7);

            // 获取首字母
            var str8 = WordsHelper.GetFirstPinyin("我爱中国");

            Console.WriteLine(str8);

            // 获取全部拼音
            var str9 = WordsHelper.GetAllPinyin('传');

            Console.WriteLine(str9);

            // 获取姓名
            var str10 = WordsHelper.GetPinyinForName("单一一");

            Console.WriteLine(str10);
            var str11 = WordsHelper.GetPinyinForName("单一一", ",");

            Console.WriteLine(str11);
            var str12 = WordsHelper.GetPinyinForName("单一一", true);

            Console.WriteLine(str12);

            string      s     = "北京|天津|河北|辽宁|吉林|黑龙江|山东|江苏|上海|浙江|安徽|福建|江西|广东|广西|海南|河南|湖南|湖北|山西|内蒙古|宁夏|青海|陕西|甘肃|新疆|四川|贵州|云南|重庆|西藏|香港|澳门|台湾";
            PinyinMatch match = new PinyinMatch();

            match.SetKeywords(s.Split('|').ToList());
            var all = match.Find("BJ");

            Console.WriteLine(all[0]);
            Console.WriteLine(all.Count);

            all = match.Find("北J");
            Console.WriteLine(all[0]);
            Console.WriteLine(all.Count);
        }