コード例 #1
0
ファイル: Rules.cs プロジェクト: yangxt/weback
        public static Result EditRuleCode(string Guid, string Code, string RuleGuid, string sepType, string Status)
        {
            Model.RuleCode rulecode = Model.RuleCode.findByField("StrGuid", Guid);
            if (rulecode == null && rulecode.Id <= 0)
            {
                Result result = new Result();
                result.Add("你操作的内容不存在或已删除!");
                return(result);
            }
            List <Model.RuleCode> rulecodes = new List <Model.RuleCode>();

            if (string.IsNullOrEmpty(sepType))
            {
                if (Code.IndexOf("$") > 0)
                {
                    sepType = "$";
                }
                if (string.IsNullOrEmpty(sepType))
                {
                    sepType = "#";
                }
            }
            string[]      codes = Code.Split(new string[] { sepType, ",", ";", " ", ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
            List <string> list  = new List <string>();

            foreach (string code in codes)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    list.Add(code);
                }
            }
            list.Sort();
            Code = strUtil.Join(sepType, list.ToArray());
            Code = sepType + Code + sepType;

            rulecode.Code     = Code;
            rulecode.RuleGuid = RuleGuid;
            rulecode.SepType  = sepType;
            rulecode.HitCount = list.Count;
            if (!string.IsNullOrEmpty(Status))
            {
                rulecode.Status = Status;
            }
            rulecode.HashCode = Encryptor.Md5Encryptor32(Code);
            _keywords         = "";
            return(rulecode.update());
        }
コード例 #2
0
ファイル: Rules.cs プロジェクト: yangxt/weback
        public static Result AddRuleCode(string Code, string RuleGuid, string sepType, string Status)
        {
            List <Model.RuleCode> rulecodes = new List <Model.RuleCode>();

            if (string.IsNullOrEmpty(sepType))
            {
                if (Code.IndexOf("$") > 0)
                {
                    sepType = "$";
                }
                if (string.IsNullOrEmpty(sepType))
                {
                    sepType = "#";
                }
            }
            string[]      codes = Code.Split(new string[] { sepType, ",", ";", " ", ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
            List <string> list  = new List <string>();

            foreach (string code in codes)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    list.Add(code);
                }
            }
            list.Sort();
            Code = strUtil.Join(sepType, list.ToArray());
            Code = sepType + Code + sepType;

            Model.RuleCode rulecode = new Model.RuleCode();
            rulecode.Guid     = Guid.NewGuid().ToString();
            rulecode.Code     = Code;
            rulecode.RuleGuid = RuleGuid;
            rulecode.SepType  = sepType;
            rulecode.Status   = Status;
            rulecode.HitCount = list.Count;
            rulecode.HashCode = Encryptor.Md5Encryptor32(Code);
            _keywords         = "";
            return(rulecode.insert());
        }
コード例 #3
0
ファイル: Rules.cs プロジェクト: yangxt/weback
        public static Model.Rules GetRule(string Text, string OpenId)
        {
            string Code = Text.Split(Separation, StringSplitOptions.RemoveEmptyEntries)[0];

            Model.RuleCode rulecode = null;
            try
            {
                try
                {
                    rulecode = Model.RuleCode.find("Status <>'close' and Code like'%#" + Code + "#%'").first();
                }
                catch { }
                if (rulecode == null)
                {
                    Code = "";
                    Result result   = strUtil.CheckSensitiveWords(Text, KeyWords);
                    int    HitCount = result.Errors.Count;
                    if (HitCount > 0)
                    {
                        string temp = "(" + strUtil.Join("|", result.Errors.ToArray()) + ")";
                        for (; HitCount > 0; HitCount--)
                        {
                            rulecode = null;
                            try
                            {
                                Code     = result.Errors[HitCount - 1];
                                rulecode = Model.RuleCode.find("Status <>'close' and Code like'%$" + Code + "$%'").first();
                                if (rulecode != null)
                                {
                                    Result        t   = strUtil.CheckSensitiveWords(rulecode.Code, temp);
                                    List <string> ary = new List <string>();
                                    for (int i = 0; i < t.Errors.Count; i++)
                                    {
                                        if (!ary.Contains(t.Errors[i]))
                                        {
                                            ary.Add(t.Errors[i]);
                                        }
                                    }
                                    if (ary.Count < rulecode.HitCount)
                                    {
                                        rulecode = null;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
            catch { return(null); }
            try
            {
                if (rulecode != null && rulecode.Status == "test" && Fans.GetBy("WeChatOpenId", OpenId).AllowTest != 1)
                {
                    return(null);
                }
                else
                {
                    Model.Rules temp = Get(rulecode.RuleGuid);
                    temp.GoOnCmd = Code;
                    return(temp);
                }
            }
            catch
            {
                return(null);
            }
        }