Exemplo n.º 1
0
        private static void GenViewXamlCode(IEnumerable <TableSetting> tableSettings, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tableSettings)
            {
                results.Add(table.TableName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ViewXamlTemplateFileName)))
            {
                foreach (var table in tableSettings)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<DataGridColumns>")
                    {
                        result.Append(DataGridColumns(table.ColumnSettings.OrderBy(p => p.Order), baseTab));
                    }
                    else
                    {
                        result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ViewXamlFileNameSubFix, "Complex" + ViewXamlFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ViewXamlFileNameSubFix), result.Value.ToString());
            }
        }
Exemplo n.º 2
0
        private static void GenComplexViewXamlCode(IEnumerable <MasterDetail> complexViews, IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var cv in complexViews)
            {
                results.Add(cv.ViewName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ComplexViewXamlTemplateFileName)))
            {
                foreach (var cv in complexViews)
                {
                    var result = results[cv.ViewName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<GridContent>")
                    {
                        result.Append(GridContent(cv, tables, baseTab));
                    }
                    else
                    {
                        result.AppendLineEx(line.Replace("<ViewName>", cv.ViewName));
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ComplexViewXamlFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ComplexViewXamlFileNameSubFix), result.Value.ToString());
            }
        }
Exemplo n.º 3
0
        public static void GenViewCode(IEnumerable <TableSetting> tableSettings, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tableSettings)
            {
                results.Add(table.TableName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ViewTemplateFileName)))
            {
                foreach (var table in tableSettings)
                {
                    var result = results[table.TableName];

                    result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ViewFileNameSubFix, "Complex" + ViewFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ViewFileNameSubFix), result.Value.ToString());
            }

            GenViewXamlCode(tableSettings, outputPath);
        }
        public static void GenAngular2TestGenTS(IEnumerable <TableSetting> tables, string outputPath)
        {
            var result = new StringBuilder();

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, Angular2TestGenTemplate)))
            {
                var trimmedEnd = line.TrimEnd();
                var trimmed    = trimmedEnd.TrimStart();
                var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);

                if (trimmed == "<NgSwitchCases>")
                {
                    result.Append(NgSwitchCases(tables, baseTab));
                }
                else if (trimmed == "<DeclareItems>")
                {
                    result.Append(DeclareItems(tables, baseTab));
                }
                else
                {
                    result.AppendLineEx(line);
                }
            }

            FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, "test-gen.component.ts"), result.ToString());
        }
Exemplo n.º 5
0
        public static void GenComplexViewCode(IEnumerable <MasterDetail> complexViews, IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var cv in complexViews)
            {
                results.Add(cv.ViewName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ComplexViewTemplateFileName)))
            {
                foreach (var cv in complexViews)
                {
                    var result = results[cv.ViewName];

                    result.AppendLineEx(line.Replace("<ViewName>", cv.ViewName));
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ComplexViewFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ComplexViewFileNameSubFix), result.Value.ToString());
            }

            GenComplexViewXamlCode(complexViews, tables, outputPath);
        }
        private static void GenEntitiesClass(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, EntityTemplateTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<InitEntityCollectionNavigationProperties>")
                    {
                        result.Append(InitEntityCollectionNavigationProperties(table.DbTable.ReferencesToThisTable, baseTab));
                    }
                    else if (trimmed == "<EntityProperties>")
                    {
                        result.Append(EntityProperties(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<EntityNavigationProperties>")
                    {
                        result.Append(EntityNavigationProperties(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<EntityCollectionNavigationProperties>")
                    {
                        result.Append(EntityCollectionNavigationProperties(table.DbTable.ReferencesToThisTable, baseTab));
                    }
                    else
                    {
                        if (table.TableName == "SmtUser")
                        {
                            result.AppendLineEx(line.Replace("IEntity", "IUser").Replace("<EntityName>", table.TableName));
                        }
                        else if (table.TableName == "SmtTenant")
                        {
                            result.AppendLineEx(line.Replace("IEntity", "ITenant").Replace("<EntityName>", table.TableName));
                        }
                        else if (table.TableName == "SmtUserClaim")
                        {
                            result.AppendLineEx(line.Replace("IEntity", "IUserClaim").Replace("<EntityName>", table.TableName));
                        }
                        else
                        {
                            result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                        }
                    }
                }
            }

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + FileNameSubFix), result.Value.ToString());
            }
        }
        public static void GenAngular2IndexTS(IEnumerable <TableSetting> tables, string outputPath)
        {
            var result = new StringBuilder();

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, Angular2IndexTemplate)))
            {
                var trimmedEnd = line.TrimEnd();
                var trimmed    = trimmedEnd.TrimStart();
                var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);

                if (trimmed == "<Imports>")
                {
                    result.Append(Imports(tables, baseTab));
                }
                else if (trimmed == "<Exports>")
                {
                    result.Append(Exports(tables, baseTab));
                }
                else if (trimmed == "<Declarations_exports>")
                {
                    result.Append(Declarations_exports(tables, baseTab));
                }
                else
                {
                    result.AppendLineEx(line);
                }
            }

            FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, "index.ts"), result.ToString());
        }
        //private const string ControllerPartTemplateFileName = "#ControllerPartTemplate.txt";
        //private const string ControllerPartFileNameSubFix = "Controller.part.cs";

        public static void GenControllersClass(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ControllerTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<InitDtoProperties>")
                    {
                        result.Append(InitDtoProperties(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<InitEntityProperties>")
                    {
                        result.Append(InitEntityProperties(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<OverrideUpdateEntityEFCore>")
                    {
                        result.Append(OverrideUpdateEntityEFCore(table, baseTab));
                    }
                    else if (trimmed == "<OverrideUpdateEntityEFFull>")
                    {
                        result.Append(OverrideUpdateEntityEFFull(table, baseTab));
                    }
                    else
                    {
                        result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ControllerFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ControllerFileNameSubFix), result.Value.ToString());
            }

            //GenControllersPartialClass(tables, outputPath);
        }
        public static void GenDbContextAndEntitiesClass(IEnumerable <TableSetting> tables, string outputPath)
        {
            var result = new StringBuilder();

            result.AppendLineEx("//user tepmlate tag <ModelBuilderConfigEFFull> to generate context class for EF Full, <ModelBuilderConfigEFCore> to generate context class for EF Core.");
            var classKeyword = " class ";
            var contextName  = "";

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, DbContextTemplateFileName)))
            {
                var indexOfClass = line.IndexOf(classKeyword);
                if (indexOfClass != -1)
                {
                    var afterClassKeywordIndex = indexOfClass + classKeyword.Length;
                    var nextSpaceIndex         = line.IndexOf(' ', afterClassKeywordIndex);
                    contextName = line.Substring(afterClassKeywordIndex, nextSpaceIndex - afterClassKeywordIndex);
                    result.AppendLineEx(line);
                    continue;
                }

                var trimmedEnd = line.TrimEnd();
                var trimmed    = trimmedEnd.TrimStart();
                var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                if (trimmed == "<ModelBuilderConfigEFCore>")
                {
                    result.Append(ModelBuilderConfigEFCore(tables, baseTab));
                }
                else if (trimmed == "<ModelBuilderConfigEFFull>")
                {
                    result.Append(ModelBuilderConfigEFFull(tables, baseTab));
                }
                else if (trimmed == "<DbSetProperties>")
                {
                    result.Append(DbSetProperties(tables, baseTab));
                }
                else
                {
                    result.AppendLineEx(line);
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, FileNameSubFix);

            FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, contextName + FileNameSubFix), result.ToString());

            GenEntitiesClass(tables, outputPath);
        }
Exemplo n.º 10
0
        public static void GenDtosClass(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, DtoTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<PublicProperties>")
                    {
                        result.Append(PublicProperties(table.ColumnSettings, baseTab));
                    }
                    else
                    {
                        if (table.TableName == "SmtUser")
                        {
                            result.AppendLineEx(line.Replace("IDto", "IUserDto").Replace("<EntityName>", table.TableName));
                        }
                        else if (table.TableName == "SmtUserClaim")
                        {
                            result.AppendLineEx(line.Replace("IDto", "IUserClaimDto").Replace("<EntityName>", table.TableName));
                        }
                        else
                        {
                            result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                        }
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, DtoFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + DtoFileNameSubFix), result.Value.ToString());
            }
        }
        public static void GenAngular2ComponentTS(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, Angular2TSTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);

                    var columnSettings = table.ColumnSettings;
                    if (trimmed == "<DeclareReferenceDataSource>")
                    {
                        result.Append(DeclareReferenceDataSource(columnSettings, baseTab));
                    }
                    else if (trimmed == "<LoadReferenceDatas>")
                    {
                        result.Append(LoadReferenceDatas(columnSettings, baseTab));
                    }
                    else if (trimmed == "<SetReferenceDataSource>")
                    {
                        result.Append(SetReferenceDataSource(columnSettings, baseTab));
                    }
                    else
                    {
                        result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, Angular2TSFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + Angular2TSFileNameSubFix), result.Value.ToString());
            }
        }
Exemplo n.º 12
0
        public static void GenTextManagerCode(IEnumerable <TableSetting> tables, string outputPath)
        {
            var result       = new StringBuilder();
            var classKeyword = " class ";
            var className    = "";

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, TextManagerTemplateFileName)))
            {
                var indexOfClass = line.IndexOf(classKeyword);
                if (indexOfClass != -1)
                {
                    var afterClassKeywordIndex = indexOfClass + classKeyword.Length;
                    var nextSpaceIndex         = line.IndexOf(' ', afterClassKeywordIndex);
                    if (nextSpaceIndex == -1)
                    {
                        className = line.Substring(afterClassKeywordIndex);
                    }
                    else
                    {
                        className = line.Substring(afterClassKeywordIndex, nextSpaceIndex - afterClassKeywordIndex);
                    }
                    result.AppendLineEx(line);
                    continue;
                }

                var trimmedEnd = line.TrimEnd();
                var trimmed    = trimmedEnd.TrimStart();
                var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                if (trimmed == "<TextStaticProperties>")
                {
                    result.Append(TextStaticProperties(tables, baseTab));
                }
                else if (trimmed == "<InitDefaultTextData>")
                {
                    result.Append(InitDefaultTextData(tables, baseTab));
                }
                else
                {
                    result.AppendLineEx(line);
                }
            }

            FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, className + TextManagerFileNameSubFix), result.ToString());
        }
        public static void GenDataModelClass(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }

            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, DataModelTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);

                    var columnSettings = table.ColumnSettings.Where(p => IsSkippedProperty(p.GetColumnNameForCodeGen()) == false);
                    if (trimmed == "<DefaultValues>")
                    {
                        result.Append(DefaultValues(columnSettings, baseTab));
                    }
                    else if (trimmed == "<PrivateFields>")
                    {
                        result.Append(PrivateFields(columnSettings, baseTab));
                    }
                    else if (trimmed == "<PublicProperties>")
                    {
                        result.Append(PublicProperties(columnSettings, baseTab));
                    }
                    else if (trimmed == "<SetCurrentValueAsOriginalValue>")
                    {
                        result.Append(SetCurrentValueAsOriginalValue(columnSettings, baseTab));
                    }
                    else if (trimmed == "<Update>")
                    {
                        result.Append(Update(columnSettings, baseTab));
                    }
                    else if (trimmed == "<HasChange>")
                    {
                        result.Append(HasChange(columnSettings, baseTab));
                    }
                    else if (trimmed == "<ForeignKeyDataModel>")
                    {
                        result.Append(ForeignKeyDataModel(columnSettings, baseTab));
                    }
                    else if (trimmed == "<ReferenceDataSource>")
                    {
                        result.Append(ReferenceDataSource(columnSettings, baseTab));
                    }
                    else if (trimmed == "<ToDto>")
                    {
                        result.Append(ToDto(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<FromDto>")
                    {
                        result.Append(FromDto(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<SetPropertiesDependency>")
                    {
                        result.Append(SetPropertiesDependency(table.DisplayTextColumn, baseTab));
                    }
                    else if (trimmed == "<DisplayText>")
                    {
                        result.Append(DisplayText(table.DisplayTextColumn, baseTab));
                    }
                    else
                    {
                        if (table.TableName == "SmtUser")
                        {
                            result.AppendLineEx(line.Replace("IDto", "IUserDto").Replace("<EntityName>", table.TableName));
                        }
                        else if (table.TableName == "SmtUserClaim")
                        {
                            result.AppendLineEx(line.Replace("IDto", "IUserClaimDto").Replace("<EntityName>", table.TableName));
                        }
                        else
                        {
                            result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                        }
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, DataModelFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + DataModelFileNameSubFix), result.Value.ToString());
            }
        }
        public static void GenViewModelCode(IEnumerable <TableSetting> tables, string outputPath)
        {
            var results = new Dictionary <string, StringBuilder>();

            foreach (var table in tables)
            {
                results.Add(table.TableName, new StringBuilder());
            }
            foreach (var line in System.IO.File.ReadLines(System.IO.Path.Combine(outputPath, ViewModelTemplateFileName)))
            {
                foreach (var table in tables)
                {
                    var result = results[table.TableName];

                    var trimmedEnd = line.TrimEnd();
                    var trimmed    = trimmedEnd.TrimStart();
                    var baseTab    = trimmedEnd.Substring(0, trimmedEnd.Length - trimmed.Length);
                    if (trimmed == "<DeclareHeaderFilters>")
                    {
                        result.Append(DeclareHeaderFilters(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<DeclareNavigationDictionaries>")
                    {
                        result.Append(DeclareNavigationDictionaries(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<InitHeaderFilters>")
                    {
                        result.Append(InitHeaderFilters(table.ColumnSettings, table.TableName, baseTab));
                    }
                    else if (trimmed == "<AddHeaderFiltersToHeaderFilterCollection>")
                    {
                        result.Append(AddHeaderFiltersToHeaderFilterCollection(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<AfterLoad>")
                    {
                        result.Append(AfterLoad(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<LoadReferenceDatas>")
                    {
                        result.Append(LoadReferenceDatas(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<SetDataModelsReferenceDataSource>")
                    {
                        result.Append(SetDataModelsReferenceDataSource(table.ColumnSettings, baseTab));
                    }
                    else if (trimmed == "<SetDataModelsDefaultValue>")
                    {
                        result.Append(SetDataModelsDefaultValue(table.ColumnSettings, baseTab));
                    }
                    else
                    {
                        result.AppendLineEx(line.Replace("<EntityName>", table.TableName));
                    }
                }
            }

            FileUtils.DeleteAllFileEndWith(outputPath, ViewModelFileNameSubFix);

            foreach (var result in results)
            {
                FileUtils.WriteAllTextInUTF8(System.IO.Path.Combine(outputPath, result.Key + ViewModelFileNameSubFix), result.Value.ToString());
            }
        }