public RPCResult <List <GatewayConfiguration> > GetGatewayConfigs() { try { List <GatewayConfiguration> list = GatewayConfigDB.GetConfigs(); return(new RPCResult <List <GatewayConfiguration> >(true, list, "")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.GetGatewayConfigs", ex.ToString()); return(new RPCResult <List <GatewayConfiguration> >(false, null, "获取网关出现错误")); } }
public RPCResult <GatewayConfiguration> GetGatewayConfig(string gateway) { try { GatewayConfiguration config = GatewayConfigDB.GetConfig(gateway); return(new RPCResult <GatewayConfiguration>(true, config, "")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.GetGatewayConfig", ex.ToString()); return(new RPCResult <GatewayConfiguration>(false, null, "获取网关出现错误")); } }
public RPCResult UpdateGatewayConfig(GatewayConfiguration config) { try { if (GatewayConfigDB.Update(config)) { return(new RPCResult(true, "")); } LogHelper.LogWarn("SMSService", "SMSService.UpdateGatewayConfig", "网关更新数据库失败"); return(new RPCResult(false, "更新网关失败")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.UpdateGatewayConfig", ex.ToString()); return(new RPCResult(false, "更新网关出现错误")); } }
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 RPCResult AddGatewayConfig(GatewayConfiguration config) { try { if (GatewayConfigDB.Exist(config.Gateway)) { return(new RPCResult(false, "已存在此网关")); } if (GatewayConfigDB.Add(config)) { return(new RPCResult(true, "")); } LogHelper.LogWarn("SMSService", "SMSService.AddGatewayConfig", "网关添加数据库失败"); return(new RPCResult(false, "添加网关失败")); } catch (Exception ex) { LogHelper.LogError("SMSService", "SMSService.AddGatewayConfig", ex.ToString()); return(new RPCResult(false, "添加网关出现错误")); } }
static void LoadChannel() { var channels = ChannelDB.GetChannels(); var gateways = GatewayConfigDB.GetConfigs(); foreach (var ch in channels) { List <GatewayHelper> gatewayHelpers = new List <GatewayHelper>(); List <string> gatewayIds = ChannelDB.GetGatewaysByChannel(ch.ChannelID); foreach (var gid in gatewayIds) { var gatewayconfig = gateways.FirstOrDefault(g => g.Gateway == gid); if (gatewayconfig == null) { throw new Exception(ch.ChannelName + " 找不到网关" + gid + "的配置"); } GatewayHelper gh = new GatewayHelper(gatewayconfig); gatewayHelpers.Add(gh); } Channels.Add(ch.ChannelID, gatewayHelpers); } }
public void Test() { string spnumber = "12345"; var gateway = GatewayConfigDB.GetConfigs().FirstOrDefault(); Assert.IsNotNull(gateway); MOSMS mo = new MOSMS(gateway.Gateway, System.Guid.NewGuid().ToString(), new DateTime(2016, 4, 1), "测试短信上行", "123214", spnumber, "test"); var b = DeliverMODB.Add(mo); Assert.IsTrue(b); var l = DeliverMODB.Gets(spnumber, new DateTime(2016, 3, 1), new DateTime(2016, 4, 30)); Assert.IsTrue(l.Count > 0); b = DeliverMODB.Del(spnumber); Assert.IsTrue(b); l = DeliverMODB.Gets(spnumber, new DateTime(2016, 3, 1), new DateTime(2016, 4, 30)); Assert.IsTrue(l.Count == 0); }
public void Test() { string gatewayName = System.Guid.NewGuid().ToString(); var b = GatewayConfigDB.Exist(gatewayName); Assert.IsFalse(b); GatewayConfiguration gateway = new GatewayConfiguration() { Gateway = "testGateway11", HandlingAbility = 100, Operators = new List <string>() { "telecom", "mobile" } }; b = GatewayConfigDB.Add(gateway); Assert.IsTrue(b); gateway.HandlingAbility = 1000; b = GatewayConfigDB.Update(gateway); Assert.IsTrue(b); b = GatewayConfigDB.Exist(gateway.Gateway); Assert.IsTrue(b); var g = GatewayConfigDB.GetConfig(gateway.Gateway); Assert.IsNotNull(g); Assert.AreEqual(g.HandlingAbility, 1000); Channel channel = new Channel() { ChannelID = "channel", ChannelName = "单元测试", Remark = "单元测试" }; b = ChannelDB.AddChannle(channel); Assert.IsTrue(b); b = ChannelDB.AddChannelGatewayBind(channel.ChannelID, new List <string>() { gateway.Gateway }); Assert.IsTrue(b); b = ChannelDB.DelGatewayByChannel(channel.ChannelID); Assert.IsTrue(b); b = ChannelDB.AddChannelGatewayBind(channel.ChannelID, new List <string>() { gateway.Gateway }); Assert.IsTrue(b); b = ChannelDB.DelGatewayByGateway(gateway.Gateway); Assert.IsTrue(b); channel.Remark = "测试更新"; b = ChannelDB.UpdateChannel(channel); Assert.IsTrue(b); var c = ChannelDB.GetChannel(channel.ChannelID); Assert.IsNotNull(c); Assert.AreEqual(c.ChannelID, channel.ChannelID); b = ChannelDB.AddChannelGatewayBind(channel.ChannelID, new List <string>() { gateway.Gateway }); Assert.IsTrue(b); var gs = ChannelDB.GetGatewaysByChannel(channel.ChannelID); Assert.IsTrue(gs.Count > 0); var cs = ChannelDB.GetChannels(); Assert.IsTrue(cs.Count > 0); b = ChannelDB.DelGatewayByChannel(channel.ChannelID); Assert.IsTrue(b); b = ChannelDB.DelChannel(channel.ChannelID); Assert.IsTrue(b); b = GatewayConfigDB.Del(gateway.Gateway); Assert.IsTrue(b); }
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); }