public static async Task <int> AddAutoReplyRule() { long merchantId = 9842; string describ = ""; AutoReplyRule ruleobj = new AutoReplyRule() { MerchantId = merchantId, RuleType = 3, Description = describ, AutoReplyMessages = new List <AutoReplyMessage>(), AutoReplyKeywords = new List <AutoReplyKeyword>(), AutoReplyRegexes = new List <AutoReplyRegex>() }; ruleobj.AutoReplyMessages.Add(new AutoReplyMessage() { MerchantId = merchantId, MsgJson = "", MsgType = "text" }); AddCannedReply acr = new AddCannedReply(); int t = await acr.AddAutoReplyRuleAndSave(ruleobj); Console.WriteLine(t); return(t); }
private static bool isGoodRule(AutoReplyRule rule, string problem) { bool ret = false; if (rule == null || rule.AutoReplyRegexes == null || rule.AutoReplyRegexes.Count() == 0) { return(ret); } ret = rule.AutoReplyRegexes.Any(x => (new Regex(x.Regex)).IsMatch(problem)); return(ret); }
public async Task <int> AddAutoReplyRuleAndSave(AutoReplyRule arr) { Db.AutoReplyRules.Add(arr); int t = 0; try { t = await Db.SaveChangesAsync(); } catch (DbUpdateException due) { Console.WriteLine(due.InnerException.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(t); return(t); }
public async Task <int> AddAutoReplyRuleAndSave(string fileName) { string outFileName = @"D:\zhijie\regResult\regResult_out.txt"; //var client = WebAppHelper.CreateRestClient(); StreamReader sr = new StreamReader(fileName); StreamWriter sw = new StreamWriter(outFileName); string line = null; string merS = null; long merchantId = 0; string describ = null; string answer = null; const int RULE_TYPE = 3; //client.Login("pfizer_test_admin", "password", "Admin_UI_Client"); AutoReplyRule ruleobj = new AutoReplyRule() { MerchantId = merchantId, RuleType = RULE_TYPE, Description = describ, AutoReplyMessages = new List <AutoReplyMessage>() { new AutoReplyMessage() { MerchantId = merchantId, MsgJson = "", MsgType = "text" } }, AutoReplyKeywords = new List <AutoReplyKeyword>(), AutoReplyRegexes = new List <AutoReplyRegex>() }; bool isFirst = true; // bool isGreater64 = false; int i = 0; while ((line = sr.ReadLine()) != null) { if (line == "BEGIN_NEW_RULE") { if (!isFirst) { Db.AutoReplyRules.Add(ruleobj); sw.WriteLine(ruleobj.ToString()); } isFirst = false; merS = sr.ReadLine(); if (merS == null) { break; } merchantId = long.Parse(merS); describ = sr.ReadLine(); answer = sr.ReadLine(); ruleobj = new AutoReplyRule() { MerchantId = merchantId, RuleType = RULE_TYPE, Description = describ, AutoReplyMessages = new List <AutoReplyMessage>() { new AutoReplyMessage() { MerchantId = merchantId, MsgJson = answer, MsgType = "text" } }, AutoReplyKeywords = new List <AutoReplyKeyword>(), AutoReplyRegexes = new List <AutoReplyRegex>() }; continue; } string[] tokens = line.Split("\t".ToArray(), StringSplitOptions.None); ruleobj.AutoReplyRegexes.Add(new AutoReplyRegex() { MerchantId = merchantId, Regex = tokens[2] }); Console.WriteLine(i++); } if (!isFirst) { Db.AutoReplyRules.Add(ruleobj); sw.WriteLine(ruleobj.ToString()); } try { int rCount = await Db.SaveChangesAsync(); return(rCount); } catch (DbUpdateException due) { Console.WriteLine(due.Message); } finally { sr.Close(); sw.Close(); } return(0); }