/// <summary> /// 运行应用程序。 /// </summary> static void RunApplication() { // The output encoding differs based on whether FanHai Gui Framework is a console app (debug mode) // or Windows app (release mode). Because this flag also affects the default encoding // when reading from other processes' standard output, we explicitly set the encoding to get // consistent behaviour in debug and release builds of SolarViewerFramework. #if DEBUG // Console apps use the system's OEM codepage, windows apps the ANSI codepage. // We'll always use the Windows (ANSI) codepage. try { Console.OutputEncoding = System.Text.Encoding.Default; } catch (IOException) { // can happen if FanHai Gui Framework doesn't have a console } #endif LoggingService.Info("Starting MES Gui Framework..."); try { StartupSettings startup = new StartupSettings(); #if DEBUG startup.UseSolarViewerFrameworkErrorHandler = !Debugger.IsAttached; #endif Assembly exe = typeof(SolarViewerFrameworkMain).Assembly; startup.ApplicationRootPath = Path.GetDirectoryName(exe.Location); startup.AllowUserAddIns = true; string configDirectory = ConfigurationManager.AppSettings["settingsPath"]; //如果在config文件中没有配置settingsPath或配置的字符串为空。 if (String.IsNullOrEmpty(configDirectory)) { startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CHINT/AMES.1.0"); } else { startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory); } startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"]; if (string.IsNullOrEmpty(startup.DomPersistencePath)) { startup.DomPersistencePath = Path.Combine(Path.GetTempPath(), "FanHai.Hemera.Gui.StartUp" + RevisionClass.MainVersion); #if DEBUG startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug"); #endif } else if (startup.DomPersistencePath == "none") { startup.DomPersistencePath = null; } //添加插件 startup.AddAddInsFromDirectory(Path.Combine(startup.ApplicationRootPath, "AddIns")); foreach (string parameter in SplashScreenForm.GetParameterList()) {//如果参数以addindir:开头,将同样载入插件 if (parameter.StartsWith("addindir:", StringComparison.OrdinalIgnoreCase)) { startup.AddAddInsFromDirectory(parameter.Substring(9)); } } startup.ResourceAssemblyName = exe.FullName; SolarViewerHost host = new SolarViewerHost(AppDomain.CurrentDomain, startup); //隐藏启动画面 if (SplashScreenForm.SplashScreen != null) { SplashScreenForm.SplashScreen.Hide(); } string[] fileList = SplashScreenForm.GetRequestedFileList(); if (fileList.Length > 0) { } host.BeforeRunWorkbench += delegate { if (SplashScreenForm.SplashScreen != null) { SplashScreenForm.SplashScreen.BeginInvoke(new MethodInvoker(SplashScreenForm.SplashScreen.Dispose)); SplashScreenForm.SplashScreen = null; } }; WorkbenchSettings workbenchSettings = new WorkbenchSettings(); workbenchSettings.RunOnNewThread = false; for (int i = 0; i < fileList.Length; i++) { workbenchSettings.InitialFileList.Add(fileList[i]); } //登陆对话框 LoginDialog login = new LoginDialog(); login.ShowDialog(); if (LoginDialog.flag) { LoggingService.CloseCmd(); return; } host.RunWorkbench(workbenchSettings); } finally { //清除注册时间。 IChannel[] channels = ChannelServices.RegisteredChannels; foreach (IChannel eachChannel in channels) { ChannelServices.UnregisterChannel(eachChannel); } LoggingService.Info("Leaving RunApplication()"); } }