Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .WriteTo.File("log-.txt",
                                       rollOnFileSizeLimit: true,
                                       shared: true,
                                       flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .CreateLogger();

            Log.Information("Start Geonorge - nedlaster");
            Console.WriteLine("Geonorge - nedlaster");
            Console.WriteLine("--------------------");
            var appSettings = ApplicationService.GetAppSettings();

            if (args.Any())
            {
                Log.Debug("Selected config file(s): ");

                foreach (var configName in args)
                {
                    Log.Debug(configName);
                }

                foreach (var configName in args)
                {
                    Log.Debug("Download from selected config-file: " + configName);
                    var config = appSettings.GetConfigByName(configName);
                    if (config != null)
                    {
                        DeleteOldLogs(config.LogDirectory);
                        StartDownloadAsync(config).Wait();
                    }
                    else
                    {
                        Log.Error("Could not find config file: " + configName);
                        Console.WriteLine("Error: Could not find config file: " + configName);
                    }
                }
            }
            else
            {
                Log.Debug("No config file is selected. Download from all config-files");
                var datasetService = new DatasetService(appSettings.LastOpendConfigFile);
                datasetService.ConvertDownloadToDefaultConfigFileIfExists();

                foreach (var config in appSettings.ConfigFiles)
                {
                    StartDownloadAsync(config).Wait();
                }
            }
        }
        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();
        }