public static async Task DbSeed(IWebHost host) { using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { ApplicationContext context = services.GetRequiredService <ApplicationContext>(); await context.Database.EnsureCreatedAsync().ConfigureAwait(false); await context.Database.MigrateAsync().ConfigureAwait(false); AppService appService = services.GetRequiredService <AppService>(); try { Appp ret = await appService.Get("aggregate").ConfigureAwait(false); } catch (Exception e) { if (e.Message.Contains("'aggregate' not found")) { long epochTime = DateTimeOffset.Now.ToUnixTimeSeconds(); await appService.Post(new Appp { AppId = "aggregate", FirstSeen = epochTime, FriendlyName = "Aggregated Data", LastSeen = epochTime }).ConfigureAwait(false); } } } catch (InvalidCastException ex) { ILogger <Program> logger = services.GetRequiredService <ILogger <Program> >(); foreach (DictionaryEntry dictionaryEntry in ex.Data) { logger.LogError(ex, $"{dictionaryEntry.Key}={dictionaryEntry.Value}"); } logger.LogError(ex, "An error occurred while seeding the database."); } } }
public AppCard(Appp app) { App = app; }