Skip to content

Commit 39b32fd

Browse files
authored
Merge pull request #10 from RoelantVos/Development---saving-model-metadata-as-JSON-and-removing-Driving-Key-from-model-info
Development saving model metadata as json and removing driving key from model info
2 parents ae3be12 + ab39654 commit 39b32fd

File tree

8 files changed

+798
-641
lines changed

8 files changed

+798
-641
lines changed

TEAM.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2018
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TEAM", "TEAM\TEAM.csproj", "{73971441-2782-43CF-862C-1F636528858A}"
77
EndProject

TEAM/FormBase.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Data;
45
using System.Data.SqlClient;
56
using System.IO;
@@ -178,6 +179,24 @@ public static void InitialiseConfiguration(string chosenFile)
178179
}
179180
}
180181

182+
public static string CreateMd5(string input)
183+
{
184+
// Use input string to calculate MD5 hash
185+
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
186+
{
187+
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
188+
byte[] hashBytes = md5.ComputeHash(inputBytes);
189+
190+
// Convert the byte array to hexadecimal string
191+
StringBuilder sb = new StringBuilder();
192+
for (int i = 0; i < hashBytes.Length; i++)
193+
{
194+
sb.Append(hashBytes[i].ToString("X2"));
195+
}
196+
return sb.ToString();
197+
}
198+
}
199+
181200
public class ConfigurationSettings
182201
{
183202

@@ -512,6 +531,7 @@ public class GlobalParameters
512531

513532
private static string _jsonTableMappingFileName = "TEAM_Table_Mapping.json";
514533
private static string _jsonAttributeMappingFileName = "TEAM_Attribute_Mapping.json";
534+
private static string _jsonModelMetadataFileName = "TEAM_Model_Metadata.json";
515535

516536
public static string ConfigurationPath
517537
{
@@ -542,11 +562,18 @@ public static string jsonTableMappingFileName
542562
get { return _jsonTableMappingFileName; }
543563
set { _jsonTableMappingFileName = value; }
544564
}
565+
545566
public static string jsonAttributeMappingFileName
546567
{
547568
get { return _jsonAttributeMappingFileName; }
548569
set { _jsonAttributeMappingFileName = value; }
549570
}
571+
572+
public static string jsonModelMetadataFileName
573+
{
574+
get { return _jsonModelMetadataFileName; }
575+
set { _jsonModelMetadataFileName = value; }
576+
}
550577
}
551578

552579
public DataTable GetDataTable(ref SqlConnection sqlConnection, string sql)
@@ -611,6 +638,22 @@ public KeyValuePair<int, int> GetVersion(int selectedVersion, SqlConnection sqlC
611638
}
612639
}
613640

641+
public DataTable ConvertToDataTable<T>(IList<T> data)
642+
{
643+
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
644+
DataTable table = new DataTable();
645+
foreach (PropertyDescriptor prop in properties)
646+
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
647+
foreach (T item in data)
648+
{
649+
DataRow row = table.NewRow();
650+
foreach (PropertyDescriptor prop in properties)
651+
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
652+
table.Rows.Add(row);
653+
}
654+
return table;
655+
}
656+
614657
protected int GetMaxVersionId(SqlConnection sqlConnection)
615658
{
616659
var versionId = new int();

TEAM/Form_Manage_Metadata.cs

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,6 @@ public class AttributeMappingJson
4848
public string transformationRule { get; set; }
4949
}
5050

51-
public static string CreateMd5(string input)
52-
{
53-
// Use input string to calculate MD5 hash
54-
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
55-
{
56-
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
57-
byte[] hashBytes = md5.ComputeHash(inputBytes);
58-
59-
// Convert the byte array to hexadecimal string
60-
StringBuilder sb = new StringBuilder();
61-
for (int i = 0; i < hashBytes.Length; i++)
62-
{
63-
sb.Append(hashBytes[i].ToString("X2"));
64-
}
65-
return sb.ToString();
66-
}
67-
}
68-
6951
public FormManageMetadata(FormMain parent) : base(parent)
7052
{
7153
InitializeComponent();
@@ -108,21 +90,21 @@ public FormManageMetadata(FormMain parent) : base(parent)
10890

10991

11092

111-
public DataTable ConvertToDataTable<T>(IList<T> data)
112-
{
113-
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
114-
DataTable table = new DataTable();
115-
foreach (PropertyDescriptor prop in properties)
116-
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
117-
foreach (T item in data)
118-
{
119-
DataRow row = table.NewRow();
120-
foreach (PropertyDescriptor prop in properties)
121-
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
122-
table.Rows.Add(row);
123-
}
124-
return table;
125-
}
93+
//public DataTable ConvertToDataTable<T>(IList<T> data)
94+
//{
95+
// PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
96+
// DataTable table = new DataTable();
97+
// foreach (PropertyDescriptor prop in properties)
98+
// table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
99+
// foreach (T item in data)
100+
// {
101+
// DataRow row = table.NewRow();
102+
// foreach (PropertyDescriptor prop in properties)
103+
// row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
104+
// table.Rows.Add(row);
105+
// }
106+
// return table;
107+
//}
126108

127109
private void PopulateTableMappingGridWithVersion(int versionId)
128110
{
@@ -177,6 +159,7 @@ private void PopulateTableMappingGridWithVersion(int versionId)
177159
dataGridViewTableMetadata.Columns[6].HeaderText = "Filter Criteria";
178160
dataGridViewTableMetadata.Columns[7].HeaderText = "Generation Indicator";
179161
}
162+
180163
}
181164
else if (repositoryTarget == "JSON") //Update the JSON
182165
{
@@ -239,6 +222,7 @@ private void PopulateTableMappingGridWithVersion(int versionId)
239222

240223
richTextBoxInformation.AppendText("The file "+ configurationSettings.ConfigurationPath + GlobalParameters.jsonTableMappingFileName + " was loaded.");
241224
}
225+
GridAutoLayout();
242226
}
243227

244228
private void PopulateAttributeGridWithVersion(int versionId)
@@ -293,8 +277,6 @@ private void PopulateAttributeGridWithVersion(int versionId)
293277
dataGridViewAttributeMetadata.Columns[4].HeaderText = "Integration Area Table";
294278
dataGridViewAttributeMetadata.Columns[5].HeaderText = "Integration Area Column";
295279
dataGridViewAttributeMetadata.Columns[6].HeaderText = "Transformation Rule";
296-
297-
GridAutoLayout();
298280
}
299281
}
300282
else if (repositoryTarget == "JSON") //Update the JSON
@@ -357,7 +339,7 @@ private void PopulateAttributeGridWithVersion(int versionId)
357339

358340
richTextBoxInformation.AppendText("The file " + configurationSettings.ConfigurationPath + GlobalParameters.jsonAttributeMappingFileName + " was loaded.");
359341
}
360-
342+
GridAutoLayout();
361343
}
362344

363345
private DialogResult STAShowDialog(FileDialog dialog)
@@ -544,8 +526,8 @@ private void ManageModelMetadataVersion()
544526
//Create insert statement
545527
var insertQueryTables = new StringBuilder();
546528

547-
insertQueryTables.AppendLine("INSERT INTO MD_VERSION_ATTRIBUTE");
548-
insertQueryTables.AppendLine("([VERSION_ID], [TABLE_NAME],[COLUMN_NAME],[DATA_TYPE],[CHARACTER_MAXIMUM_LENGTH],[NUMERIC_PRECISION], [ORDINAL_POSITION], [PRIMARY_KEY_INDICATOR], [DRIVING_KEY_INDICATOR], [MULTI_ACTIVE_INDICATOR])");
529+
insertQueryTables.AppendLine("INSERT INTO [MD_VERSION_ATTRIBUTE]");
530+
insertQueryTables.AppendLine("([VERSION_ID], [TABLE_NAME],[COLUMN_NAME],[DATA_TYPE],[CHARACTER_MAXIMUM_LENGTH],[NUMERIC_PRECISION], [ORDINAL_POSITION], [PRIMARY_KEY_INDICATOR], [MULTI_ACTIVE_INDICATOR])");
549531
insertQueryTables.AppendLine("SELECT ");
550532
insertQueryTables.AppendLine(" " + versionId + ",");
551533
insertQueryTables.AppendLine(" [TABLE_NAME], ");
@@ -555,10 +537,9 @@ private void ManageModelMetadataVersion()
555537
insertQueryTables.AppendLine(" [NUMERIC_PRECISION], ");
556538
insertQueryTables.AppendLine(" [ORDINAL_POSITION], ");
557539
insertQueryTables.AppendLine(" [PRIMARY_KEY_INDICATOR], ");
558-
insertQueryTables.AppendLine(" [DRIVING_KEY_INDICATOR], ");
559540
insertQueryTables.AppendLine(" [MULTI_ACTIVE_INDICATOR] ");
560-
insertQueryTables.AppendLine("FROM MD_VERSION_ATTRIBUTE");
561-
insertQueryTables.AppendLine("WHERE VERSION_ID = " + previousVersionId + "");
541+
insertQueryTables.AppendLine("FROM [MD_VERSION_ATTRIBUTE]");
542+
insertQueryTables.AppendLine("WHERE [VERSION_ID] = " + previousVersionId + "");
562543

563544
//Execute the insert statement
564545
using (var connection = new SqlConnection(configurationSettings.ConnectionStringOmd))

0 commit comments

Comments
 (0)