public async Task EnsureMigrated() { try { if ((await _dbContext.Database.GetPendingMigrationsAsync()).Any()) { Utilis.DieWith("There are pending migrations!\nrun 'dotnet run --migrate true'"); } } catch (Exception e) { Utilis.DieWith("Can't ensure database is migrated. \nReason: " + e.Message); } }
private void GenerateViews(IServiceProvider serviceProvider) { var viewNames = Configuration.GetValue <string>("view-names"); if (string.IsNullOrEmpty(viewNames)) { Utilis.DieWith("Missing --view-names argument"); } if (viewNames == "all") { viewNames = "_Display,_Form,Create,Delete,Details,Edit,Index,ReOrder"; } foreach (var vn in viewNames.Split(',')) { GenerateView(serviceProvider, vn); } }
private void GenerateView(IServiceProvider serviceProvider, string viewName) { var controllerType = GetControllerType(); if (!typeof(IGenerableView).IsAssignableFrom(controllerType)) { Utilis.DieWith("Controller type '" + controllerType + "' doesn't implement '" + typeof(IGenerableView) + "'"); } var controllerInstance = (IGenerableView)serviceProvider.GetService(controllerType); controllerInstance.SetServiceProvider(serviceProvider); controllerInstance.BuildGenerableMetadata(); if (!controllerType.ImplementsGenericInterface(typeof(IGenerableView <>))) { throw new Exception($"{controllerType.Name} is not a {typeof(IGenerableView<>).Name}"); } var methodInfo = controllerType.GetMethods().FirstOrDefault(m => m.Name == viewName); if (!viewName.StartsWith("_") && methodInfo == null) { throw new Exception($"Invalid viewName '{viewName}' on controller '{controllerType.FullName}'"); } var entityType = controllerType.GetGenericArgumentTypeOfImplementedGenericInterface(typeof(IGenerableView <>)); var mi = typeof(IUiViewGeneratorService).GetMethod(nameof(IUiViewGeneratorService.GenerateFor)); mi = mi.MakeGenericMethod(entityType); var viewGenerator = serviceProvider.GetService <IUiViewGeneratorService>(); var task = (Task)mi.Invoke(viewGenerator, new object[] { viewName, controllerInstance }); task.Wait(); }
private Type GetControllerType() { var controller = Configuration.GetValue <string>("controller"); if (string.IsNullOrEmpty(controller)) { Utilis.DieWith("Missing --controller argument"); } if (!controller.EndsWith("Controller")) { controller += "Controller"; } var controllerType = GetTypeExtensions.GetType(controller); if (controllerType == null) { Utilis.DieWith("Couldn't locate controller type '" + controller + "'"); } return(controllerType); }