コード例 #1
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static void AddCannedReplies()
        {
            AddCannedReply acr     = new AddCannedReply();
            var            options = new ParallelOptions {
                MaxDegreeOfParallelism = 5
            };

            /*var merchantsCn = acr.Db.Merchants.Where(m=> m.LanguageCode =="zh" && m.CountryCode == "cn").ToList();
             * Parallel.ForEach(merchantsCn, options, (m) =>
             * {
             *  AddCannedRepliesForOneMerchant(m.Id, true);
             * });*/
            var merchantsEn = acr.Db.Merchants.Where(m =>
                                                     //m.Id == 52 || m.Id==53
                                                     m.LanguageCode == "en" && m.CountryCode == "us"
                                                     ).ToList();

            Parallel.ForEach(merchantsEn, options, (m) =>
            {
                AddCannedRepliesForOneMerchant(m.Id, false);
            });

            /*var merchantsDefault = acr.Db.Merchants.Where(m=> !(m.LanguageCode == "zh" && m.CountryCode == "cn")&&!(m.LanguageCode == "en" && m.CountryCode == "us")).ToList();
             * Parallel.ForEach(merchantsDefault, options, (m) =>
             * {
             *  AddCannedRepliesForOneMerchant(m.Id, true);
             * });*/
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static void AddCannedRepliesForOneMerchant(long merchantId, bool cn)
        {
            var acr = new AddCannedReply();
            List <CannedReply> cannedReplies = new List <CannedReply>();
            var lst = cn ? crLstCn : crLstEn;

            lst.ForEach((cr) =>
            {
                var cannedReply = new CannedReply
                {
                    MerchantId         = merchantId,
                    UserId             = null,
                    CategoryName       = cn ? "问候语" : "Greeting",
                    ReplyContent       = cr.ReplyContent,
                    IsAutoReplyEnabled = true,
                    Questions          = cr.Questions,
                    CreationTime       = DateTimeOffset.UtcNow
                };
                cannedReplies.Add(cannedReply);
            });
            var task = acr.BulkPost(cannedReplies);

            task.Wait();
            List <CannedReply.CannedReplyBulkResult> cbr = task.Result;

            File.WriteAllText($"d:\\logs\\{merchantId}.txt", JsonConvert.SerializeObject(cannedReplies));
            File.WriteAllText($"d:\\logs\\{merchantId}.result.txt", JsonConvert.SerializeObject(cbr));
            Console.Write(JsonConvert.SerializeObject(cannedReplies));
            Console.Write(JsonConvert.SerializeObject(cbr));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static async Task <int> DeleteAutoReplyRule(int ruleType)
        {
            AddCannedReply acr = new AddCannedReply();
            int            ret = await acr.DeleteAutoReplyRule3(ruleType);

            Console.WriteLine(ret);
            return(ret);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static async Task <int> BatchAddRules()
        {
            AddCannedReply acr   = new AddCannedReply();
            int            count = await acr.AddAutoReplyRuleAndSave(@"D:/zhijie/regResult/regResult3.txt");

            Console.WriteLine(count);
            return(count);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static void LookupRule(string fileName, string oneResult, string manyResult)
        {
            AddCannedReply acr      = new AddCannedReply();
            var            allRules = new List <AutoReplyRule>();

            foreach (var rule in acr.Db.AutoReplyRules)
            {
                allRules.Add(rule);
            }
            int i = 0;

            using (StreamReader sr = new StreamReader(fileName))
            {
                StreamWriter oneExtractRule = new StreamWriter(oneResult);
                StreamWriter manyRule       = new StreamWriter(manyResult);
                StreamWriter zeroFile       = new StreamWriter("D:/zhijie/regResult/zeroFile.txt");
                string       line           = null;
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(i++);
                    var goodRules = GetGoodRules(line, allRules);
                    if (goodRules.Count() == 0)
                    {
                        zeroFile.WriteLine(line);
                    }
                    else if (goodRules.Count() == 1)
                    {
                        oneExtractRule.WriteLine("{0}\n{1}\n{2}", line, goodRules[0].AutoReplyRegexes.First().Regex, goodRules[0].Description);
                        oneExtractRule.WriteLine("----------------------------------");
                    }
                    else
                    {
                        manyRule.WriteLine(line);
                        foreach (AutoReplyRule rule in goodRules)
                        {
                            manyRule.WriteLine(rule.AutoReplyRegexes.First().Regex);
                            manyRule.WriteLine(rule.Description);
                        }
                        manyRule.WriteLine("----------------------------------");
                    }
                }
                oneExtractRule.Close();
                manyRule.Close();
            }
            //Console.ReadKey();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: zhijieqiu/migratedata
        public static void SeeCurrentStatus()
        {
            AddCannedReply acr            = new AddCannedReply();
            var            allRules       = acr.Db.AutoReplyRules;
            string         outputFileName = @"D:/zhijie/tmp/regexes.txt";

            using (StreamWriter sw = new StreamWriter(outputFileName))
            {
                foreach (var rule in allRules)
                {
                    Console.WriteLine(rule.AutoReplyRegexes.Count());
                    foreach (var regex in rule.AutoReplyRegexes)
                    {
                        //Console.WriteLine(regex.Regex);
                        sw.WriteLine(regex.Regex);
                    }
                }
                Console.WriteLine("please input a key");
                Console.ReadKey();
            }
        }