예제 #1
0
        private static void RunOptions(CommandLineOptions options)
        {
            // Build Container

            IContainer container = PluginManager.Compose();

            // Initialize Context Logger

            LogHelper     logHelper = container.Resolve <LogHelper>();
            ContextLogger logger    = logHelper.CreateContextLogger(Application.Current);

            // Test Logging

            string appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            logger.Log(LogEventLevel.Information, "Ruminoid Studio - 版本{AppVersion}", appVersion);

            // Add Event Handler

            Application.Current.DispatcherUnhandledException += (sender, args) =>
            {
                args.Handled = true;

                logger.LogException(LogEventLevel.Error, "发生了一个故障。", args.Exception);

                new TaskDialog
                {
                    EnableHyperlinks = false,
                    MainInstruction  = "发生了一个故障。",
                    WindowTitle      = "灾难性故障",
                    Content          = args.Exception.Message,
                    MainIcon         = TaskDialogIcon.Error,
                    MinimizeBox      = false,
                    Buttons          =
                    {
                        new TaskDialogButton(ButtonType.Ok)
                    }
                }.ShowDialog();
            };

            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                if (!(args.ExceptionObject is Exception))
                {
                    return;
                }

                logger.LogException(LogEventLevel.Fatal, "发生了一个故障。", (Exception)args.ExceptionObject);

                new TaskDialog
                {
                    EnableHyperlinks = false,
                    MainInstruction  = "发生了一个故障。",
                    WindowTitle      = "灾难性故障",
                    Content          = ((Exception)args.ExceptionObject).Message ?? "Exception",
                    MainIcon         = TaskDialogIcon.Error,
                    MinimizeBox      = false,
                    Buttons          =
                    {
                        new TaskDialogButton(ButtonType.Ok)
                    }
                }.ShowDialog();
            };

            // Load Project

            logger.Log(LogEventLevel.Warning, "Lifecycle Helper: 开始加载项目。");

            ProjectManager projectManager = container.Resolve <ProjectManager>();

            projectManager.Load(options.ProjectFile);

            // Change Default Culture

            Resources.Culture = CultureInfo.CurrentUICulture;

            // Register Theme Service

            ThemeService.Current.Register(Application.Current, Theme.Windows, Accent.Windows);

            // Initialize Main Window

            Application.Current.MainWindow = new MainWindow();
            Application.Current.MainWindow.Show();

            // Change Default Theme

            Application.Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeTheme(Theme.Dark));
            Application.Current.Dispatcher?.Invoke(() => ThemeService.Current.ChangeAccent(Accent.Blue));
        }