public async Task <CodeComponentFile> GenerateDomainModelMultilanguage(CodeModelVariable variable, CodeModel model) { if (variable == null || model == null) { throw new ArgumentNullException(); } return(await Task.Run(() => { var className = model.Name + variable.Name; var sb = new StringBuilder(domainModelMultilanguageUsings); sb.AppendLine(); sb.AppendLine(); sb.AppendLine($"namespace {GetDomainModelNamespace(model.Namespace, model.SubNamespace)}"); sb.AppendLine("{"); sb.Append($"{GenerateSummary($"Localized {model.Name} {variable.Name}", 1)}"); sb.AppendLine($"{identation}public sealed class {className} : EntityLocaleResource<long, {model.Name}>"); sb.AppendLine($"{identation}{{"); sb.AppendLine($"{identation}}}"); sb.AppendLine("}"); return new CodeComponentFile(sb.ToString(), className); }) .ConfigureAwait(false)); }
private CodeModel TabToModelAisTemplater() { var variables = new HashSet <CodeModelVariable>(); //Loop through each row and form variable script values foreach (DataGridViewRow row in AisTemplaterGrid.Rows) { variables.Add( CodeModelVariable.CreateNew( GetCellValue <string>(row, templaterVariableAccessLevel), GetCellValue <string>(row, templaterVariableName), GetCellValue <string>(row, templaterAisVariableType), GetCellValue <string>(row, templaterAisVariableComment), GetCellValueInt(row, templaterAisVariableStringLength), GetCellValueBool(row, templaterAisVariableIsRequired), GetCellValueBool(row, templaterAisVariableIsPartOfUpdate), GetCellValueBool(row, templaterAisVariableIsPartOfCreateNew), GetCellValueBool(row, templaterAisVariableIsMultilanguage) )); } var model = CodeModel.CreateNew(AisTemplaterModelNameTextBox.Text, AisTemplaterNamespaceTextBox.Text, AisTemplaterClassSummaryTextBox.Text, AisTemplaterAggregateRootCheckBox.Checked, AisTemplaterIsUserManagedCheckBox.Checked, AisTemplaterIsValidityRangeCheckBox.Checked, variables, AisTemplaterContextTextBox.Text, AisTemplaterSubNamespaceTextBox.Text); aisModel = model; return(model); }
private string GenerateVariableConfigurationDefinition(CodeModelVariable variable, int identationCount) { var localIdentation = GenerateIdentation(identationCount); var sb = new StringBuilder(); sb.Append($"{localIdentation}c.Property(e => e.{variable.Name})"); if (variable.IsRequired) { sb.Append(".IsRequired()"); } if (variable.LengthConstraint.HasValue && variable.LengthConstraint > 0 && variable.Type.ToLower() == "string") { sb.Append($".HasMaxLength({variable.LengthConstraint})"); } sb.Append(";"); return(sb.ToString()); }
private string GenerateMultilanguageVariableDefinition(CodeModelVariable variable, string modelName, bool isDomain, int identationCount) { var localIdentation = GenerateIdentation(identationCount); var localizedVariableName = $"{modelName}{variable.Name}"; var sb = new StringBuilder(); if (!isDomain) { sb.Append(GenerateSummary($"Localized {variable.Name.FirstCharToLower()}", identationCount)); sb.AppendLine($"{localIdentation}public IEnumerable<{localizedVariableName}> {variable.Name} {{ get; private set; }} = Enumerable.Empty<{localizedVariableName}>();"); } else { var summary = GenerateSummary($"Set of {variable.Name.FirstCharToLower()} in all supported languages", identationCount); sb.Append(summary); sb.AppendLine($"{localIdentation}private HashSet<{localizedVariableName}> _{variable.Name} = new HashSet<{localizedVariableName}>();"); sb.Append(summary); sb.AppendLine($"{localIdentation}public IEnumerable<{localizedVariableName}> {variable.Name} {{ get; private set; }} => _{variable.Name};"); } return(sb.ToString()); }
public async Task <CodeComponentFile> GenerateAPIModelMultilanguage(CodeModelVariable variable, CodeModel model) { if (variable == null || model == null) { throw new ArgumentNullException(); } return(await Task.Run(() => { var className = model.Name + variable.Name; var identation2 = GenerateIdentation(2); var sb = new StringBuilder(domainModelMultilanguageUsings); sb.AppendLine(); sb.AppendLine(); sb.AppendLine($"namespace {GetDomainModelNamespace(model.Namespace, model.SubNamespace)}"); sb.AppendLine("{"); sb.Append($"{GenerateSummary($"Localized {model.Name} {variable.Name}", 1)}"); sb.AppendLine($"{identation}[WebForm]"); sb.AppendLine($"{identation}public class {className} : ILocaleResource"); sb.AppendLine($"{identation}{{"); sb.Append(GenerateSummary($"{variable.Name} locale", 2)); sb.AppendLine($"{identation2}[EnumDataType(typeof(Locale))]"); sb.AppendLine($"{identation2}public Locale Locale {{ get; set; }}"); sb.AppendLine(); sb.Append(GenerateSummary($"{variable.Name} value", 2)); if (variable.LengthConstraint.HasValue && variable.Type.ToLower() == "string") { sb.AppendLine($"{identation2}[StringLength({variable.LengthConstraint.Value})]"); } sb.AppendLine($"{identation2}public string Value {{ get; set; }}"); sb.AppendLine($"{identation}}}"); sb.AppendLine("}"); return new CodeComponentFile(sb.ToString(), className); }) .ConfigureAwait(false)); }
private string GenerateVariableDefinition(CodeModelVariable variable, bool isDomain, int identationCount) { var sb = new StringBuilder(); var localIdentation = GenerateIdentation(identationCount); sb.Append(GenerateSummary(variable.Summary, identationCount)); if (!isDomain) { if (variable.LengthConstraint.HasValue && variable.Type.ToLower() == "string") { sb.AppendLine($"{localIdentation}[StringLength({variable.LengthConstraint.Value})]"); } if (variable.IsRequired) { sb.AppendLine($"{localIdentation}[Required]"); } } sb.AppendLine($"{localIdentation}{variable.AccessLevel} {variable.Type} {variable.Name} {{ get; private set; }}"); return(sb.ToString()); }
public async Task <CodeComponentFile> GenerateEntityTypeConfigurationMultilanguage(CodeModelVariable variable, CodeModel model) { if (variable == null || model == null) { throw new ArgumentNullException(); } return(await Task.Run(() => { var fullName = model.Name + variable.Name; var className = fullName + "EntityTypeConfiguration"; var identation2 = GenerateIdentation(2); var identation3 = GenerateIdentation(3); var sb = new StringBuilder(entityConfigurationUsings); sb.AppendLine(); sb.AppendLine($"using {GetDomainModelNamespace(model.Namespace, model.SubNamespace)}"); sb.AppendLine(); sb.AppendLine($"namespace {GetEntityConfigurationNamespace(model.Namespace)}"); sb.AppendLine("{"); sb.AppendLine($"{identation}internal class {className} : IEntityTypeConfiguration<{fullName}>"); sb.AppendLine($"{identation}{{"); sb.AppendLine($"{identation2}public void Configure(EntityTypeBuilder<{fullName}> c)"); sb.AppendLine($"{identation2}{{"); sb.AppendLine($"{identation3}c.ToTable(\"{fullName}\", {model.ContextName}.DefaultSchema)"); sb.AppendLine($"{identation3}c.HasKey(e => new {{ e.EntityId, e.Locale }});"); sb.AppendLine($"{identation3}c.Property(f => f.Value)"); if (variable.LengthConstraint.HasValue && variable.LengthConstraint > 0 && variable.Type.ToLower() == "string") { sb.Append($".HasMaxLength({variable.LengthConstraint})"); } sb.Append(";"); sb.AppendLine($"{identation2}}}"); sb.AppendLine($"{identation}}}"); sb.AppendLine("}"); return new CodeComponentFile(sb.ToString(), className); }) .ConfigureAwait(false)); }