public static async Task Main(string[] args) { var configuration = ConfigureSettings.Build(args); serviceProvider = ConfigureDi.BuildDi(configuration); logger = serviceProvider.GetService <ILogger <Program> >(); try { logger.LogInformation("Starting"); var configurationChecker = serviceProvider.GetRequiredService <ConfigurationChecker>(); var configurationCheck = configurationChecker.ConfigurationIsValid(); if (configurationCheck.Errors.Any()) { logger.LogError("Configuration is invalid, stopping."); return; } var argumentParser = serviceProvider.GetRequiredService <ArgumentParser>(); var dataFiles = argumentParser.ParseArgs(args); if (dataFiles.UnableToParseArguments) { logger.LogError("Unable to parse command line, details follow."); foreach (var message in dataFiles.Errors) { logger.LogCritical(message); } } else { var sawyerFactory = serviceProvider.GetRequiredService <SawyerFactory>(); var sawmill = sawyerFactory.CreateCsvReaderWriter(dataFiles.Source.FullName, dataFiles.Destination.FullName); await sawmill.ProcessTreeDataAsync(); // Output a bunch of stats on the tree we just processed. var treeAnalyser = serviceProvider.GetRequiredService <TreeAnalyser>(); var jsonTreeWriter = new JsonTreeWriter(null, dataFiles.Destination.FullName); var trees = await jsonTreeWriter.ReadAllAsync(); var treeStatistics = treeAnalyser.GenerateStatistics(trees); var consoleTreeReporter = serviceProvider.GetRequiredService <ConsoleTreeReporter>(); consoleTreeReporter.OutputToConsole(treeStatistics); } } catch (Exception ex) { logger.LogCritical(ex, "Unable to start application."); Console.WriteLine("Unable to start application."); } logger.LogInformation("Complete"); Console.WriteLine("Press a key to exit."); Console.ReadKey(); }
public static async Task Main(string[] args) { var configuration = ConfigureSettings.Build(args); serviceProvider = ConfigureDi.BuildDi(configuration); logger = serviceProvider.GetService <ILogger <Program> >(); try { var addresses = new List <string> { "Luton", "Unknown", "?", "75 Beadlow Road, Lewsey Farm, Luton, LU4 0QZ", "75 Beadlow Road, Lewsey Farm, Luton, LU4 0QZ, UK", }; var geocodeManager = serviceProvider.GetRequiredService <GeocodeManager>(); foreach (var address in addresses) { var geocoded = await geocodeManager.GeocodeAddressAsync(address); using (logger.BeginScope("Geocoding results for '{address}' via {engine}", address, geocoded.GeocoderId)) { foreach (var location in geocoded.Locations) { logger.LogInformation("Result '{address}', {lat},{lng} from {source}", location.FormattedAddress, location.Location.Latitude, location.Location.Longitude, geocoded.GeocoderId); } } } } catch (Exception ex) { logger.LogCritical(ex, "Error running console"); } logger.LogInformation("Complete, press a key to quit"); Console.ReadKey(); }