Skip to content

Commit

Permalink
Improved: save values sorted to improve source control difference det…
Browse files Browse the repository at this point in the history
…ection.
  • Loading branch information
yagasoft committed May 29, 2023
1 parent 177b46a commit 835c906
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
29 changes: 29 additions & 0 deletions TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using CrmCodeGenerator.VSPackage.Helpers;
using CrmCodeGenerator.VSPackage.ViewModels;
using Microsoft.Xrm.Sdk.Metadata;
using NuGet;

using Yagasoft.CrmCodeGenerator;
using Yagasoft.CrmCodeGenerator.Connection;
using Yagasoft.CrmCodeGenerator.Helpers;
Expand All @@ -36,6 +38,7 @@
using InnerMetadataHelpers = Yagasoft.CrmCodeGenerator.Helpers.MetadataHelpers;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox;
using Settings = Yagasoft.CrmCodeGenerator.Models.Settings.Settings;

#endregion

Expand Down Expand Up @@ -422,6 +425,32 @@ public void SaveFilter()
Settings.SelectedActions.Remove(entity.LogicalName);
}
}

SortSettings();
}

private void SortSettings()
{
Settings.CrmEntityProfiles = Settings.CrmEntityProfiles.OrderBy(p => p.LogicalName).ToList();

Settings.EntitiesSelected = new ObservableCollection<string>(Settings.EntitiesSelected.OrderBy(p => p));
Settings.EarlyBoundFilteredSelected = new ObservableCollection<string>(Settings.EarlyBoundFilteredSelected.OrderBy(p => p));

Settings.EarlyBoundLinkedSelected = new ObservableCollection<string>(Settings.EarlyBoundLinkedSelected.OrderBy(p => p));

Settings.PluginMetadataEntitiesSelected = new ObservableCollection<string>(Settings.PluginMetadataEntitiesSelected.OrderBy(p => p));
Settings.JsEarlyBoundEntitiesSelected = new ObservableCollection<string>(Settings.JsEarlyBoundEntitiesSelected.OrderBy(p => p));

Settings.OptionsetLabelsEntitiesSelected = new ObservableCollection<string>(Settings.OptionsetLabelsEntitiesSelected.OrderBy(p => p));
Settings.LookupLabelsEntitiesSelected = new ObservableCollection<string>(Settings.LookupLabelsEntitiesSelected.OrderBy(p => p));

var tempSelectedActions = Settings.SelectedActions;
Settings.SelectedActions = new SortedDictionary<string, string[]>();

foreach (var pair in tempSelectedActions)
{
Settings.SelectedActions[pair.Key] = pair.Value.OrderBy(p => p).ToArray();
}
}

#region CRM
Expand Down
52 changes: 42 additions & 10 deletions TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,34 +545,38 @@ public void SaveFilter()

//EntityProfile.EnglishLabelField = TextBoxEnglishLabelField.Text;

EntityProfile.Attributes = rowListAttrSource.Where(field => field.IsSelected).Select(field => field.Name).ToArray();
EntityProfile.Attributes = rowListAttrSource.Where(field => field.IsSelected).Select(field => field.Name).OrderBy(p => p).ToArray();
EntityProfile.AttributeRenames = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Rename))
.ToDictionary(field => field.Name, field => field.Rename);
EntityProfile.AttributeLanguages = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Language))
.ToDictionary(field => field.Name, field => field.Language);
EntityProfile.AttributeAnnotations = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Annotations))
.ToDictionary(field => field.Name, field => field.Annotations);
EntityProfile.ReadOnly = rowListAttrSource.Where(field => field.IsReadOnly).Select(field => field.Name).ToArray();
EntityProfile.ClearFlag = rowListAttrSource.Where(field => field.IsClearFlag).Select(field => field.Name).ToArray();
EntityProfile.ReadOnly = rowListAttrSource.Where(field => field.IsReadOnly).Select(field => field.Name).OrderBy(p => p).ToArray();
EntityProfile.ClearFlag = rowListAttrSource.Where(field => field.IsClearFlag).Select(field => field.Name).OrderBy(p => p).ToArray();

EntityProfile.OneToN =
rowList1NSource.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
rowList1NSource.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
EntityProfile.OneToNRenames = rowList1NSource.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
.ToDictionary(relation => relation.Name, relation => relation.Rename);
EntityProfile.OneToNReadOnly = rowList1NSource.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
EntityProfile.OneToNReadOnly = rowList1NSource.Where(relation => relation.IsReadOnly)
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);

EntityProfile.NToOne =
rowListN1Source.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
rowListN1Source.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
EntityProfile.NToOneRenames = rowListN1Source.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
.ToDictionary(relation => relation.Name, relation => relation.Rename);
EntityProfile.NToOneFlatten = rowListN1Source.ToDictionary(relation => relation.Name, relation => relation.IsFlatten);
EntityProfile.NToOneReadOnly = rowListN1Source.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
EntityProfile.NToOneFlatten = rowListN1Source.Where(relation => relation.IsFlatten)
.ToDictionary(relation => relation.Name, relation => relation.IsFlatten);
EntityProfile.NToOneReadOnly = rowListN1Source.Where(relation => relation.IsReadOnly)
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);

EntityProfile.NToN =
RelationsNn.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
RelationsNn.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
EntityProfile.NToNRenames = RelationsNn.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
.ToDictionary(relation => relation.Name, relation => relation.Rename);
EntityProfile.NToNReadOnly = RelationsNn.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
EntityProfile.NToNReadOnly = RelationsNn.Where(relation => relation.IsReadOnly)
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);

var toSelect = Relations1N.Where(relation => relation.IsSelected).Select(relation => relation.ToEntity)
.Union(RelationsN1.Where(relation => relation.IsSelected).Select(relation => relation.ToEntity)
Expand All @@ -586,6 +590,34 @@ public void SaveFilter()
}

callback?.Invoke();

SortSettings();
}

private void SortSettings()
{
EntityProfile.AttributeRenames = SortValues(EntityProfile.AttributeRenames);
EntityProfile.AttributeLanguages = SortValues(EntityProfile.AttributeLanguages);
EntityProfile.AttributeAnnotations = SortValues(EntityProfile.AttributeAnnotations);
EntityProfile.OneToNRenames = SortValues(EntityProfile.OneToNRenames);
EntityProfile.OneToNReadOnly = SortValues(EntityProfile.OneToNReadOnly);
EntityProfile.NToOneRenames = SortValues(EntityProfile.NToOneRenames);
EntityProfile.NToOneFlatten = SortValues(EntityProfile.NToOneFlatten);
EntityProfile.NToOneReadOnly = SortValues(EntityProfile.NToOneReadOnly);
EntityProfile.NToNRenames = SortValues(EntityProfile.NToNRenames);
EntityProfile.NToNReadOnly = SortValues(EntityProfile.NToNReadOnly);
}

private static IDictionary<string, T> SortValues<T>(IDictionary<string, T> source)
{
var sorted = new SortedDictionary<string, T>();

foreach (var pair in source)
{
sorted[pair.Key] = pair.Value;
}

return sorted;
}

#region CRM
Expand Down
Binary file modified lib/ILMerge/Yagasoft.CrmCodeGenerator.dll
Binary file not shown.
Binary file modified lib/ILMerge/Yagasoft.TemplateCodeGeneratorPlugin.dll
Binary file not shown.
Binary file modified lib/Yagasoft.CrmCodeGenerator.dll
Binary file not shown.

0 comments on commit 835c906

Please sign in to comment.