Exemplo n.º 1
0
        static void Init(IStartup startup)
        {
            //注册引导
            startup.InfoText = "正在初始化插件系统....";
            startup.DispatchUI(() =>
            {
                new ServiceManager().Load();
            });

            //初始化配置
            AppContext.ExtensionManager.ConfigurationProvider.Init(startup);

            //重置设置
            if (_cmd.Any(s => s == "/reset"))
            {
                AppContext.ExtensionManager.ConfigurationProvider.Reset();
            }

            Root.Init();

            if (ProgramConfiguration.Instance.CurrentVersion != Version)
            {
                startup.Update("正在升级...");
                //TODO: 版本升级初始化数据
                ProgramConfiguration.Instance.CurrentVersion = Version;
            }
            if (ProgramConfiguration.Instance.SubmitOrderBrowser != null && !ProgramConfiguration.Instance.SubmitOrderBrowser.IsAvailable)
            {
                ProgramConfiguration.Instance.SubmitOrderBrowser = null;
            }

            Statistics.Current.LastStartTime = DateTime.Now;
            Statistics.Current.StartupCount++;

            //初始化配置
            startup.Update("正在初始化配置信息....");
            NetworkEnvironment.Init(startup, () => startup.DispatchUI(new Action(RequireInitProxy)));

            //正在初始化相关信息
            new ResourceInitializer(startup).Run();

            //初始化服务
            startup.Update("正在初始化服务....");
            if (EnableAutoVcLoading)
            {
                VerifyCodeRecognizeServiceLoader.Init();
            }

            //更新HTTP配置
            var(success, message) = AppContext.ExtensionManager.GlobalKernel.Resolve <IWeb12306ConfProvider>().RefreshAsync().Result;
            if (!success)
            {
                throw new Exception("更新HTTP配置出错: " + message);
            }
            else
            {
                ParamData.Init();
            }

            //恢复会话
            startup.Update("正在恢复现场....");
            RunTime.SessionManager.TryRecoverSession(_ => startup.Update("正在尝试自动登录 " + _ + " ..."));

            //初始化资源
            startup.Update("初始化资源....");

            using (var g = startup.CreateGraphics())
            {
                DpiX = g.DpiX;
                DpiY = g.DpiY;
            }
        }