📄 wordreplace.cs
字号:
namespace PowerEasy.Accessories
{
using PowerEasy.Common;
using PowerEasy.Components;
using PowerEasy.IDal.Accessories;
using PowerEasy.Model.Accessories;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
public sealed class WordReplace
{
private static readonly IWordReplace dal = DataAccess.CreateWordReplace();
private static string m_LinkType = "";
private static string m_SourceWord = "";
private WordReplace()
{
}
public static bool Add(WordReplaceInfo wordReplaceInfo)
{
return dal.Add(wordReplaceInfo);
}
public static bool Delete(string id)
{
return (DataValidator.IsValidId(id) && dal.Delete(id));
}
public static bool Disabled(string id)
{
return (DataValidator.IsValidId(id) && dal.Disabled(id));
}
public static bool Enabled(string id)
{
return (DataValidator.IsValidId(id) && dal.Enabled(id));
}
public static bool Exists(string source, int type)
{
return dal.Exists(source, type);
}
public static int GetCountNumber(string keyword, int listType)
{
return dal.GetCountNumber();
}
public static WordReplaceInfo GetInfoById(int id)
{
return dal.GetInfoById(id);
}
public static IList<WordReplaceInfo> GetInsideList(int startRowIndexId, int maxNumberRows, string keyword, int listType)
{
if (!string.IsNullOrEmpty(keyword))
{
keyword = keyword.Replace("'", "''").Trim();
}
return dal.GetInsideLink(startRowIndexId, maxNumberRows, keyword, listType);
}
public static int GetMaxId()
{
return dal.GetMaxId();
}
public static IList<WordReplaceInfo> GetWordFilterList()
{
return dal.GetWordFilterList();
}
public static IList<WordReplaceInfo> GetWordFilterList(int startRowIndexId, int maxNumberRows, string keyword, int listType)
{
return dal.GetWordFilterList(startRowIndexId, maxNumberRows, DataSecurity.FilterBadChar(keyword), listType);
}
private static string regReplace(Match m)
{
string pattern = "(?<!<[^<>]*)" + m_SourceWord + "(?![^<>]*>)";
return Regex.Replace(m.Value, pattern, m_LinkType, RegexOptions.IgnoreCase);
}
public static string ReplaceInsideLink(string inputText)
{
IList<WordReplaceInfo> list = SiteCache.Get("CK_Accessories_ReplaceInsideLinkList") as List<WordReplaceInfo>;
string input = inputText;
if (list == null)
{
list = dal.GetInsideLink(0, 0, "", 2);
SiteCache.Insert("CK_Accessories_ReplaceInsideLinkList", list);
}
foreach (WordReplaceInfo info in list)
{
m_SourceWord = info.SourceWord;
if (info.OpenType)
{
m_LinkType = "<a class=\"insidelink\" href=\"" + info.TargetWord + "\">" + info.SourceWord + "</a>";
}
else
{
m_LinkType = "<a class=\"insidelink\" href=\"" + info.TargetWord + "\" target=\"_blank\">" + info.SourceWord + "</a>";
}
input = Regex.Replace(input, @"((^|</a>)[\s\S]*?<a|</a>[\s\S]*$)", new MatchEvaluator(WordReplace.regReplace), RegexOptions.IgnoreCase);
if (Regex.Matches(input, "</a>", RegexOptions.IgnoreCase).Count == 0)
{
input = input.Replace(m_SourceWord, m_LinkType);
}
}
return input;
}
public static string ReplaceText(string inputText)
{
IList<WordReplaceInfo> wordFilterList = SiteCache.Get("CK_Accessories_WordReplaceInfoList") as List<WordReplaceInfo>;
StringBuilder builder = new StringBuilder(inputText);
if (wordFilterList == null)
{
wordFilterList = GetWordFilterList();
SiteCache.Insert("CK_Accessories_WordReplaceInfoList", wordFilterList);
}
foreach (WordReplaceInfo info in wordFilterList)
{
builder.Replace(info.SourceWord, info.TargetWord);
}
return builder.ToString();
}
public static bool Update(WordReplaceInfo wordReplaceInfo)
{
return dal.Update(wordReplaceInfo);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -