示例#1
0
        /// <summary>
        /// 生成图标文件
        /// </summary>
        /// <returns></returns>
        public ActionResult GenerateIconCSS()
        {
            CommonResult  result       = new CommonResult();
            string        regex        = "^\\.(?<name>.*?):before\\s*\\{";
            List <string> filePathList = new List <string>()
            {
                "~/Content/themes/metronic/assets/global/plugins/bootstrap/css/bootstrap.css",
                "~/Content/themes/metronic/assets/global/plugins/font-awesome/css/font-awesome.css",
                "~/Content/themes/metronic/assets/global/plugins/simple-line-icons/simple-line-icons.css",
            };
            //图标类型
            List <string> sourceTypeList = new List <string>()
            {
                "Glyphicons",
                "FontAwesome",
                "SimpleLine",
            };
            List <string> prefixList = new List <string>()
            {
                "glyphicon ",
                "fa ",
                "",
            };

            //对每个文件进行匹配并存储
            int i = 0;

            try
            {
                foreach (string filePath in filePathList)
                {
                    string realPath = Server.MapPath(filePath);
                    if (FileUtil.FileIsExist(realPath))
                    {
                        string sourceType = sourceTypeList[i];
                        BLLFactory <BootstrapIcon> .Instance.DeleteBySourceType(sourceType);

                        string        prefix    = prefixList[i];
                        string        content   = FileUtil.FileToString(realPath);
                        List <string> matchList = CRegex.GetList(content, regex, 1);
                        foreach (string item in matchList)
                        {
                            //包含特殊的字符,去掉即可
                            if (item.IndexOfAny(new char[] { '.', '>', '+' }) > 0)
                            {
                                continue;
                            }

                            BootstrapIconInfo info = new BootstrapIconInfo()
                            {
                                DisplayName = item,
                                ClassName   = prefix + item,
                                CreateTime  = DateTime.Now,
                                SourceType  = sourceType,
                            };

                            BLLFactory <BootstrapIcon> .Instance.Insert(info);
                        }
                        result.Success = true;
                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(BootstrapIconController));
            }

            return(ToJsonContent(result));
        }