/// <summary> /// Initializes a new instance of the <see cref="MainWindow" /> class. /// </summary> /// <param name="viewModel">The view model of the main window.</param> /// <param name="newsViewViewModel">The view model of the news view.</param> /// <param name="favoritesViewViewModel">The view model of the favorites view.</param> public MainWindow( MainWindowViewModel viewModel, NewsViewViewModel newsViewViewModel, FavoritesViewViewModel favoritesViewViewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } if (newsViewViewModel == null) { throw new ArgumentNullException(nameof(newsViewViewModel)); } if (favoritesViewViewModel == null) { throw new ArgumentNullException(nameof(favoritesViewViewModel)); } this.InitializeComponent(); this.DataContext = viewModel; this.NewsView.DataContext = newsViewViewModel; this.FavoritesView.DataContext = favoritesViewViewModel; }
/// <summary> /// Initializes a new instance of the <see cref="App" /> class. /// </summary> public App() { AppDomain.CurrentDomain.UnhandledException += this.CurrentDomainUnhandledException; AppDomain.CurrentDomain.ProcessExit += this.CurrentDomainProcessExit; if (!this.mutex.WaitOne()) { // The application is already running. Environment.Exit(1); } this.config = this.LoadConfig(); if (!string.IsNullOrEmpty(this.config.SelectedLanguage)) { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this.config.SelectedLanguage); } else { this.config.SelectedLanguage = Thread.CurrentThread.CurrentCulture.Name; } CultureInfo fallbackCultureInfo = CultureInfo.GetCultureInfo("EN-us"); this.resourceManager = new ResourceManager(Thread.CurrentThread.CurrentCulture, fallbackCultureInfo); this.favoritesServerWatcher = new ServerWatcher(28970, 100, 1000, 2000); this.favoritesServerWatcher.Start(); // Load the saved favorites servers. try { foreach (var favoriteServer in this.config.FavoriteServers) { this.favoritesServerWatcher.AddServer(favoriteServer); } } catch (Exception) { MessageBox.Show( this.resourceManager["resErrorInvalidServerInConfig"].Value, "Invalid server address loaded", MessageBoxButton.OK, MessageBoxImage.Warning); } // Registry var registry = new RegistryConfig(); // MainWindowViewModel MainWindowViewModel mainWindowViewModel = new MainWindowViewModel( this.config, registry, new Updater.Updater(), this.resourceManager); // NewsViewModel NewsViewViewModel newsViewViewModel = new NewsViewViewModel( this.resourceManager["resNewsNotLoaded"].Value, this.resourceManager); // FavoritesViewModel FavoritesViewViewModel favoritesViewViewModel = new FavoritesViewViewModel( this.favoritesServerWatcher, new G2OStarter(registry), this.resourceManager); // Main window MainWindow window = new MainWindow(mainWindowViewModel, newsViewViewModel, favoritesViewViewModel); window.Show(); }