Exemplo n.º 1
0
        private string AddProperty(string file, IPropertyAdditionOptions options, bool forInterface)
        {
            StringEditor stringEditor = new StringEditor(file);

            FindStartingLineForNewProperty(file, options, stringEditor);

            if (!stringEditor.GetLine().Contains("}"))
            {
                stringEditor.Prev();
            }

            if (ContainsProperty(file))
            {
                stringEditor.InsertNewLine();
            }

            if (forInterface)
            {
                stringEditor.InsertLine(BackendDtoInterfacePropertyLine.GetPropertyLine(options));
            }
            else
            {
                stringEditor.InsertLine(BackendDtoPropertyLine.GetPropertyLine(options));
            }

            return(stringEditor.GetText());
        }
Exemplo n.º 2
0
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            // ----------- Creators -----------
            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains($"public static I{options.EntityName} Default()");
            stringEditor.Next(line => line.Trim().Equals("};"));
            stringEditor.InsertLine($"                {options.PropertyName} = {options.EntityName}TestValues.{options.PropertyName}Default,");
            fileData = stringEditor.GetText();

            stringEditor = new StringEditor(fileData);
            stringEditor.NextThatContains($"public static I{options.EntityName} Default2()");
            stringEditor.Next(line => line.Trim().Equals("};"));
            stringEditor.InsertLine($"                {options.PropertyName} = {options.EntityName}TestValues.{options.PropertyName}Default2,");
            fileData = stringEditor.GetText();

            // ----------- Asserts -----------
            stringEditor = new StringEditor(fileData);
            stringEditor.NextThatContains("AssertDefault(");
            stringEditor.Next(line => line.Trim().Equals("}"));
            stringEditor.InsertLine($"            Assert.AreEqual({options.EntityName}TestValues.{options.PropertyName}Default, {options.EntityNameLower}.{options.PropertyName});");
            fileData = stringEditor.GetText();

            stringEditor = new StringEditor(fileData);
            stringEditor.NextThatContains("AssertDefault2(");
            stringEditor.Next(line => line.Trim().Equals("}"));
            stringEditor.InsertLine($"            Assert.AreEqual({options.EntityName}TestValues.{options.PropertyName}Default2, {options.EntityNameLower}.{options.PropertyName});");
            fileData = stringEditor.GetText();

            return(stringEditor.GetText());
        }
Exemplo n.º 3
0
 public PropertyAdditionOptions(IPropertyAdditionOptions options) : base(options)
 {
     this.PropertyType = options.PropertyType;
     this.PropertyName = options.PropertyName;
     this.PropertyTypeExtra = options.PropertyTypeExtra;
     this.IsOptional = options.IsOptional;
 }
Exemplo n.º 4
0
        private string AddProperty(string file, IPropertyAdditionOptions options)
        {
            StringEditor stringEditor = new StringEditor(file);

            FindStartingLineForNewProperty(file, options, stringEditor);

            if (!stringEditor.GetLine().Contains("}"))
            {
                stringEditor.Prev();
            }

            if (ContainsProperty(file))
            {
                stringEditor.InsertNewLine();
            }

            if (!options.IsOptional)
            {
                stringEditor.InsertLine("        [Required]");
            }

            if (options.PropertyType == PropertyTypes.String && options.PropertyTypeExtra != null)
            {
                stringEditor.InsertLine($"        [StringLength({options.PropertyTypeExtra})]");
            }

            stringEditor.InsertLine(BackendDtoPropertyLine.GetPropertyLine(options));

            return(stringEditor.GetText());
        }
        public static string GetPropertyLine(IPropertyAdditionOptions options)
        {
            switch (options.PropertyType)
            {
            case PropertyTypes.Boolean:
                return
                    ($"    <p [attr.aria-label]=\"'{options.PropertyName.ToReadable()}: ' + ({options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}) ? 'aktiv' : 'inaktiv' \">\n" +
                     $"        <span style=\"font-size: 0.8em;\" aria-hidden=\"true\">{options.PropertyName.ToReadable()}:</span>\n" +
                     $"        <br>\n" +
                     $"        <mat-icon color=\"accent\" *ngIf=\"{options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"            check_box\n" +
                     $"        </mat-icon>\n" +
                     $"        <mat-icon style=\"color: gray\" *ngIf=\"!{options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"            check_box_outline_blank\n" +
                     $"        </mat-icon>\n" +
                     "    </p>");

            case PropertyTypes.DateTime:
                return
                    ($"    <p [attr.aria-label]=\"'{options.PropertyName.ToReadable()}: ' + {options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}.toLocaleString()\">\n" +
                     $"        <span style=\"font-size: 0.8em;\" aria-hidden=\"true\">{options.PropertyName.ToReadable()}:</span>\n" +
                     $"        <br>\n" +
                     $"        <span aria-hidden=\"true\">{{{{{options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()} | date:'dd. MMM. yyyy, HH:mm'}}}}</span>\n" +
                     "    </p>");

            default:
                return
                    ($"    <p [attr.aria-label]=\"'{options.PropertyName.ToReadable()}: ' + {options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"        <span style=\"font-size: 0.8em;\" aria-hidden=\"true\">{options.PropertyName.ToReadable()}:</span>\n" +
                     $"        <br>\n" +
                     $"        <span aria-hidden=\"true\">{{{{{options.EntityName.LowerFirstChar()}.{options.PropertyName.LowerFirstChar()}}}}}</span>\n" +
                     "    </p>");
            }
        }
Exemplo n.º 6
0
        public static string GetPropertyLine(IPropertyAdditionOptions options)
        {
            switch (options.PropertyType)
            {
            case PropertyTypes.Boolean:
                return
                    ($"            <ng-container matColumnDef=\"{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"                <th mat-header-cell *matHeaderCellDef mat-sort-header> {options.PropertyName.ToReadable()} </th>\n" +
                     $"                <td mat-cell *matCellDef=\"let element\">\n" +
                     $"                    <mat-icon color=\"accent\" *ngIf=\"element.{options.PropertyName.LowerFirstChar()}\" >\n" +
                     $"                        check_box\n" +
                     $"                    </mat-icon>\n" +
                     $"                    <mat-icon style=\"color: gray\" *ngIf=\"!element.{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"                        check_box_outline_blank\n" +
                     $"                    </mat-icon>\n" +
                     $"                </td>\n" +
                     $"            </ng-container>\n");

            case PropertyTypes.DateTime:
                return
                    ($"            <ng-container matColumnDef=\"{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"                <th mat-header-cell *matHeaderCellDef mat-sort-header> {options.PropertyName.ToReadable()} </th>\n" +
                     $"                <td mat-cell *matCellDef=\"let element\"> {{{{element.{options.PropertyName.LowerFirstChar()} | date:'dd. MMM. yyyy, HH:mm'}}}} </td>\n" +
                     "            </ng-container>\n");

            default:
                return
                    ($"            <ng-container matColumnDef=\"{options.PropertyName.LowerFirstChar()}\">\n" +
                     $"                <th mat-header-cell *matHeaderCellDef mat-sort-header> {options.PropertyName.ToReadable()} </th>\n" +
                     $"                <td mat-cell *matCellDef=\"let element\" > {{{{element.{options.PropertyName.LowerFirstChar()}}}}} </td>\n" +
                     "            </ng-container>\n");
            }
        }
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            StringEditor stringEditor = new StringEditor(fileData);

            // ----------- DbSet -----------

            if (fileData.Contains("</mat-tab-group>"))
            {
                stringEditor.NextThatContains("<mat-tab label=\"Stammdaten\">");
                stringEditor.NextThatContains("</mat-tab>");
            }
            else
            {
                stringEditor.NextThatStartsWith($"<div class=\"{options.EntityName.ToKebab()}-detail-page\"");
                stringEditor.NextThatStartsWith($"</div>");
            }

            stringEditor.InsertNewLine();

            stringEditor.InsertLine(FrontendPageDetailPropertyLine.GetPropertyLine(options));

            return(stringEditor.GetText());
        }
        public static string GetPropertyLine(IPropertyAdditionOptions options)
        {
            string optionalText = (options.IsOptional) ? "?" : "";

            switch (options.PropertyType)
            {
            case PropertyTypes.String:
                return($"        string{optionalText} {options.PropertyName} {{ get; set; }}");

            case PropertyTypes.Integer:
                return($"        int{optionalText} {options.PropertyName} {{ get; set; }}");

            case PropertyTypes.Double:
                return($"        double{optionalText} {options.PropertyName} {{ get; set; }}");

            case PropertyTypes.DateTime:
                return($"        DateTime{optionalText} {options.PropertyName} {{ get; set; }}");

            case PropertyTypes.Boolean:
                return($"        bool{optionalText} {options.PropertyName} {{ get; set; }}");

            case PropertyTypes.Guid:
                return($"        Guid{optionalText} {options.PropertyName} {{ get; set; }}");

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 9
0
        public static string GetPropertyLine(IPropertyAdditionOptions options, string postfix)
        {
            switch (options.PropertyType)
            {
            case PropertyTypes.String:
                return("\"" + options.PropertyName + postfix + "\"");

            case PropertyTypes.Integer:
                return(new Random().Next(100, 999).ToString());

            case PropertyTypes.Double:
                return(new Random().Next(10, 99).ToString() + "." + new Random().Next(0, 99999).ToString());

            case PropertyTypes.Guid:
                return($"Guid.Parse(\"{Guid.NewGuid()}\")");

            case PropertyTypes.Boolean:
                return(postfix.Equals("DbDefault").ToString().ToLower());

            case PropertyTypes.DateTime:
                Random gen        = new Random();
                int    range      = 10 * 365; // 10 years
                var    randomDate = DateTime.Today.AddDays(-gen.Next(range));
                return($"new DateTime({randomDate.Year}, {randomDate.Month}, {randomDate.Day})");

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 10
0
        public void Add(IPropertyAdditionOptions options, string domainFolder, string templateFileName)
        {
            string filePath = GetFilePath(options, domainFolder, templateFileName);
            string fileData = UpdateFileData(options, filePath);

            CsharpClassWriter.Write(filePath, fileData);
        }
Exemplo n.º 11
0
        public void AddProperty(IPropertyAdditionOptions options, string domainFolder, string templateFileName)
        {
            string filePath = GetFilePath(options, domainFolder, templateFileName);
            string fileData = GetFileData(options, filePath);

            File.WriteAllText(filePath, fileData);
        }
Exemplo n.º 12
0
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            // ----------- DbSet -----------
            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains("UpdateEf" + options.EntityName);
            stringEditor.Next(line => line.Trim().Equals("}"));

            stringEditor.InsertLine($"            ef{options.EntityName}.{options.PropertyName} = db{options.EntityName}.{options.PropertyName};");
            fileData = stringEditor.GetText();

            // ----------- DbSet -----------
            stringEditor = new StringEditor(fileData);
            stringEditor.NextThatContains("FromEf" + options.EntityName);
            stringEditor.Next(line => line.Trim().Equals("};"));

            stringEditor.InsertLine($"                {options.PropertyName} = ef{options.EntityName}.{options.PropertyName},");
            fileData = stringEditor.GetText();

            // ----------- DbSet -----------
            stringEditor = new StringEditor(fileData);
            stringEditor.NextThatContains("ToEf" + options.EntityName);
            stringEditor.Next(line => line.Trim().Equals("};"));

            stringEditor.InsertLine($"                {options.PropertyName} = db{options.EntityName}.{options.PropertyName},");

            return(stringEditor.GetText());
        }
Exemplo n.º 13
0
        private string GetFilePath(IPropertyAdditionOptions options, string domainFolder, string templateFileName)
        {
            string absolutePathForDTOs = this.pathService.GetAbsolutePathForFrontendModel(options, domainFolder);
            string fileName            = templateFileName.Replace("entity-kebab", StringConverter.PascalToKebabCase(options.EntityName));
            string filePath            = Path.Combine(absolutePathForDTOs, fileName);

            return(filePath);
        }
Exemplo n.º 14
0
        protected override void AddProperty(IPropertyAdditionOptions options)
        {
            this.frontendDtoPropertyAddition.AddPropertyToDTO(options, ModelProjectGeneration.DomainFolder, FileName);

            this.frontendDtoPropertyMethodAddition.AddPropertyToDTO(options, "toApiEntityUpdate", "iEntityUpdate", ModelProjectGeneration.DomainFolder, FileName);

            this.frontendDtoPropertyMethodAddition.AddPropertyToDTO(options, "fromEntityDetail", "iEntityDetail", ModelProjectGeneration.DomainFolder, FileName);
        }
Exemplo n.º 15
0
        private string GetFilePath(IPropertyAdditionOptions options, string domainFolder, string templateFileName)
        {
            string absolutePathForDTOs = this.pathService.GetAbsolutePathForDTOs(options, domainFolder);
            string fileName            = templateFileName.Replace("Entity", options.EntityName);
            string filePath            = Path.Combine(absolutePathForDTOs, fileName);

            return(filePath);
        }
Exemplo n.º 16
0
        private string AddUsingStatements(IPropertyAdditionOptions options, string fileData)
        {
            if (options.PropertyType == PropertyTypes.Guid || options.PropertyType == PropertyTypes.DateTime)
            {
                fileData = UsingStatements.Add(fileData, "System");
            }

            return(fileData);
        }
Exemplo n.º 17
0
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath, bool forInterface)
        {
            string fileData = File.ReadAllText(filePath);

            fileData = AddUsingStatements(options, fileData);
            fileData = AddProperty(fileData, options, forInterface);

            return(fileData);
        }
        public static string GetPropertyLine(IPropertyAdditionOptions options)
        {
            if (options.PropertyType == PropertyTypes.String)
            {
                return($"    {options.PropertyName.LowerFirstChar()}: '',");
            }

            return($"    {options.PropertyName.LowerFirstChar()}: null,");
        }
Exemplo n.º 19
0
        public void AddPropertyToDTO(IPropertyAdditionOptions options, string domainFolder, string templateFileName, string importStatementTypes, string importStatementPath)
        {
            string filePath = GetFilePath(options, domainFolder, templateFileName);
            string fileData = UpdateFileData(options, filePath);

            fileData = ImportStatements.Add(fileData, importStatementTypes, importStatementPath);

            TypescriptClassWriter.Write(filePath, fileData);
        }
Exemplo n.º 20
0
 public void PerformAddPropertyCommand(IPropertyAdditionOptions options)
 {
     try
     {
         this.AddProperty(options);
     }
     catch (Exception e)
     {
         Console.WriteLine("Fehler bei Property-Generierung: " + e.Message);
     }
 }
Exemplo n.º 21
0
        public void AddProperty(IPropertyAdditionOptions options)
        {
            if (!PropertyAdditionOptions.Validate(options))
            {
                throw new OptionValidationException("Die Optionen sind nicht korrekt formatiert.");
            }

            foreach (ClassGeneration classGeneration in classGenerations)
            {
                classGeneration.PerformAddPropertyCommand(options);
            }
        }
Exemplo n.º 22
0
        public void Add(IPropertyAdditionOptions options)
        {
            if (DatabaseDbContextPropertyLine.GetPropertyLine(options) == null)
            {
                return;
            }

            string filePath = this.pathService.GetAbsolutePathForDbContext(options);
            string fileData = UpdateFileData(options, filePath);

            CsharpClassWriter.Write(filePath, fileData);
        }
Exemplo n.º 23
0
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains("this.formBuilder.group({");
            stringEditor.NextThatContains("});");
            stringEditor.InsertLine(FrontendFormBuilderPropertyLine.GetPropertyLine(options));

            return(stringEditor.GetText());
        }
        public void AddPropertyToDTO(IPropertyAdditionOptions options, string functionName, string variableName, string domainFolder, string fileName)
        {
            functionName = functionName.Replace("Entity", options.EntityName);
            functionName = functionName.Replace("entity", options.EntityName.LowerFirstChar());

            variableName = variableName.Replace("Entity", options.EntityName);
            variableName = variableName.Replace("entity", options.EntityName.LowerFirstChar());

            string filePath = GetFilePath(options, domainFolder, fileName);
            string fileData = UpdateFileData(options, functionName, variableName, filePath);

            TypescriptClassWriter.Write(filePath, fileData);
        }
Exemplo n.º 25
0
        public static bool Validate(IPropertyAdditionOptions options)
        {
            if (!EntityAdditionOptions.Validate(options) ||
               string.IsNullOrEmpty(options.PropertyName) ||
               !options.PropertyName.IsAlpha())
            {
                return false;
            }

            options.PropertyName = options.PropertyName.UpperFirstChar();

            return true;
        }
        private string UpdateFileData(IPropertyAdditionOptions options, string functionName, string variableName, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains($"public static " + functionName);
            stringEditor.NextThatContains("return {");
            stringEditor.NextThatContains("};");

            stringEditor.InsertLine($"            {options.PropertyName.LowerFirstChar()}: {variableName}.{options.PropertyName.LowerFirstChar()},");

            return(stringEditor.GetText());
        }
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            StringEditor stringEditor = new StringEditor(fileData);

            // ----------- DbSet -----------
            stringEditor.NextThatContains("<table mat-table");
            stringEditor.NextThatContains("<ng-container matColumnDef=\"detail\">");

            stringEditor.InsertLine(FrontendPageEntitiesPropertyLine.GetPropertyLine(options));

            return(stringEditor.GetText());
        }
Exemplo n.º 28
0
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            // ----------- Asserts -----------
            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains($"public static I{options.EntityName}Update ForUpdate()");
            stringEditor.Next(line => line.Trim().Equals("};"));
            stringEditor.InsertLine($"                {options.PropertyName} = {options.EntityName}TestValues.{options.PropertyName}ForUpdate,");
            fileData = stringEditor.GetText();

            return(stringEditor.GetText());
        }
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            // ----------- AssertDbDefault -----------
            StringEditor stringEditor = new StringEditor(fileData);

            stringEditor.NextThatContains("AssertDbDefault(");
            stringEditor.Next(line => line.Trim().Equals("}"));

            stringEditor.InsertLine($"            Assert.AreEqual({options.EntityName}TestValues.{options.PropertyName}DbDefault, db{options.EntityName}Detail.{options.PropertyName});");

            return(stringEditor.GetText());
        }
        private string UpdateFileData(IPropertyAdditionOptions options, string filePath)
        {
            string fileData = File.ReadAllText(filePath);

            StringEditor stringEditor = new StringEditor(fileData);

            // ----------- DbSet -----------
            stringEditor.NextThatContains("GridColumns: string[]");
            stringEditor.NextThatContains("'detail'");

            stringEditor.InsertLine($"    '{options.PropertyName.LowerFirstChar()}',");

            return(stringEditor.GetText());
        }