Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Utils.WriteLogFile("启动服务...");
                string   time        = ConfigurationManager.AppSettings["time"].ToString();
                DateTime lastruntime = DateTime.Parse("1900-01-01");
                timer = new Timer((o) =>
                {
                    if (DateTime.Now - lastruntime > TimeSpan.FromMinutes(int.Parse(time)))
                    {
                        lastruntime = DateTime.Now;
                        try
                        {
                            Utils.WriteLogFile("正在导入数据...");
                            string rs = ElasticSearchHelper.SetIndexAlias();
                            if (rs.Length > 0)
                            {
                                Utils.WriteLogFile("Mall导入完成,新的索引名称为:" + rs);
                            }
                            else
                            {
                                Utils.WriteLogFile("Mall导入失败");
                            }

                            rs = ElasticSearchHelper.SetSuggestIndex();
                            if (rs.Length > 0)
                            {
                                Utils.WriteLogFile("MallSuggest导入完成,新的索引名称为:" + rs);
                            }
                            else
                            {
                                Utils.WriteLogFile("MallSuggest导入失败");
                            }
                        }
                        catch (Exception ex)
                        {
                            Utils.WriteLogFile(ex.Message);
                        }
                    }
                }, null, 0, 1000);
                Utils.WriteLogFile("服务已启动");
            }
            catch (Exception ex1)
            {
                Utils.WriteLogFile(ex1.Message);
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            try
            {
                string IndexNew = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now);
                Console.WriteLine("正在导入数据...");
                string rs = ElasticSearchHelper.SetIndexAlias();
                if (rs.Length > 0)
                {
                    Utils.WriteLogFile("Mall导入完成,新的索引名称为:" + rs);
                    Console.WriteLine("Mall导入完成,新的索引名称为:" + rs);
                }
                else
                {
                    Utils.WriteLogFile("Mall导入失败");
                    Console.WriteLine("Mall导入失败");
                }

                rs = ElasticSearchHelper.SetSuggestIndex();
                if (rs.Length > 0)
                {
                    Utils.WriteLogFile("MallSuggest导入完成,新的索引名称为:" + rs);
                    Console.WriteLine("MallSuggest导入完成,新的索引名称为:" + rs);
                }
                else
                {
                    Utils.WriteLogFile("MallSuggest导入失败");
                    Console.WriteLine("MallSuggest导入失败");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            int count = 100;

            for (int i = 0; i < count; i++)
            {
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine((count - i) + "秒后自动关闭");
            }
        }