コード例 #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                //1.MEF初始化
                MefConfig.Init();

                //2.数据库初始化连接
                ConfigInit.InitConfig();

                //3.系统参数配置初始化
                ConfigManager configManager = MefConfig.TryResolve <ConfigManager>();
                configManager.Init();

                //4.任务启动
                QuartzHelper.InitScheduler();
                QuartzHelper.StartScheduler();

                //5.加载SQL信息到缓存中
                XmlCommandManager.LoadCommnads(SysConfig.XmlCommandFolder);
                //开发时监听资源文件变化,用于实时更新
                DevelperHelper.WatcherResourceChange();

                // 保持web服务运行
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    //7.启动站点
                    using (NancyHost host = Startup.Start(SystemConfig.WebPort))
                    {
                        //调用系统默认的浏览器
                        string url = string.Format("http://127.0.0.1:{0}", SystemConfig.WebPort);
                        LogHelper.WriteLog(string.Format("系统已启动,当前监听站点地址:{0}", url));
                        try
                        {
                            //4.消息队列启动
                            RabbitMQClient.InitClient();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                        //8.系统命令初始化
                        CommandHelp.Init();
                    }
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("服务启动异常", ex);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            AdminRun.Run();

            if (!SetConsoleCtrlHandler(cancelHandler, true))
            {
                Console.WriteLine("程序监听系统按键异常");
            }
            try
            {
                //1.MEF初始化
                MefConfig.Init();

                //2.数据库初始化连接
                ConfigInit.InitConfig();

                //3.系统参数配置初始化
                ConfigManager configManager = MefConfig.TryResolve <ConfigManager>();
                configManager.Init();

                Console.Title         = SystemConfig.ProgramName;
                Console.CursorVisible = false; //隐藏光标

                //4.任务启动
                QuartzHelper.InitScheduler();
                QuartzHelper.StartScheduler();

                //5.加载SQL信息到缓存中
                XmlCommandManager.LoadCommnads(SysConfig.XmlCommandFolder);
                //开发时监听资源文件变化,用于实时更新
                DevelperHelper.WatcherResourceChange();

                //测试dapper orm框架
                //DapperDemoService.Test();

                //启动站点
                using (NancyHost host = Startup.Start(SystemConfig.WebPort))
                {
                    //调用系统默认的浏览器
                    string url = string.Format("http://127.0.0.1:{0}", SystemConfig.WebPort);
                    Process.Start(url);
                    Console.WriteLine("系统已启动,当前监听站点地址:{0}", url);
                    try
                    {
                        //4.消息队列启动
                        RabbitMQClient.InitClient();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                    //5.系统命令初始化
                    CommandHelp.Init();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.Read();
        }