public PhotoImporter(ProcessingDirectories directories, ILogger <PhotoImporter> logger) { _directories = directories; _logger = logger; }
private async void ImportPhotos(object sender, RoutedEventArgs e) { Console.BufferHeight = short.MaxValue - 1; _logger.LogInformation("Import Photos requested by user"); try { ImportPhotosButton.IsEnabled = false; var sourceDirectory = OrganiseSourceTextBox.Text; var outputDirectory = OrganiseOutputTextBox.Text; _logger.LogInformation($"Source Directory: {sourceDirectory}"); _logger.LogInformation($"Output Directory: {outputDirectory}"); if (string.IsNullOrWhiteSpace(sourceDirectory)) { MessageBox.Show(this, $"The source directory must be supplied.", "Error", MessageBoxButton.OK); return; } if (string.IsNullOrWhiteSpace(outputDirectory)) { MessageBox.Show(this, $"The output directory must be supplied.", "Error", MessageBoxButton.OK); return; } if (!Directory.Exists(sourceDirectory)) { MessageBox.Show(this, $"The source directory {sourceDirectory} does not exist.", "Error", MessageBoxButton.OK); return; } if (new DirectoryInfo(sourceDirectory).FullName == new DirectoryInfo(outputDirectory).FullName) { MessageBox.Show(this, $"The source directory must be different from the output directory.", "Error", MessageBoxButton.OK); return; } // TODO: Check the output directory is not inside the source directory var progress = new Progress <decimal>(percent => { ProgressBar.Value = (int)percent; }); await Task.Run(async() => { _logger.LogInformation($"Import photos started from {sourceDirectory} to {outputDirectory}"); var directories = ProcessingDirectories.From(sourceDirectory, outputDirectory, null); var cancellationToken = CancellationToken.None; var logger = _serviceProvider.GetService <ILogger <PhotoImporter> >(); var importer = new PhotoImporter(directories, logger); await importer.ImportAsync(progress, cancellationToken); _logger.LogInformation("Complete"); }); } finally { ImportPhotosButton.IsEnabled = true; } }