From f0a2319bee33b5719c7b2e30a395a125c20481c4 Mon Sep 17 00:00:00 2001 From: "KFS\\guym" Date: Wed, 22 Jun 2022 10:05:01 -0400 Subject: [PATCH 1/3] Fix bug with buidling director groups due to non-unique ids being generated --- .../Utilities/Translators/CcbGroup.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbGroup.cs b/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbGroup.cs index f5c5d3c..660a91d 100644 --- a/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbGroup.cs +++ b/Slingshot.CCB/Slingshot.CCB/Utilities/Translators/CcbGroup.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; @@ -40,10 +41,17 @@ public static List Translate( XElement inputGroup ) groups.Add( group ); - // add the department as a group with an id of 9999 + its id to create a unique group id for it if ( inputGroup.Element( "department" ) != null && inputGroup.Element( "department" ).Attribute( "id" ) != null && inputGroup.Element( "department" ).Attribute( "id" ).Value.IsNotNullOrWhitespace() ) + MD5 md5Hasher = MD5.Create(); + + // add the department as a group with id set to hash of 9999 + department id to create a unique group id for it { - departmentId = ( "9999" + inputGroup.Element( "department" ).Attribute( "id" ).Value ).AsInteger(); + var hashedDepartmentId = md5Hasher.ComputeHash( Encoding.UTF8.GetBytes( $@" + {9999} + {inputGroup.Element( "department" ).Attribute( "id" ).Value} + " ) ); + departmentId = Math.Abs( BitConverter.ToInt32( hashedDepartmentId, 0 ) ); // used abs to ensure positive number + var departmentName = inputGroup.Element( "department" ).Value; if ( departmentName.IsNullOrWhiteSpace() ) { @@ -52,10 +60,16 @@ public static List Translate( XElement inputGroup ) groups.Add( new Group { Id = departmentId.Value, Name = inputGroup.Element( "department" ).Value, IsActive = true, GroupTypeId = 9999 } ); } - // add the director as a group with an id of 9998 + its id to create a unique group id for it if ( inputGroup.Element( "director" ) != null && inputGroup.Element( "director" ).Attribute( "id" ) != null && inputGroup.Element( "director" ).Attribute( "id" ).Value.IsNotNullOrWhitespace() ) { - directorId = ( "9998" + inputGroup.Element( "director" ).Attribute( "id" ).Value ).AsInteger(); + // add the director as a group with an id of 9998 + its id + its department id (if any) to create a unique group id for it + var departmentIdString = departmentId.HasValue ? departmentId.Value.ToString() : string.Empty; + var hashedDirectorId = md5Hasher.ComputeHash( Encoding.UTF8.GetBytes( $@" + {9998} + {inputGroup.Element( "director" ).Attribute( "id" ).Value} + {departmentIdString} + " ) ); + directorId = Math.Abs( BitConverter.ToInt32( hashedDirectorId, 0 ) ); // used abs to ensure positive number var directorGroup = new Group(); directorGroup.Id = directorId.Value; From 3fd844a776cacf0cea9c575e235a7842db0aa70e Mon Sep 17 00:00:00 2001 From: "KFS\\guym" Date: Wed, 22 Jun 2022 10:07:27 -0400 Subject: [PATCH 2/3] Add ability to make director group breakout to be optional --- Slingshot.CCB/Slingshot.CCB/MainWindow.xaml | 1 + .../Slingshot.CCB/MainWindow.xaml.cs | 3 +++ .../Slingshot.CCB/Utilities/CcbApi.cs | 25 ++++++++++++++++--- .../Utilities/Translators/CcbGroup.cs | 23 +++++++++++++---- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Slingshot.CCB/Slingshot.CCB/MainWindow.xaml b/Slingshot.CCB/Slingshot.CCB/MainWindow.xaml index 107b74e..b682c70 100644 --- a/Slingshot.CCB/Slingshot.CCB/MainWindow.xaml +++ b/Slingshot.CCB/Slingshot.CCB/MainWindow.xaml @@ -89,6 +89,7 @@