private void CmbConfigFiles_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var cmbConfig = (ComboBox)sender;

            if (cmbConfig?.SelectedItem != null)
            {
                SaveDownloadList();
                _datasetService = new DatasetService(_appSettings.GetConfigByName(cmbConfig.SelectedItem.ToString()));
                _appSettings.LastOpendConfigFile = _appSettings.GetConfigByName(cmbConfig.SelectedItem.ToString());
                ApplicationService.WriteToAppSettingsFile(_appSettings);
                _selectedFilesForDownload = _datasetService.GetSelectedFilesToDownloadAsViewModel();
                LbSelectedFilesForDownload.ItemsSource = _selectedFilesForDownload;
            }
        }
 private void OnChanged(object source, FileSystemEventArgs e)
 {
     try
     {
         _selectedFilesForDownload = _datasetService.GetSelectedFilesToDownloadAsViewModel();
         Dispatcher.Invoke(() =>
         {
             LbSelectedFilesForDownload.ItemsSource = _selectedFilesForDownload;
         });
     }
     catch (Exception err)
     {
         System.Windows.MessageBox.Show(err.Message);
     }
 }
        public MainWindow()
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .WriteTo.File("log-.txt",
                                       rollOnFileSizeLimit: true,
                                       shared: true,
                                       flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .CreateLogger();

            Log.Information("Start application");

            InitializeComponent();


            BtnSelectAll.Visibility = Visibility.Hidden;
            BtnSelectAll.IsChecked  = false;
            ToggleSubscribeSelectedDatasetFiles.Visibility = Visibility.Hidden;
            MenuSubscribe.Visibility = Visibility.Hidden;

            var massivNedlastingVersjon = new MassivNedlastingVersion(new GitHubReleaseInfoReader());

            _currentVersion = MassivNedlastingVersion.Current;
            if (massivNedlastingVersjon.UpdateIsAvailable())
            {
                versionStatusMessage.Visibility = Visibility.Visible;
                versionStatusMessage.Text       = "Ny versjon tilgjengelig!";
            }
            else
            {
                versionStatusMessage.Visibility = Visibility.Collapsed;
            }

            _appSettings        = ApplicationService.GetAppSettings();
            _datasetService     = new DatasetService(_appSettings.LastOpendConfigFile);
            _selectedConfigFile = _appSettings.LastOpendConfigFile;
            _datasetService.UpdateProjections();
            _datasetService.ConvertDownloadToDefaultConfigFileIfExists();


            try
            {
                LbDatasets.ItemsSource = _datasetService.GetDatasets();
                fylker.ItemsSource     = _datasetService.GetCounties();
            }
            catch (Exception)
            {
                MessageBox.Show("Klarer ikke hente datasett... Sjekk internett tilkoblingen din");
            }


            _selectedFilesForDownload = _datasetService.GetSelectedFilesToDownloadAsViewModel();
            _selectedDatasetFiles     = new List <DatasetFileViewModel>();

            var viewDatasets = (CollectionView)CollectionViewSource.GetDefaultView(LbDatasets.ItemsSource);

            if (viewDatasets != null)
            {
                viewDatasets.Filter = UserDatasetFilter;
            }

            LbSelectedFilesForDownload.ItemsSource = _selectedFilesForDownload;

            cmbConfigFiles.ItemsSource  = ApplicationService.NameConfigFiles();
            cmbConfigFiles.SelectedItem = _selectedConfigFile.Name;

            SetDownloadUsage();

            RunWatch();
        }