public async Task GenerateFor <TE>(string viewName, IGenerableView <TE> generableView) where TE : Entity { // Console.WriteLine("UiViewGeneratorService.GenerateFor: " + generableView.GetType().Name); var viewDirectory = GetViewDirectory(generableView); Directory.CreateDirectory(viewDirectory); switch (viewName) { case "Index": await RenderView((IGenerableIndexView <TE>) generableView, viewDirectory, viewName); break; case "_Display": await RenderView((IGenerableDisplayView <TE>) generableView, viewDirectory, viewName); break; case "Details": await RenderView((IGenerableDetailsView <TE>) generableView, viewDirectory, viewName); break; case "_Form": await RenderView((IGenerableFormView <TE>) generableView, viewDirectory, viewName); break; case "Create": await RenderView((IGenerableCreateView <TE>) generableView, viewDirectory, viewName); break; case "Edit": await RenderView((IGenerableEditView <TE>) generableView, viewDirectory, viewName); break; case "Delete": await RenderView((IGenerableDeleteView <TE>) generableView, viewDirectory, viewName); break; case "ReOrder": await RenderView((IGenerableOrderView <TE>) generableView, viewDirectory, viewName); break; default: throw new NotImplementedException(viewName); } Console.WriteLine($"Generated: {viewDirectory}/{viewName}.cshtml"); }
private string GetViewDirectory(IGenerableView generableView) { var dir = "Views/" + generableView.GetType().Name.Replace("Controller", ""); var assemblyShortName = generableView.GetType().Assembly.GetName().Name; var viewsAndWwwPaths = EnvVarManager.Get("VIEWS_AND_WWW_PATHS"); if (!string.IsNullOrEmpty(viewsAndWwwPaths)) { foreach (var projectDirectory in viewsAndWwwPaths.Split(',', StringSplitOptions.RemoveEmptyEntries)) { if (Path.GetFileName(projectDirectory) == assemblyShortName) { dir = Path.Combine(projectDirectory, dir); } } } return(dir); }