Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions TALXIS.CLI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TALXIS.CLI.IntegrationTests", "tests\TALXIS.CLI.IntegrationTests\TALXIS.CLI.IntegrationTests.csproj", "{EDB2D38C-8601-43BD-AC88-165E822986C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TALXIS.CLI.DataVisualizer", "src\TALXIS.CLI.DataVisualizer\TALXIS.CLI.DataVisualizer.csproj", "{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -101,6 +103,18 @@ Global
{EDB2D38C-8601-43BD-AC88-165E822986C7}.Release|x64.Build.0 = Release|Any CPU
{EDB2D38C-8601-43BD-AC88-165E822986C7}.Release|x86.ActiveCfg = Release|Any CPU
{EDB2D38C-8601-43BD-AC88-165E822986C7}.Release|x86.Build.0 = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|x64.ActiveCfg = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|x64.Build.0 = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|x86.ActiveCfg = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Debug|x86.Build.0 = Debug|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|Any CPU.Build.0 = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|x64.ActiveCfg = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|x64.Build.0 = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|x86.ActiveCfg = Release|Any CPU
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -111,6 +125,7 @@ Global
{047E218E-A6A2-1C66-58E1-AFEF0AD34E7F} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{DFE5EC2E-21E2-42D6-B9C6-3111CE00FD0B} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{0914E284-15E7-4215-B72F-7195F0EB8EEA} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{AFF26BEA-6C69-7440-9F51-7C0E8F3CDBC0} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{EDB2D38C-8601-43BD-AC88-165E822986C7} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
608 changes: 608 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/DataVisualizer.cs

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace TALXIS.CLI.DataVisualizer.Extensions;

public static class StringExtension
{
public static string FirstCharToUpper(this string input) => input switch
{
null => throw new ArgumentNullException(nameof(input)),
"" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)),
_ => string.Concat(input.First().ToString().ToUpper(), input.AsSpan(1))
};

/// <summary>
/// Remove diacritics, pascal case, remove spaces and replace "-" with "_"
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string NormalizeString(this string text)
{
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();

foreach (var c in normalizedString)
{
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}

return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(stringBuilder.ToString().Normalize(NormalizationForm.FormC)).Replace(" ", "").Replace("-", "_");

}
}
27 changes: 27 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Extensions/TableExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TALXIS.CLI.DataVisualizer.Model;

namespace TALXIS.CLI.DataVisualizer.Extensions;

public static class TableExtension
{
public static Table Find(this List<Table> list, string logicalName)
{
return list.FirstOrDefault(x => x.LogicalName.Equals(logicalName, StringComparison.InvariantCultureIgnoreCase));
}

public static Table CreateTable(string tableName, TableType type)
{
return new Table
{
Type = type,
LocalizedName = tableName,
LogicalName = tableName,
SetName = tableName + "s",
Rows = { new TableRow(tableName + "id", RowType.Primarykey) }
};
}
}

27 changes: 27 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/DataverseToSqlTypeMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;

namespace TALXIS.CLI.DataVisualizer.Model;

public class DataverseToSqlTypeMapper
{
private readonly Dictionary<string, string> translationTable = new Dictionary<string, string>()
{
{ "nvarchar", "varchar" },
{ "lookup", "uniqueidentifier" },
{ "primarykey", "uniqueidentifier [primary key]"},
{ "partylist", "varchar"},
{ "file", "varchar" },
{ "customer", "uniqueidentifier" },
{ "ntext", "varchar" }
};

public string this[string key]
{
get
{
if (translationTable.ContainsKey(key)) return translationTable[key];
return key;
}
}

}
39 changes: 39 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace TALXIS.CLI.DataVisualizer.Model;

public class Module
{
public Module()
{
var random = new Random();
Colorhex = string.Format("#{0:X6}", random.Next(0x1000000));
}

public Module(string module, XDocument xml)
{
ModuleName = module;
XmlDoc = xml;

var random = new Random();
Colorhex = string.Format("#{0:X6}", random.Next(0x1000000));

entities = XmlDoc.Descendants().Where(x => x.Name == "Entity").ToList();
relationships = XmlDoc.Descendants().Where(x => x.Name == "EntityRelationship").ToList();
optionsets = XmlDoc.Descendants().Where(x => x.Name == "optionset").ToList();
}

public string ModuleName { get; set; } = "";
public XDocument XmlDoc { get; set; } = new XDocument();

public List<XElement> entities = [];
public List<XElement> relationships = [];
public List<XElement> optionsets = [];

public string Colorhex { get; }
}
47 changes: 47 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/OptionsetEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TALXIS.CLI.DataVisualizer.Model;

public class OptionsetEnum
{
public string LocalizedName { get; set; }

public List<OptionsetRow> Values = [];

public OptionsetEnum(string localizedName, List<OptionsetRow> values)
{
LocalizedName = localizedName;
Values = values;
}

public void Add(string label, int value)
{
Values.Add(new OptionsetRow(label, value));
}

public void MergeOptions(List<OptionsetRow> options)
{
foreach (var newoption in options)
{
OptionsetRow optionsetRow = Values.FirstOrDefault(x => x.Value == newoption.Value);
if (optionsetRow == default)
{
Values.Add(newoption);
}
else
{
if (optionsetRow.Label != newoption.Label) optionsetRow.Label = $"{newoption.Label}";
}
}
}

public override string ToString()
{
return LocalizedName;
}

}
19 changes: 19 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/OptionsetRow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TALXIS.CLI.DataVisualizer.Model;

public class OptionsetRow
{
public OptionsetRow(string label, int value)
{
Label = label;
Value = value;
}

public string Label { get; set; }
public int Value { get; set; }


}
13 changes: 13 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/ParsedModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TALXIS.CLI.DataVisualizer.Model;

public class ParsedModel
{
public List<Table> tables = [];
public List<Relationship> relationships = [];
public List<OptionsetEnum> optionSets = [];

}
38 changes: 38 additions & 0 deletions src/TALXIS.CLI.DataVisualizer/Model/Relationship.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TALXIS.CLI.DataVisualizer.Model;

public class Relationship
{
private static Dictionary<string, string> CardinalityLookup = new Dictionary<string, string>()
{
{"OneToOne", "-"},
{"OneToMany", ">" },
{"ManyToOne", "<" }
};

public Relationship(string name, string cardinality, Table leftSideTable, TableRow leftSideRow, Table righSideTable, TableRow righSideRow)
{
Name = name;
Cardinality = cardinality;
LeftSideTable = leftSideTable;
LeftSideRow = leftSideRow;
RighSideTable = righSideTable;
RighSideRow = righSideRow;
}

public string Name { get; set; }
public string Cardinality { get; set; }
public Table LeftSideTable { get; set; }
public TableRow LeftSideRow { get; set; }
public Table RighSideTable { get; set; }
public TableRow RighSideRow { get; set; }

public override string ToString()
{
return Name;
}

}
Loading