From 1c5e8d5db84156dfe68aae40ecd644282eca0036 Mon Sep 17 00:00:00 2001
From: Cj <161484149+CJ-SPT@users.noreply.github.com>
Date: Sun, 16 Jun 2024 13:34:36 -0400
Subject: [PATCH] Implement filtering by required matches
---
RecodeItGUI/GUI/Main.Designer.cs | 50 +++++++++++++++-----
RecodeItGUI/GUI/Main.cs | 30 ++++++++++++
RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs | 41 +++++++++++-----
3 files changed, 98 insertions(+), 23 deletions(-)
diff --git a/RecodeItGUI/GUI/Main.Designer.cs b/RecodeItGUI/GUI/Main.Designer.cs
index c8e23d9..5e11258 100644
--- a/RecodeItGUI/GUI/Main.Designer.cs
+++ b/RecodeItGUI/GUI/Main.Designer.cs
@@ -101,6 +101,9 @@ partial class ReCodeItForm
IsSealedUpDown = new DomainUpDown();
TabControlMain = new TabControl();
AutoMapperTab = new TabPage();
+ label3 = new Label();
+ AutoMapperMinLengthUpDown = new NumericUpDown();
+ RunAutoRemapButton = new Button();
label2 = new Label();
AutoMapperRequiredMatchesUpDown = new NumericUpDown();
treeView1 = new TreeView();
@@ -126,7 +129,6 @@ partial class ReCodeItForm
AssemblyPathTextBox = new TextBox();
SilentModeCheckbox = new CheckBox();
DebugLoggingCheckbox = new CheckBox();
- RunAutoRemapButton = new Button();
TabPageRemapper.SuspendLayout();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)ConstuctorCountUpDown).BeginInit();
@@ -141,6 +143,7 @@ partial class ReCodeItForm
((System.ComponentModel.ISupportInitialize)NestedTypeCountUpDown).BeginInit();
TabControlMain.SuspendLayout();
AutoMapperTab.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)AutoMapperMinLengthUpDown).BeginInit();
((System.ComponentModel.ISupportInitialize)AutoMapperRequiredMatchesUpDown).BeginInit();
SettingsTab.SuspendLayout();
groupBox3.SuspendLayout();
@@ -724,7 +727,7 @@ partial class ReCodeItForm
NestedTypeCountEnabled.AutoSize = true;
NestedTypeCountEnabled.Location = new Point(287, 326);
NestedTypeCountEnabled.Name = "NestedTypeCountEnabled";
- NestedTypeCountEnabled.Size = new Size(189, 29);
+ NestedTypeCountEnabled.Size = new Size(276, 29);
NestedTypeCountEnabled.TabIndex = 12;
NestedTypeCountEnabled.Text = "Nested OriginalTypeRef Count";
NestedTypeCountEnabled.UseVisualStyleBackColor = true;
@@ -933,6 +936,8 @@ partial class ReCodeItForm
// AutoMapperTab
//
AutoMapperTab.BackColor = SystemColors.ControlDarkDark;
+ AutoMapperTab.Controls.Add(label3);
+ AutoMapperTab.Controls.Add(AutoMapperMinLengthUpDown);
AutoMapperTab.Controls.Add(RunAutoRemapButton);
AutoMapperTab.Controls.Add(label2);
AutoMapperTab.Controls.Add(AutoMapperRequiredMatchesUpDown);
@@ -948,6 +953,33 @@ partial class ReCodeItForm
AutoMapperTab.TabIndex = 3;
AutoMapperTab.Text = "Auto Mapper";
//
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(76, 97);
+ label3.Name = "label3";
+ label3.Size = new Size(277, 25);
+ label3.TabIndex = 30;
+ label3.Text = "Min Length of field or prop name";
+ //
+ // AutoMapperMinLengthUpDown
+ //
+ AutoMapperMinLengthUpDown.Location = new Point(13, 95);
+ AutoMapperMinLengthUpDown.Name = "AutoMapperMinLengthUpDown";
+ AutoMapperMinLengthUpDown.Size = new Size(57, 31);
+ AutoMapperMinLengthUpDown.TabIndex = 29;
+ AutoMapperMinLengthUpDown.ValueChanged += AutoMapperMinLengthUpDown_ValueChanged;
+ //
+ // RunAutoRemapButton
+ //
+ RunAutoRemapButton.Location = new Point(6, 3);
+ RunAutoRemapButton.Name = "RunAutoRemapButton";
+ RunAutoRemapButton.Size = new Size(168, 34);
+ RunAutoRemapButton.TabIndex = 28;
+ RunAutoRemapButton.Text = "Run Auto Remap";
+ RunAutoRemapButton.UseVisualStyleBackColor = true;
+ RunAutoRemapButton.Click += RunAutoRemapButton_Click;
+ //
// label2
//
label2.AutoSize = true;
@@ -963,6 +995,7 @@ partial class ReCodeItForm
AutoMapperRequiredMatchesUpDown.Name = "AutoMapperRequiredMatchesUpDown";
AutoMapperRequiredMatchesUpDown.Size = new Size(57, 31);
AutoMapperRequiredMatchesUpDown.TabIndex = 26;
+ AutoMapperRequiredMatchesUpDown.ValueChanged += AutoMapperRequiredMatchesUpDown_ValueChanged_1;
//
// treeView1
//
@@ -1214,16 +1247,6 @@ partial class ReCodeItForm
DebugLoggingCheckbox.UseVisualStyleBackColor = true;
DebugLoggingCheckbox.CheckedChanged += DebugLoggingCheckbox_CheckedChanged;
//
- // RunAutoRemapButton
- //
- RunAutoRemapButton.Location = new Point(6, 3);
- RunAutoRemapButton.Name = "RunAutoRemapButton";
- RunAutoRemapButton.Size = new Size(168, 34);
- RunAutoRemapButton.TabIndex = 28;
- RunAutoRemapButton.Text = "Run Auto Remap";
- RunAutoRemapButton.UseVisualStyleBackColor = true;
- RunAutoRemapButton.Click += RunAutoRemapButton_Click;
- //
// ReCodeItForm
//
AutoScaleDimensions = new SizeF(10F, 25F);
@@ -1254,6 +1277,7 @@ partial class ReCodeItForm
TabControlMain.ResumeLayout(false);
AutoMapperTab.ResumeLayout(false);
AutoMapperTab.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)AutoMapperMinLengthUpDown).EndInit();
((System.ComponentModel.ISupportInitialize)AutoMapperRequiredMatchesUpDown).EndInit();
SettingsTab.ResumeLayout(false);
groupBox3.ResumeLayout(false);
@@ -1365,4 +1389,6 @@ partial class ReCodeItForm
private Label label2;
private NumericUpDown AutoMapperRequiredMatchesUpDown;
private Button RunAutoRemapButton;
+ private Label label3;
+ private NumericUpDown AutoMapperMinLengthUpDown;
}
diff --git a/RecodeItGUI/GUI/Main.cs b/RecodeItGUI/GUI/Main.cs
index 3ef093e..7c336da 100644
--- a/RecodeItGUI/GUI/Main.cs
+++ b/RecodeItGUI/GUI/Main.cs
@@ -20,6 +20,7 @@ public partial class ReCodeItForm : Form
InitializeComponent();
PopulateDomainUpDowns();
RefreshSettingsPage();
+ RefreshAutoMapperPage();
RemapTreeView.NodeMouseDoubleClick += EditSelectedRemap;
Remapper.OnComplete += ReloadTreeView;
@@ -475,6 +476,35 @@ public partial class ReCodeItForm : Form
#endregion SETTINGS_TAB
+ #region AUTOMAPPER
+
+ public void RefreshAutoMapperPage()
+ {
+ AutoMapperExcludeBox.Items.Clear();
+
+ foreach (var method in DataProvider.Settings.AutoMapper.TypesToIgnore)
+ {
+ AutoMapperExcludeBox.Items.Add(method);
+ }
+
+ MaxMatchCountUpDown.Value = DataProvider.Settings.Remapper.MaxMatchCount;
+ AutoMapperRequiredMatchesUpDown.Value = DataProvider.Settings.AutoMapper.RequiredMatches;
+ }
+
+ private void AutoMapperRequiredMatchesUpDown_ValueChanged_1(object sender, EventArgs e)
+ {
+ DataProvider.Settings.AutoMapper.RequiredMatches = (int)AutoMapperRequiredMatchesUpDown.Value;
+ DataProvider.SaveAppSettings();
+ }
+
+ private void AutoMapperMinLengthUpDown_ValueChanged(object sender, EventArgs e)
+ {
+ DataProvider.Settings.AutoMapper.MinLengthToMatch = (int)AutoMapperMinLengthUpDown.Value;
+ DataProvider.SaveAppSettings();
+ }
+
+ #endregion AUTOMAPPER
+
// Reset All UI elements to default
private void ResetAll()
{
diff --git a/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs b/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs
index 61f25d9..0643cc9 100644
--- a/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs
+++ b/RecodeItLib/AutoMapper/ReCodeItAutoMapper.cs
@@ -50,7 +50,9 @@ public class ReCodeItAutoMapper
MappingPairs.AddRange(FilterPropertyNames(type));
}
- FilterTypeNames();
+ Logger.Log(MappingPairs.Count());
+
+ PrimaryTypeNameFilter();
SanitizeProposedNames();
StartRenameProcess();
@@ -145,7 +147,7 @@ public class ReCodeItAutoMapper
///
///
///
- private List FilterPropertyNames(TypeDefinition type)
+ private IEnumerable FilterPropertyNames(TypeDefinition type)
{
var propertiesWithTypes = new List();
@@ -199,7 +201,7 @@ public class ReCodeItAutoMapper
/// This giant linq statement handles all of the filtering once the initial gathering of fields
/// and properties is complete
///
- private void FilterTypeNames()
+ private void PrimaryTypeNameFilter()
{
// Filter types to the ones we're looking for
var mappingPairs = MappingPairs
@@ -223,16 +225,35 @@ public class ReCodeItAutoMapper
// Filter out backing fields
/// This is slow, but oh well
- .Where(pair => !pair.Name.ToCharArray().Contains('<'))
+ .Where(pair => !pair.Name.ToCharArray().Contains('<')).ToList();
+ MappingPairs = mappingPairs;
+ SecondaryTypeNameFilter();
+ }
+
+ ///
+ /// This is where we filter down based on more specific parameters
+ ///
+ ///
+ private void SecondaryTypeNameFilter()
+ {
+ // Filter property/field names by required number of matches
+ MappingPairs = MappingPairs
+ .GroupBy(pair => pair.OriginalPropOrFieldName.TrimAfterSpecialChar())
+ .Where(group => group.Count() > Settings.RequiredMatches)
+ .SelectMany(group => group).ToList();
+
+ FinalGroupAndSelect();
+ }
+
+ private void FinalGroupAndSelect()
+ {
+ MappingPairs = MappingPairs
// We only want types once, so make it unique
.GroupBy(pair => pair.OriginalTypeDefinition.FullName)
.Select(group => group.First())
.GroupBy(pair => pair.Name)
- .Select(group => group.First())
- .ToList();
-
- MappingPairs = [.. mappingPairs];
+ .Select(group => group.First()).ToList();
}
///
@@ -291,7 +312,7 @@ public class ReCodeItAutoMapper
Logger.Log($"------------------------------------------------------------------------");
}
- Logger.Log($"Automatically remapped {MappingPairs.Count} objects");
+ Logger.Log($"Automatically remapped {MappingPairs.Count()} objects");
}
///
@@ -354,8 +375,6 @@ public class ReCodeItAutoMapper
Error = true;
}
}
-
-
}
///