public MainView(LoggingService loggingService, ScrapperProvider scrapperProvider) { WindowStartupLocation = WindowStartupLocation.CenterScreen; _loggingService = loggingService; InitializeComponent(); DataContext = new MainViewViewModel(loggingService, scrapperProvider); (DataContext as MainViewViewModel).PropertyChanged += MainViewPropertyChanged; KeyUp += OnWindowKeyUp; ((MainViewViewModel)DataContext).UpdateFocus += OnUpdateFocus; }
protected override void OnStartup(StartupEventArgs e) { try { var loggingService = new LoggingService(); var currencyApi = new CurrencyApi(loggingService); var scrapperProvider = new ScrapperProvider(loggingService, currencyApi); MainWindow = new MainView(loggingService, scrapperProvider); MainWindow.Closed += MainWindowClosed; MainWindow.Show(); base.OnStartup(e); } catch (Exception ex) { new LoggingService().LogException(ex, "Unhandled exception while starting the app up"); } }
public MainViewViewModel(LoggingService loggingService, ScrapperProvider scrapperProvider) { _loggingService = loggingService; _scrapperProvider = scrapperProvider; _scrappers = new ObservableCollection <ScrapperInfoViewModel>(scrapperProvider.ScrapingServices.Select(x => new ScrapperInfoViewModel(x))); OnPropertyChanged(nameof(Scrappers)); foreach (var scrapper in _scrappers) { scrapper.Model.AsyncScrapCompleted += ScrapingCompleted; scrapper.IsCheckedChanged += () => { OnPropertyChanged(nameof(IsAllChecked)); OnPropertyChanged(nameof(IsAuctionsChecked)); OnPropertyChanged(nameof(IsAdsChecked)); OnPropertyChanged(nameof(IsCompaniesChecked)); }; } _loggingService.LogText("View Model started"); CanSearch = true; FilterRequiredVisibility = Visibility.Collapsed; _advertisements = new ObservableCollection <AdvertisementViewModel>(); _unpagedAdvertisements = new List <AdvertisementViewModel>(); _comparer = new AdvertisementsComparer(); SearchCommand = new DelegateCommand(SearchCommandExecute, SearchCommandCanExecute); SwitchPageCommand = new DelegateCommand(SwitchPageCommandExecute, SwitchPageCommandCanExecute); RefreshCommand = new DelegateCommand(RefreshCommandExecute, RefreshCommandCanExecute); ToggleAllSearchesCommand = new DelegateCommand(ToggleAllSearchesCommandExecute, ToggleAllSearchesCommandCanExecute); ToggleAllAuctionsCommand = new DelegateCommand(ToggleAllAuctionsCommandExecute, ToggleAllAcutionsCommandCanExecute); ToggleAllAdsCommand = new DelegateCommand(ToggleAllAdsCommandExecute, ToggleAllAdsCommandCanExecute); ToggleAllCompaniesCommand = new DelegateCommand(ToggleAllCompaniesCommandExecute, ToggleAllCompaniesCommandCanExecute); UntoggleAllCommand = new DelegateCommand(UntoggleAllComandExecute, UntoggleAllCommandCanExecute); PreviousSubPageCommand = new DelegateCommand(PreviousSubPageCommandExecute, PreviousSubPageCommandCanExecute); NextSubPageCommand = new DelegateCommand(NextSubPageCommandExecute, NextSubPageCommandCanExecute); SetTimer(); }