public static string Generate(IDbConnection connection, string tableSchema, string table, string module, string connectionKey, string entityClass, string permission, GeneratorConfig config) { var model = GenerateModel(connection, tableSchema, table, module, connectionKey, entityClass, permission, config); return(Templates.Render(GeneratorConfig.GetEntityRowView(config), model)); }
private void GenerateCss() { string relativeFile = Path.Combine(@"Content\site\", "site.less"); string file = Path.Combine(siteWebPath, relativeFile); Directory.CreateDirectory(Path.GetDirectoryName(file)); if (!File.Exists(file)) { CodeFileHelper.CheckoutAndWrite(file, "\r\n", false); } string code = Templates.Render(new Views.EntityCss(), model); using (var ms = new MemoryStream()) { var old = File.ReadAllBytes(file); if (old.Length > 0) { ms.Write(old, 0, old.Length); } using (var sw = new StreamWriter(ms, utf8)) { AppendComment(sw); sw.Write(code); sw.Flush(); CodeFileHelper.CheckoutAndWrite(file, ms.ToArray(), false); } } ProjectFileHelper.AddFileToProject(siteWebProj, relativeFile); }
private void GenerateRepository() { CreateNewSiteWebFile(Templates.Render(new Views.EntityRepository(), new { RootNamespace = model.RootNamespace, ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, Permission = model.Permission }), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Repository.cs")))); }
/*private void GenerateCss() * { * string relativeFile = Path.Combine(@"Content\site\", "site.module." + model.Module.ToLowerInvariant() + ".less"); * string file = Path.Combine(siteWebPath, relativeFile); * Directory.CreateDirectory(Path.GetDirectoryName(file)); * if (!File.Exists(file)) * using (var sw = new StreamWriter(file, false, utf8)) * sw.Write("\r\n"); * * string code = Templates.Render("EntityCss", model); * using (var sw = new StreamWriter(file, true, utf8)) * { * AppendComment(sw); * sw.Write(code); * } * * AddFileToProject(siteWebProj, relativeFile); * }*/ private void GenerateForm() { CreateNewSiteWebFile(Templates.Render(new Views.EntityForm(), new { ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, RootNamespace = model.RootNamespace, Fields = model.Fields, IdField = model.Identity }), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Form.cs")))); }
private void GenerateEndpoint() { CreateNewSiteWebFile(Templates.Render(new Views.EntityEndpoint(), new { ConnectionKey = model.ConnectionKey, RootNamespace = model.RootNamespace, ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, Permission = model.Permission }), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Endpoint.cs")))); }
private void GenerateColumns() { CreateNewSiteWebFile(Templates.Render(new Views.EntityColumns(), new { ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, RootNamespace = model.RootNamespace, Fields = model.Fields, IdField = model.Identity, NameField = model.NameField }), Path.Combine(modules, Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Columns.cs")))); }
private void GeneratePageController() { CreateNewSiteWebFile(Templates.Render(new Views.EntityPageController(), new { Schema = model.Schema, RootNamespace = model.RootNamespace, ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, Permission = model.Permission, NavigationCategory = model.Module }), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Page.cs")))); }
private void GenerateRow() { if (config.RowFieldsSurroundWithRegion) { CreateNewSiteWebFile(Templates.Render(GeneratorConfig.GetEntityRowView(config), model, config), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.RowClassName + ".cs")))); } else { CreateNewSiteWebFile(Templates.Render(GeneratorConfig.GetEntityRowView(config), model), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.RowClassName + ".cs")))); } }
private void GeneratePageIndex() { CreateNewSiteWebFile(Templates.Render(new Views.EntityPageIndex(), new { ConnectionKey = model.ConnectionKey, RootNamespace = model.RootNamespace, ClassName = model.ClassName, RowClassName = model.RowClassName, Module = model.Module, Permission = model.Permission, NavigationCategory = model.Module }), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Index.cshtml")))); }
public static string Generate(IDbConnection connection, string tableSchema, string table, string module, string connectionKey, string entityClass, string permission, GeneratorConfig config) { var model = GenerateModel(connection, tableSchema, table, module, connectionKey, entityClass, permission, config); if (config.RowFieldsSurroundWithRegion) { return(Templates.Render(new Views.EntityRowWithRegion(), model, config)); } else { return(Templates.Render(new Views.EntityRow(), model)); } }
private void GenerateScriptFormTS() { var targetFile = model.ClassName + "Form.ts"; if (model.Module != null) { targetFile = model.Module + "." + targetFile; } targetFile = Path.Combine(Path.GetDirectoryName(serverTypings), targetFile); var content = Templates.Render(new Views.EntityScriptFormTS(), model); CreateNewSiteWebFile(content, targetFile, serverTypings); }
private void GenerateNavigationLink() { string file = Path.Combine(rootDir, string.IsNullOrEmpty(model.Module) ? "Modules/Common/Navigation/NavigationItems.cs" : "Modules/" + model.ModuleSlash + model.Module + "Navigation.cs"); file = file.Replace('/', Path.DirectorySeparatorChar); string code = Templates.Render("NavigationLink", model); if (!File.Exists(file)) { Directory.CreateDirectory(Path.GetDirectoryName(file)); CreateFile(code, file); } else { var lines = File.ReadAllLines(file).ToList(); var toInsert = code.Replace("\r", "", StringComparison.Ordinal).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); var usingIndex = lines.FindLastIndex(x => x.TrimToEmpty().StartsWith("using ", StringComparison.Ordinal)); if (usingIndex < 0) { usingIndex = 0; } foreach (var usng in toInsert.Where(x => x.TrimToEmpty().StartsWith("using ", StringComparison.Ordinal))) { if (lines.Find(x => x.TrimToEmpty().Replace(" ", "", StringComparison.Ordinal) .IsTrimmedSame(usng.TrimToEmpty().Replace(" ", "", StringComparison.Ordinal))) == null) { lines.Insert(usingIndex, usng); usingIndex++; } } if (!lines.Any(x => x.Contains("MyPages." + model.ClassName + "Controller", StringComparison.Ordinal))) { var insertIndex = lines.FindLastIndex(x => !string.IsNullOrWhiteSpace(x)) + 1; foreach (var z in toInsert.Where(x => !string.IsNullOrWhiteSpace(x) && !x.TrimToEmpty().StartsWith("using ", StringComparison.Ordinal))) { lines.Insert(insertIndex, z); } } CodeFileHelper.CheckoutAndWrite(file, string.Join(Environment.NewLine, lines), false); } }
private void GenerateScriptForm() { var targetFile = model.ClassName + "Form.cs"; if (model.Module != null) { targetFile = model.Module + "." + targetFile; } targetFile = Path.Combine(@"Imports\FormContexts\", targetFile); var content = Templates.Render(new Views.EntityScriptForm(), model); var dependentUpon = @"Imports\FormContext\FormContexts.tt"; CreateNewSiteScriptFile(content, targetFile, dependentUpon); }
private void GenerateScriptFormSS() { var targetFile = model.ClassName + "Form.cs"; if (model.Module != null) { targetFile = model.Module + "." + targetFile; } var dependentUpon = (ScriptFileExists(serverImports) || !ScriptFileExists(formContexts)) ? serverImports : formContexts; targetFile = Path.Combine(Path.GetDirectoryName(dependentUpon), targetFile); var content = Templates.Render(new Views.EntityScriptFormSS(), model); CreateNewSiteScriptFile(content, targetFile, dependentUpon); }
private void GenerateCss() { string relativeFile = Path.Combine(@"Content/site/".Replace('/', Path.DirectorySeparatorChar), "site" + (!string.IsNullOrEmpty(model.Module) ? ("." + model.Module.ToLowerInvariant()) : "") + ".less"); string file = Path.Combine(rootDir, relativeFile); Directory.CreateDirectory(Path.GetDirectoryName(file)); if (!File.Exists(file)) { if (!string.IsNullOrEmpty(model.Module)) { relativeFile = Path.Combine("Content/site/".Replace('/', Path.DirectorySeparatorChar), "site.less"); file = Path.Combine(rootDir, relativeFile); } if (!File.Exists(file)) { CodeFileHelper.CheckoutAndWrite(file, Environment.NewLine, false); } } string code = Templates.Render(new Views.EntityCss(), model); using (var ms = new MemoryStream()) { var old = File.ReadAllBytes(file); if (old.Length > 0) { ms.Write(old, 0, old.Length); } using (var sw = new StreamWriter(ms, utf8)) { sw.Write(code); sw.Flush(); CodeFileHelper.CheckoutAndWrite(file, ms.ToArray(), false); } } }
private void GenerateCss() { string relativeFile = Path.Combine(@"Content\site\", "site.less"); string file = Path.Combine(siteWebPath, relativeFile); Directory.CreateDirectory(Path.GetDirectoryName(file)); if (!File.Exists(file)) { using (var sw = new StreamWriter(file, false, utf8)) sw.Write("\r\n"); } string code = Templates.Render(new Views.EntityCss(), model); using (var sw = new StreamWriter(file, true, utf8)) { AppendComment(sw); sw.Write(code); } ProjectFileHelper.AddFileToProject(siteWebProj, relativeFile); }
public void Run() { Directory.CreateDirectory(Path.GetDirectoryName(rootDir)); if (config.GenerateRow) { CreateFile(Templates.Render("Row", model), moduleClass + "Row.cs"); CreateFile(Templates.Render("RowTyping", model), typingClass + "Row.ts", serverTypingsTT); } if (config.GenerateService) { CreateFile(Templates.Render("Repository", model), moduleClass + "Repository.cs"); CreateFile(Templates.Render("Endpoint", model), moduleClass + "Endpoint.cs"); CreateFile(Templates.Render("ServiceTyping", model), typingClass + "Service.ts", serverTypingsTT); } if (config.GenerateUI) { CreateFile(Templates.Render("Page", model), moduleClass + "Page.cs"); CreateFile(Templates.Render("IndexView", model), moduleClass + "Index.cshtml"); CreateFile(Templates.Render("Columns", model), moduleClass + "Columns.cs"); CreateFile(Templates.Render("Form", model), moduleClass + "Form.cs"); CreateFile(Templates.Render("Dialog", model), moduleClass + "Dialog.ts"); CreateFile(Templates.Render("Grid", model), moduleClass + "Grid.ts"); CreateFile(Templates.Render("FormTyping", model), typingClass + "Form.ts", serverTypingsTT); GenerateNavigationLink(); GenerateStyle(); } if (config.CustomGenerate != null && config.GenerateCustom) { foreach (var pair in config.CustomGenerate) { if (string.IsNullOrEmpty(pair.Value)) { continue; } var templateKey = pair.Key; if (templateKey.Contains("..", StringComparison.Ordinal) || templateKey.StartsWith("\\", StringComparison.Ordinal) || templateKey.StartsWith("//", StringComparison.Ordinal)) { throw new ArgumentOutOfRangeException("templateFile"); } var outputFile = pair.Value; if (outputFile.Contains("..", StringComparison.Ordinal) || outputFile.StartsWith("\\", StringComparison.Ordinal) || outputFile.StartsWith("//", StringComparison.Ordinal)) { throw new ArgumentOutOfRangeException("outputFile"); } outputFile = string.Format(CultureInfo.InvariantCulture, outputFile, model.ClassName, model.Module, Path.GetDirectoryName(moduleClass), Path.GetDirectoryName(typingClass), rootDir); var content = Templates.Render(templateKey, model); if (!string.IsNullOrWhiteSpace(content)) { CreateFile(content, outputFile); } } } }
private void GenerateRow() { CreateNewSiteWebFile(Templates.Render(new Views.EntityRow(), model), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.RowClassName + ".cs")))); }
private void GenerateStyle() { #if !ASPNETMVC string contentSite = "wwwroot/Content/site".Replace('/', Path.DirectorySeparatorChar); #else string contentSite = "Content/site".Replace('/', Path.DirectorySeparatorChar); #endif string file = Path.Combine(rootDir, Path.Combine(contentSite, "site" + model.DotModule.ToLowerInvariant() + ".less")); if (!string.IsNullOrEmpty(model.Module)) { var siteLess = Path.Combine(rootDir, Path.Combine(contentSite, "site.less")); if (File.Exists(siteLess)) { var importLine = "@import \"site." + model.Module.ToLowerInvariant() + ".less\";"; var lines = File.ReadAllLines(siteLess).ToList(); if (!lines.Any(x => string.Compare(x ?? "", importLine, StringComparison.OrdinalIgnoreCase) == 0)) { var index = lines.FindLastIndex(x => { return(x.StartsWith("@import", StringComparison.Ordinal) || (x.StartsWith("//", StringComparison.Ordinal) && x.Contains("if:", StringComparison.Ordinal))); }); if (index < 0) { index = lines.Count; } else { index++; } lines.Insert(index, importLine); CodeFileHelper.CheckoutAndWrite(siteLess, string.Join(Environment.NewLine, lines), false); } } } if (!File.Exists(file)) { Directory.CreateDirectory(Path.GetDirectoryName(file)); CreateFile("@import \"site.mixins.less\";" + Environment.NewLine, file); } string code = Templates.Render("Style", model); using (var ms = new MemoryStream()) { var firstLine = code.Replace("\r", "", StringComparison.Ordinal) .Split('\n').FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)); if (!string.IsNullOrWhiteSpace(firstLine)) { var lines = File.ReadAllLines(file); // don't generate less for dialog multiple times if (lines.Any(x => x.IsTrimmedSame(firstLine))) { return; } } var old = File.ReadAllBytes(file); if (old.Length > 0) { ms.Write(old, 0, old.Length); } using (var sw = new StreamWriter(ms, utf8)) { sw.Write(code); sw.Flush(); CodeFileHelper.CheckoutAndWrite(file, ms.ToArray(), false); } } }
private void GenerateScriptDialogTS() { CreateNewSiteWebFile(Templates.Render(new Views.EntityScriptDialogTS(), model), Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Dialog.ts")))); }
private void GenerateScriptGridSS() { CreateNewSiteScriptFile(Templates.Render(new Views.EntityScriptGridSS(), model), Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Grid.cs"))); }
public static string Generate(IDbConnection connection, string tableSchema, string table, string module, string schema, string entityClass, string permission) { var model = GenerateModel(connection, tableSchema, table, module, schema, entityClass, permission); return(Templates.Render(new Views.EntityRow(), model)); }