aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-23 09:34:03 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-23 09:34:03 +0200
commit5bec920df45bb79e5912a97f2d0afc1a849adbd2 (patch)
treea0a4a7b62df4bae64b4fb45760f445baad21f4e4 /Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI
parente0b0859f62924d38c8cd7ac9975303c4bfb08624 (diff)
downloadTango-5bec920df45bb79e5912a97f2d0afc1a849adbd2.tar.gz
Tango-5bec920df45bb79e5912a97f2d0afc1a849adbd2.zip
Fixed some issues with observables generator.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs38
1 files changed, 36 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 e45815046..3a40dfd1f 100644
--- a/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs
+++ b/Software/Visual_Studio/Utilities/Tango.DBObservablesGenerator.CLI/ObservablesGenerator.cs
@@ -16,6 +16,7 @@ using Tango.Core;
using System.Data;
using System.Diagnostics;
using static Tango.Core.Components.DataBaseDescriptionsHelper;
+using System.Threading;
namespace Tango.DBObservablesGenerator.CLI
{
@@ -31,6 +32,7 @@ namespace Tango.DBObservablesGenerator.CLI
public void GenerateCSharp(String targetPath)
{
List<DbDescription> dbDescriptions = new List<DbDescription>();
+ List<ForeignKeyDescription> foreign_keys = new List<ForeignKeyDescription>();
//Get column descriptions...
using (RemoteDB db = new RemoteDB(SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource))
@@ -39,6 +41,7 @@ namespace Tango.DBObservablesGenerator.CLI
db.Database.Connection.Open();
dbDescriptions = Core.Components.DataBaseDescriptionsHelper.GetDescriptions(db.Database.Connection);
+ foreign_keys = Core.Components.DataBaseDescriptionsHelper.GetForeignKeys(db.Database.Connection);
}
//Generate Entities...
@@ -61,7 +64,38 @@ namespace Tango.DBObservablesGenerator.CLI
Description = table_description,
};
- List<String> foreignKeys = 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", "")).ToList();
+ 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();
+
+ String t_name = table.Name;
+
+ if (guessed_keys.Count != foreignKeys.Count)
+ {
+ Console.ForegroundColor = ConsoleColor.Yellow;
+
+ Console.WriteLine($"Specious entry at {table.Name}.");
+ for (int i = 0; i < Math.Max(guessed_keys.Count, foreignKeys.Count); i++)
+ {
+ if (i < guessed_keys.Count)
+ {
+ Console.Write(guessed_keys[i]);
+ }
+
+ Console.Write(" <=> ");
+
+ if (i < foreignKeys.Count)
+ {
+ Console.Write(foreignKeys[i]);
+ }
+
+ Console.WriteLine();
+ }
+
+ Console.ForegroundColor = ConsoleColor.Gray;
+
+ Thread.Sleep(2000);
+ }
foreach (var field in table.PropertyType.GenericTypeArguments.First().GetProperties().Skip(3))
{
@@ -117,7 +151,7 @@ namespace Tango.DBObservablesGenerator.CLI
{
codeField.Type = field.PropertyType.Name;
- if (codeField.Name.EndsWith("Guid"))
+ if (foreignKeys.Contains(codeField.Name.Replace("Guid", "")))
{
codeField.IsForeignKey = true;
codeField.ForeignKeyName = codeField.Name.Replace("Guid", "");