static async Task <int> Main(string[] args) //03-12-18 made async and returns int not void { MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures); MxReturnCode <int> rc = new MxReturnCode <int>("Main()", -1, "*****@*****.**"); try //03-12-18 { IWebHost host = CreateWebHostBuilder(args).Build(); //calls Startup.ConfigureServices() using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; if (services == null) { rc.SetError(3130101, MxError.Source.Sys, "scope.ServiceProvider is null"); } else { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var config = services.GetRequiredService <IConfiguration>(); if ((userManager == null) || (roleManager == null) || (config == null)) { rc.SetError(3130102, MxError.Source.Sys, "userManager or roleManager or config is null"); } else { var result = await SeedDb.EnsureDataPresentAsync(config, userManager, roleManager); rc += result; if (result.IsSuccess()) { host.Run(); //calls Startup.Configure() rc.SetResult(0); //success - webapp has completed } } } } } catch (Exception e) { rc.SetError(3010103, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true); } return(rc.GetResult()); //03-12-18 }
static async Task <int> Main(string[] args) //Uses Dapper/Gdpr.Domain Repository classes to access the database { MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures); MxReturnCode <int> rc = new MxReturnCode <int>(string.Format("{0} v{1}", "ReturnCodeApp()", GetVersion()), 1, "*****@*****.**"); var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("local.settings.json") .Build(); var conn = config?["ConnectionStrings:DefaultConnection"]; //03-12-18 if (conn == null) { rc.SetError(2010101, MxError.Source.AppSetting, "config not built or ConnectionStrings:DefaultConnection not found"); } else { using (IAdminRepository repository = new AdminRepository(conn)) { rc += await repository.GetRoleCountAsync(); } if (rc.IsSuccess()) { Console.WriteLine(@"URD Count = {0}", rc.GetResult()); } } if (rc.IsError()) { Console.WriteLine(rc.GetErrorUserMsg()); Console.WriteLine(rc.GetErrorTechMsg()); } else { Console.WriteLine("ends ok"); } return(rc.IsSuccess() ? 0 : -1); }
public RepositoryBaseFixture() { MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures); Db = new AdminRepository(ConfigSettings.LocalDbConnectionStr); }
public static void Main(string[] args) { MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures); CreateWebHostBuilder(args).Build().Run(); }