コード例 #1
0
        static void Main(string[] args)
        {
            try
            {
                //1:初始化容器和服务
                IOCFactory.InitContainer();
                ICategoryService categoryService = IOCFactory.Resolve <ICategoryService>();
                //2:初始化数据库
                InitDb(categoryService);
                //3:插入类别数据
                LoadCategory(categoryService);
                //4:加载明细数据并将数据插入到db中
                LoadCommodty(categoryService);
            }
            catch (Exception ex)
            {
                //如果其中一个线程出现异常,那么就终止所有其他线程
                cts.Cancel();
                ctsPrice.Cancel();
                //出现异常中断其他运行的线程
                Console.WriteLine("页面抓取出现异常:{0}", ex.Message);
            }

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                #region 1.0 特性封装
                Console.WriteLine("*************特性封装********************");
                string strAndroid = MobileEnum.Android.GetRemark();
                string strIOS     = MobileEnum.IOS.GetRemark();

                Console.WriteLine($"android备注:{strAndroid},ios的备注{strIOS}");
                #endregion


                #region 2.0 封装方法
                Console.WriteLine("*************Unity 使用********************");
                //初始化unity
                IOCFactory.InitContainer();

                Person person = new Person();
                person.Address = "哈哈哈11111111";
                person.Name    = "dark";
                person.Email   = "*****@*****.**";
                person.Phone   = "18652428020";

                ISQLHelper sqlHelper = IOCFactory.Resolve <ISQLHelper>();
                sqlHelper.Insert <Person>(person);

                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine($"系统异常:{ex.Message.ToString()}");
                throw;
            }

            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            try
            {
                #region 1.0 爬虫
                //1:初始化容器和服务
                IOCFactory.InitContainer();
                ICategoryService  categoryService  = IOCFactory.Resolve <ICategoryService>();
                ICommodityService commodityService = IOCFactory.Resolve <ICommodityService>();
                //这个是爬虫的demo
                //CrawlerDemo(categoryService, commodityService);
                #endregion

                #region 2.0 lucene.net
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"*****************lucene.net demo*****************");
                LuceneTools luceneTools = new LuceneTools(commodityService);
                //luceneTools.InitLucene();
                luceneTools.QueryList("Title:asus", new Page()
                {
                    Sort = "Price"
                }, "[100,200]");
                #endregion

                #region 3.0 redis 异步队列
                //3.1 启动异步队列
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"*****************启动一个异步队列*****************");
                RedisTools.Current.Start(luceneTools);
                //3.2 添加一个实体
                Console.WriteLine($"1.0 添加一个实体到数据");
                GM_Commodity commodity = new GM_Commodity()
                {
                    Title     = "华硕(asus),测试数据",
                    ImageUrl  = "",
                    Price     = 150,
                    ProductId = "11",
                    SkuId     = "11",
                    Url       = "http://www.baidu.com"
                };
                int id = commodityService.Insert(commodity);
                Console.WriteLine($"2.0 添加一个实体到数据库,得到的Id={id}");
                commodity.Id = id;
                //将该数据添加到异步队列中
                Console.WriteLine($"3.0 更新实体到索引中");
                RedisTools.Current.Add(commodity);
                //停留2秒中等待redis中的数据更新到index 中
                Thread.Sleep(2000);
                Console.WriteLine($"4.0 在查询包含 asus的索引");
                luceneTools.QueryList("Title:asus", new Page()
                {
                    Sort = "Price"
                }, "[100,200]");
                #endregion
            }
            catch (Exception ex)
            {
                //如果其中一个线程出现异常,那么就终止所有其他线程
                cts?.Cancel();
                ctsPrice?.Cancel();
                //出现异常中断其他运行的线程
                Console.WriteLine("页面抓取出现异常:{0}", ex.Message);
            }

            Console.ReadLine();
        }