diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-23 20:15:36 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-23 20:15:36 +0200 |
| commit | 17612c08da93c75d4c941a643bc7602c18f351d8 (patch) | |
| tree | 7fb879ef52d5460149b199f752279c3889cb5271 /Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI | |
| parent | d7c8a8e9a6320ade6098e0d8e182c7ada4e30a97 (diff) | |
| download | Tango-17612c08da93c75d4c941a643bc7602c18f351d8.tar.gz Tango-17612c08da93c75d4c941a643bc7602c18f351d8.zip | |
Implemented auto DTO generation.
Implemented mapping of DTO <=> Observables.
Organization of unit tests.
Removed DELETED from ADDRESS & CONTACT.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs b/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs index 51b619b46..a8181dea8 100644 --- a/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs +++ b/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs @@ -44,7 +44,7 @@ namespace Tango.DBObservablesGenerator.CLI foreign_keys = Core.Components.DataBaseDescriptionsHelper.GetForeignKeys(db.Database.Connection); } - //Generate Entities... + //Generate Entities and DTOs... foreach (var table in typeof(RemoteDB).GetProperties().Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType))) { Console.WriteLine("Generating table '" + table + "'..."); @@ -64,6 +64,12 @@ namespace Tango.DBObservablesGenerator.CLI Description = table_description, }; + EntityDTOCodeFile dtoCodeBase = new EntityDTOCodeFile(); + dtoCodeBase.Name = codeFile.Name.Replace("Base", "DTOBase"); + dtoCodeBase.Description = codeFile.Description; + dtoCodeBase.ObservableType = codeFile.Name.Replace("Base", ""); + dtoCodeBase.InheritedType = dtoCodeBase.Name.Replace("Base", ""); + List<String> guessed_keys = table.PropertyType.GenericTypeArguments.First().GetProperties().Skip(3).Where(x => x.PropertyType == typeof(String)).Where(x => x.Name.ToLower().Contains("guid")).Select(x => DalNameToStandardName(x.Name).SingularizeMVC().Replace("Guid", "")).OrderBy(x => x).ToList(); List<String> foreignKeys = foreign_keys.Where(x => x.TableName == table.Name).Select(x => DalNameToStandardName(x.ColumnName).SingularizeMVC().Replace("Guid", "")).OrderBy(x => x).ToList(); @@ -159,6 +165,16 @@ namespace Tango.DBObservablesGenerator.CLI } } codeFile.Fields.Add(codeField); + + if (field.PropertyType.IsPrimitive || field.PropertyType.IsValueType || field.PropertyType == typeof(String)) + { + dtoCodeBase.Properties.Add(new Property() + { + Type = codeField.Type, + Name = codeField.Name, + Description = codeField.Description, + }); + } } String code = codeFile.GenerateCode(); @@ -173,6 +189,23 @@ namespace Tango.DBObservablesGenerator.CLI String inheritedCode = inherited.GenerateCode(); File.WriteAllText(Path.Combine(entitiesPath, inherited.Name + ".cs"), inheritedCode); } + + if (dtoCodeBase.Name != "SysdiagramDTOBase") + { + String dtoCode = dtoCodeBase.GenerateCode(); + String dtoPath = Path.Combine(targetPath, "DTO"); + Directory.CreateDirectory(dtoPath); + File.WriteAllText(Path.Combine(dtoPath, dtoCodeBase.Name + ".cs"), dtoCode); + + String inheritedName = dtoCodeBase.Name.Replace("Base", ""); + + if (!File.Exists(Path.Combine(dtoPath, inheritedName + ".cs"))) + { + EntityInheritedDTOCodeFile inherited = new EntityInheritedDTOCodeFile(inheritedName, dtoCodeBase.Name); + String inheritedCode = inherited.GenerateCode(); + File.WriteAllText(Path.Combine(dtoPath, inherited.Name + ".cs"), inheritedCode); + } + } } //Generate Entities... @@ -220,7 +253,7 @@ namespace Tango.DBObservablesGenerator.CLI } catch (Exception ex) { - + } } } |
