Пример #1
0
        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.IndexOf("..") >= 0 ||
                        templateKey.StartsWith("\\") ||
                        templateKey.StartsWith("//"))
                    {
                        throw new ArgumentOutOfRangeException("templateFile");
                    }

                    var outputFile = pair.Value;
                    if (outputFile.IndexOf("..") >= 0 ||
                        outputFile.StartsWith("\\") ||
                        outputFile.StartsWith("//"))
                    {
                        throw new ArgumentOutOfRangeException("outputFile");
                    }

                    outputFile = String.Format(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);
                    }
                }
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        private void GenerateStyle()
        {
#if ASPNETCORE
            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 => (x ?? "").ToLowerInvariant().IsTrimmedSame(importLine)))
                    {
                        var index = lines.FindLastIndex(x =>
                        {
                            return(x.StartsWith("@import") ||
                                   (x.StartsWith("//") && x.Contains("if:")));
                        });

                        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", "").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);
                }
            }
        }
Пример #4
0
 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"))));
 }
Пример #5
0
 private void GenerateScriptGridSS()
 {
     CreateNewSiteScriptFile(Templates.Render(new Views.EntityScriptGridSS(), model),
                             Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.ClassName + "Grid.cs")));
 }
Пример #6
0
 private void GenerateRow()
 {
     CreateNewSiteWebFile(Templates.Render(GeneratorConfig.GetEntityRowView(config), model),
                          Path.Combine(@"Modules\", Path.Combine(model.Module ?? model.RootNamespace, Path.Combine(model.ClassName, model.RowClassName + ".cs"))));
 }
Пример #7
0
        public void Run()
        {
            if (config.GenerateRow)
            {
                CreateFile(Templates.Render("Row", model), moduleClass + "Row.cs");
                CreateFile(Templates.Render("RowTyping", model), typingClass + "Row.ts");
            }

            if (config.GenerateService)
            {
                var handlerClass = Path.Combine(modulePath,
                                                Path.Combine(model.ClassName, "RequestHandlers", model.ClassName));
                CreateFile(Templates.Render("DeleteHandler", model), handlerClass + "DeleteHandler.cs");
                CreateFile(Templates.Render("ListHandler", model), handlerClass + "ListHandler.cs");
                CreateFile(Templates.Render("RetrieveHandler", model), handlerClass + "RetrieveHandler.cs");
                CreateFile(Templates.Render("SaveHandler", model), handlerClass + "SaveHandler.cs");

                CreateFile(Templates.Render("Endpoint", model), moduleClass + "Endpoint.cs");
                CreateFile(Templates.Render("ServiceTyping", model), typingClass + "Service.ts");
            }

            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");
                CreateFile(Templates.Render("ColumnsTyping", model), typingClass + "Columns.ts");

                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"))));
 }