public DefaultImportService(ReferenceDataContext ctx) { _ctx = ctx; _csvConfiguration = new CsvConfiguration() { Delimiter = ";", CultureInfo = new CultureInfo("en"), HasHeaderRecord = true, IgnoreReadingExceptions = true }; }
public async void BuildUserDatabase() { string dbName = "UserRefDb" + Guid.NewGuid().ToString() + ".db3"; try { var ctx = new ReferenceDataContext(dbName); // Re-initialize all tables await ctx.InitializeDatabaseAsync(); // Perform import var importer = new DefaultImportService(ctx); ProgressMessage = AppResources.Settings_Progress_LoadingLines; string haltestellen = await importer.DownloadHaltestellenAsync(); ProgressMessage = AppResources.Settings_Progress_LoadingLines; string linien = await importer.DownloadLinienAsync(); ProgressMessage = AppResources.Settings_Progress_LoadingPlatforms; string steige = await importer.DownloadSteigeAsync(); if (null == haltestellen || null == linien || null == steige) { ProgressMessage = AppResources.Settings_Progress_ErrorDownloading; return; } ProgressMessage = AppResources.Settings_Progress_InsertingInDb; int countOfHaltestellen = await importer.ImportHaltestellenAsync(haltestellen); int countOfLinien = await importer.ImportLinienAsync(linien); int countOfSteige = await importer.ImportSteigeAsync(steige); await importer.CreateLookupTableAsync(); ProgressMessage = String.Format(AppResources.Settings_Progress_ImportSuccessMessage, countOfHaltestellen, countOfLinien, countOfSteige); _configurationService.UsingDefaultReferenceDatabase = false; _configurationService.CustomReferenceDatabaseName = dbName; _configurationService.ReferenceDatabaseBuildDate = DateTime.Now.Date; NotifyOfPropertyChange(() => CanRevertToDefault); NotifyOfPropertyChange(() => DatabaseBuildDateMessage); } catch (Exception ex) { ProgressMessage = AppResources.Settings_Progress_ImportFailed + ex.Message; Debug.WriteLine(ex.ToString()); } }
private static async Task<ImportResults> PerformImportActionsAsync() { var ctx = new ReferenceDataContext(); // Re-initialize all tables await ctx.InitializeDatabaseAsync(); // Perform import var importer = new DefaultImportService(ctx); var result = await importer.ImportBatchAsync(); result.LookupCount = await importer.CreateLookupTableAsync(); Debug.WriteLine("# of Haltestellen: " + result.HaltestellenCount); Debug.WriteLine("# of Linien: " + result.LinienCount); Debug.WriteLine("# of Steige: " + result.SteigeCount); Debug.WriteLine("# of Lookups: " + result.LookupCount); return result; }