Пример #1
0
        /// <summary>
        /// Function that's run when the program first starts.
        /// Set up the data context links with the local variables.
        /// </summary>
        public MainWindow()
        {
            try
            {
                // Set up an event handler for any otherwise unhandled exceptions in the code.
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                InitializeComponent();

                Title = $"{ProductInfo.Name} - {ProductInfo.Version}";

                // Load configuration data
                QuestCollectionWrapper config;
                try
                {
                    config = NetTallyConfig.Load();
                }
                catch (ConfigurationErrorsException e)
                {
                    MessageBox.Show(e.Message, "Error in configuration.  Current configuration ignored.", MessageBoxButton.OK, MessageBoxImage.Error);
                    config = null;
                }

                PlatformSetup(config);
            }
            catch (Exception e)
            {
                ErrorLog.Log(e);
                MessageBox.Show(e.Message, "Unable to start up. Closing.", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// Function that's run when the program first starts.
        /// Set up the data context links with the local variables.
        /// </summary>
        public MainWindow(ViewModel model, IoCNavigationService navigationService, ILogger <MainWindow> logger)
        {
            // Initialize the readonly fields.
            this.mainViewModel     = model;
            this.navigationService = navigationService;
            this._syncContext      = SynchronizationContext.Current !;
            this.logger            = logger;

            try
            {
                // Set up an event handler for any otherwise unhandled exceptions in the code.
                AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
                AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

                // Initialize the window.
                InitializeComponent();

                // Set the title.
                Title = $"{ProductInfo.Name} - {ProductInfo.Version}";

                // Load configuration data
                QuestCollection?quests       = null;
                string?         currentQuest = null;

                try
                {
                    logger.LogDebug("Loading configuration.");
                    NetTallyConfig.Load(out quests, out currentQuest, AdvancedOptions.Instance);
                    logger.LogInformation("Configuration loaded.");
                }
                catch (ConfigurationErrorsException e)
                {
                    MessageBox.Show(e.Message, "Error in configuration.  Current configuration ignored.", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                // Complete the platform setup.
                PlatformSetup(quests, currentQuest);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failure during program startup.");
                ShowWarning("Unable to start the program.", "Failure on startup");
                this.Close();
            }
        }
Пример #3
0
        /// <summary>
        /// Function that's run when the program first starts.
        /// Set up the data context links with the local variables.
        /// </summary>
        public MainWindow()
        {
            try
            {
                _syncContext = SynchronizationContext.Current;

                // Set up an event handler for any otherwise unhandled exceptions in the code.
                AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
                AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

                // Set up the logger to use the Windows error log.
                Logger.LogUsing(new WindowsErrorLog());

                // Initialize the window.
                InitializeComponent();

                // Set the title.
                Title = $"{ProductInfo.Name} - {ProductInfo.Version}";

                // Load configuration data
                QuestCollection quests       = null;
                string          currentQuest = null;

                try
                {
                    NetTallyConfig.Load(out quests, out currentQuest, AdvancedOptions.Instance);
                }
                catch (ConfigurationErrorsException e)
                {
                    MessageBox.Show(e.Message, "Error in configuration.  Current configuration ignored.", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                // Complete the platform setup.
                PlatformSetup(quests, currentQuest);
            }
            catch (Exception e)
            {
                Logger.Error("Failure during program startup.", e);
                MessageBox.Show(e.Message, "Unable to start up. Closing.", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }