Beispiel #1
0
 /// <summary>
 /// 添加关键词组与网关绑定信息
 /// </summary>
 /// <param name="keyGroup"></param>
 /// <param name="gateways"></param>
 /// <returns></returns>
 public RPCResult AddkeyGroupGatewayBind(string keyGroup, string gateway)
 {
     try
     {
         if (string.IsNullOrEmpty(keyGroup))
         {
             return(new RPCResult(false, "关键词组不能为空"));
         }
         if (string.IsNullOrEmpty(gateway))
         {
             return(new RPCResult(false, "网关名不能为空"));
         }
         if (KeywordsGatewayBindDB.Del(gateway))
         {
             if (KeywordsGatewayBindDB.Add(keyGroup, gateway))
             {
                 return(new RPCResult(true, ""));
             }
         }
         LogHelper.LogWarn("SMSService", "SMSService.AddkeyGroupGatewayBind", "关键词组绑定网关数据库操作失败");
         return(new RPCResult(false, "关键词组绑定网关失败"));
     }
     catch (Exception ex)
     {
         LogHelper.LogError("SMSService", "SMSService.AddkeyGroupGatewayBind", ex.ToString());
         return(new RPCResult(false, "关键词组绑定网关失败"));
     }
 }
Beispiel #2
0
 /// <summary>
 /// 删除敏感词组
 /// </summary>
 /// <param name="keyGroup"></param>
 /// <returns></returns>
 public RPCResult DelKeywordGroup(string keyGroup)
 {
     try
     {
         if (string.IsNullOrEmpty(keyGroup))
         {
             return(new RPCResult(false, "敏感词组名不能为空!"));
         }
         if (KeywordsGatewayBindDB.GetGateways(keyGroup).Count > 0)
         {
             return(new RPCResult(false, "敏感词组正在使用,不允许删除"));
         }
         if (WordfilteDB.GetCountKeywords(keyGroup) > 0)
         {
             return(new RPCResult(false, "敏感词组内还包含敏感词,不允许删除"));
         }
         if (WordfilteDB.DelKeyTypesByGroup(keyGroup))
         {
             if (WordfilteDB.DelKeyGroup(keyGroup))
             {
                 return(new RPCResult(true, ""));
             }
         }
         return(new RPCResult(false, "删除词组失败"));
     }
     catch (Exception ex)
     {
         LogHelper.LogError("SMSService", "SMSService.DelKeywordGroup", ex.ToString());
         return(new RPCResult(false, "删除词组失败出现错误"));
     }
 }
Beispiel #3
0
 public void Send(string keyGroup, string message)
 {
     lock (lockHelper)
     {
         RabbitMQHelper fqKeywords;
         List <string>  update = KeywordsGatewayBindDB.GetGateways(keyGroup);
         for (int i = 0; i < update.Count; i++)
         {
             update[i] = "Keyword_" + update[i];
         }
         fqKeywords = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
         fqKeywords.BindQueue("Keyword_" + KeyGroup, AppConfig.MaxPriority, update.ToArray());
         fqKeywords.PublishMessage(message);
     }
 }
Beispiel #4
0
 /// <summary>
 /// 获取网关指定的关键词组
 /// </summary>
 /// <param name="keywordGroup"></param>
 /// <returns></returns>
 public RPCResult <string> GetKeyGroupGatewayBinds(string gateway)
 {
     try
     {
         if (string.IsNullOrEmpty(gateway))
         {
             return(new RPCResult <string>(false, "", "网关名不能为空"));
         }
         string str = KeywordsGatewayBindDB.GetkeyGroup(gateway);
         return(new RPCResult <string>(true, str, ""));
     }
     catch (Exception ex)
     {
         LogHelper.LogError("SMSService", "SMSService.GetKeyGroupGatewayBinds", ex.ToString());
         return(new RPCResult <string>(false, "", "获取网关指定的关键词组失败"));
     }
 }
Beispiel #5
0
 public RPCResult DelGatewayConfig(string gateway)
 {
     try
     {
         if (GatewayConfigDB.Del(gateway))
         {
             KeywordsGatewayBindDB.Del(gateway);
             ChannelDB.DelGatewayByGateway(gateway);
             return(new RPCResult(true, ""));
         }
         LogHelper.LogWarn("SMSService", "SMSService.DelGatewayConfig", "网关删除数据库失败");
         return(new RPCResult(false, "删除网关失败"));
     }
     catch (Exception ex)
     {
         LogHelper.LogError("SMSService", "SMSService.DelGatewayConfig", ex.ToString());
         return(new RPCResult(false, "删除网关出现错误"));
     }
 }
        public void Test()
        {
            var keyGroups = WordfilteDB.GetKeyGroups();

            Assert.IsNotNull(keyGroups);
            Assert.IsTrue(keyGroups.Count > 0);

            var keyTypes = WordfilteDB.GetKeyTypes();

            Assert.IsNotNull(keyTypes);
            Assert.IsTrue(keyTypes.Count > 0);

            var keyGroup = keyGroups.First().Key;

            var b = WordfilteDB.ExistGroup(keyGroup);

            Assert.IsTrue(b);
            var keyType = keyTypes.First().Key;

            b = WordfilteDB.ExistType(keyType);
            Assert.IsTrue(b);

            var addKeyGroup = "AddKeyGroup" + UnitTestDBAccess.Util.GenRandStr(10);

            b = WordfilteDB.AddKeyGroup(addKeyGroup, "添加keyGroup 测试");
            Assert.IsTrue(b);
            b = WordfilteDB.DelKeyGroup(addKeyGroup);
            Assert.IsTrue(b);

            var addKeyType = "AddKeyType" + UnitTestDBAccess.Util.GenRandStr(10);

            b = WordfilteDB.AddKeyType(addKeyType, "添加keyType 测试");
            Assert.IsTrue(b);

            b = WordfilteDB.AddGroupTypeBind(addKeyGroup, new List <string>()
            {
                addKeyType, UnitTestDBAccess.Util.GenRandStr(15)
            });
            Assert.IsTrue(b);

            var kgt = WordfilteDB.GetKeyTypesByGroup(addKeyGroup);

            Assert.IsNotNull(kgt);
            Assert.IsTrue(kgt.Count > 0);
            var ktg = WordfilteDB.GetKeywordsGroupByType(addKeyType);

            Assert.IsNotNull(ktg);
            Assert.IsTrue(ktg.Count > 0);

            b = WordfilteDB.DelKeyTypesByGroup(addKeyGroup);
            Assert.IsTrue(b);

            Keywords keywords1 = new Keywords()
            {
                KeyGroup        = addKeyGroup,
                KeywordsType    = addKeyType,
                Enable          = true,
                ReplaceKeywords = "",
                Words           = "words" + UnitTestDBAccess.Util.GenRandStr(15)
            };
            Keywords keywords2 = new Keywords()
            {
                KeyGroup        = addKeyGroup,
                KeywordsType    = addKeyType,
                Enable          = true,
                ReplaceKeywords = "",
                Words           = "words" + UnitTestDBAccess.Util.GenRandStr(15)
            };
            Keywords keywords3 = new Keywords()
            {
                KeyGroup        = addKeyGroup,
                KeywordsType    = addKeyType,
                Enable          = true,
                ReplaceKeywords = "",
                Words           = "words" + UnitTestDBAccess.Util.GenRandStr(15)
            };
            List <Keywords> list = new List <Keywords>();

            list.Add(keywords1);
            list.Add(keywords2);
            list.Add(keywords3);
            b = WordfilteDB.Add(addKeyGroup, list);
            Assert.IsTrue(b);
            var list2 = WordfilteDB.Gets(addKeyGroup);

            Assert.IsNotNull(list2);
            Assert.IsTrue(list2.Count > 2);
            var list3 = WordfilteDB.GetKeywordsByType(addKeyType);

            Assert.IsNotNull(list3);
            Assert.IsTrue(list3.Count > 2);

            b = WordfilteDB.KeywordsEnabled(addKeyGroup, keywords1.Words, false);
            Assert.IsTrue(b);
            keywords1.ReplaceKeywords = "replace";
            b = WordfilteDB.Update(keywords1);
            Assert.IsTrue(b);
            var i = WordfilteDB.GetCountKeywords(addKeyGroup);

            Assert.IsTrue(i > 0);
            var arr = WordfilteDB.Get(addKeyGroup);

            Assert.IsNotNull(arr);
            Assert.IsTrue(arr.Length > 0);

            var klist = WordfilteDB.GetKeywordsByKeyword("words");

            Assert.IsNotNull(klist);
            Assert.IsTrue(klist.Count > 0);

            i = WordfilteDB.GetAllKeywordCount();
            Assert.IsTrue(i > 0);

            var list4 = WordfilteDB.GetAllKeywords(1, 2);

            Assert.IsTrue(list4.Count == 2);

            var gateway = GatewayConfigDB.GetConfigs().FirstOrDefault();

            Assert.IsNotNull(gateway);

            b = KeywordsGatewayBindDB.Add(addKeyGroup, gateway.Gateway);
            Assert.IsTrue(b);

            var gts = KeywordsGatewayBindDB.GetGateways(addKeyGroup);

            Assert.IsTrue(gts.Count > 0);

            var kg = KeywordsGatewayBindDB.GetkeyGroup(gateway.Gateway);

            Assert.IsNotNull(kg);


            gts = KeywordsGatewayBindDB.GetGateways();
            Assert.IsTrue(gts.Count > 0);

            b = KeywordsGatewayBindDB.Del(gateway.Gateway);
            Assert.IsTrue(b);


            List <string> keywords = (from k in list select k.Words).ToList();

            b = WordfilteDB.Del(addKeyGroup, keywords);
            Assert.IsTrue(b);
        }