Skip to content

Commit 835c906

Browse files
committed
Improved: save values sorted to improve source control difference detection.
1 parent 177b46a commit 835c906

5 files changed

Lines changed: 71 additions & 10 deletions

File tree

TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using CrmCodeGenerator.VSPackage.Helpers;
2222
using CrmCodeGenerator.VSPackage.ViewModels;
2323
using Microsoft.Xrm.Sdk.Metadata;
24+
using NuGet;
25+
2426
using Yagasoft.CrmCodeGenerator;
2527
using Yagasoft.CrmCodeGenerator.Connection;
2628
using Yagasoft.CrmCodeGenerator.Helpers;
@@ -36,6 +38,7 @@
3638
using InnerMetadataHelpers = Yagasoft.CrmCodeGenerator.Helpers.MetadataHelpers;
3739
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
3840
using MessageBox = System.Windows.MessageBox;
41+
using Settings = Yagasoft.CrmCodeGenerator.Models.Settings.Settings;
3942

4043
#endregion
4144

@@ -422,6 +425,32 @@ public void SaveFilter()
422425
Settings.SelectedActions.Remove(entity.LogicalName);
423426
}
424427
}
428+
429+
SortSettings();
430+
}
431+
432+
private void SortSettings()
433+
{
434+
Settings.CrmEntityProfiles = Settings.CrmEntityProfiles.OrderBy(p => p.LogicalName).ToList();
435+
436+
Settings.EntitiesSelected = new ObservableCollection<string>(Settings.EntitiesSelected.OrderBy(p => p));
437+
Settings.EarlyBoundFilteredSelected = new ObservableCollection<string>(Settings.EarlyBoundFilteredSelected.OrderBy(p => p));
438+
439+
Settings.EarlyBoundLinkedSelected = new ObservableCollection<string>(Settings.EarlyBoundLinkedSelected.OrderBy(p => p));
440+
441+
Settings.PluginMetadataEntitiesSelected = new ObservableCollection<string>(Settings.PluginMetadataEntitiesSelected.OrderBy(p => p));
442+
Settings.JsEarlyBoundEntitiesSelected = new ObservableCollection<string>(Settings.JsEarlyBoundEntitiesSelected.OrderBy(p => p));
443+
444+
Settings.OptionsetLabelsEntitiesSelected = new ObservableCollection<string>(Settings.OptionsetLabelsEntitiesSelected.OrderBy(p => p));
445+
Settings.LookupLabelsEntitiesSelected = new ObservableCollection<string>(Settings.LookupLabelsEntitiesSelected.OrderBy(p => p));
446+
447+
var tempSelectedActions = Settings.SelectedActions;
448+
Settings.SelectedActions = new SortedDictionary<string, string[]>();
449+
450+
foreach (var pair in tempSelectedActions)
451+
{
452+
Settings.SelectedActions[pair.Key] = pair.Value.OrderBy(p => p).ToArray();
453+
}
425454
}
426455

427456
#region CRM

TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,34 +545,38 @@ public void SaveFilter()
545545

546546
//EntityProfile.EnglishLabelField = TextBoxEnglishLabelField.Text;
547547

548-
EntityProfile.Attributes = rowListAttrSource.Where(field => field.IsSelected).Select(field => field.Name).ToArray();
548+
EntityProfile.Attributes = rowListAttrSource.Where(field => field.IsSelected).Select(field => field.Name).OrderBy(p => p).ToArray();
549549
EntityProfile.AttributeRenames = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Rename))
550550
.ToDictionary(field => field.Name, field => field.Rename);
551551
EntityProfile.AttributeLanguages = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Language))
552552
.ToDictionary(field => field.Name, field => field.Language);
553553
EntityProfile.AttributeAnnotations = rowListAttrSource.Where(field => !string.IsNullOrWhiteSpace(field.Annotations))
554554
.ToDictionary(field => field.Name, field => field.Annotations);
555-
EntityProfile.ReadOnly = rowListAttrSource.Where(field => field.IsReadOnly).Select(field => field.Name).ToArray();
556-
EntityProfile.ClearFlag = rowListAttrSource.Where(field => field.IsClearFlag).Select(field => field.Name).ToArray();
555+
EntityProfile.ReadOnly = rowListAttrSource.Where(field => field.IsReadOnly).Select(field => field.Name).OrderBy(p => p).ToArray();
556+
EntityProfile.ClearFlag = rowListAttrSource.Where(field => field.IsClearFlag).Select(field => field.Name).OrderBy(p => p).ToArray();
557557

558558
EntityProfile.OneToN =
559-
rowList1NSource.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
559+
rowList1NSource.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
560560
EntityProfile.OneToNRenames = rowList1NSource.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
561561
.ToDictionary(relation => relation.Name, relation => relation.Rename);
562-
EntityProfile.OneToNReadOnly = rowList1NSource.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
562+
EntityProfile.OneToNReadOnly = rowList1NSource.Where(relation => relation.IsReadOnly)
563+
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
563564

564565
EntityProfile.NToOne =
565-
rowListN1Source.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
566+
rowListN1Source.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
566567
EntityProfile.NToOneRenames = rowListN1Source.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
567568
.ToDictionary(relation => relation.Name, relation => relation.Rename);
568-
EntityProfile.NToOneFlatten = rowListN1Source.ToDictionary(relation => relation.Name, relation => relation.IsFlatten);
569-
EntityProfile.NToOneReadOnly = rowListN1Source.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
569+
EntityProfile.NToOneFlatten = rowListN1Source.Where(relation => relation.IsFlatten)
570+
.ToDictionary(relation => relation.Name, relation => relation.IsFlatten);
571+
EntityProfile.NToOneReadOnly = rowListN1Source.Where(relation => relation.IsReadOnly)
572+
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
570573

571574
EntityProfile.NToN =
572-
RelationsNn.Where(relation => relation.IsSelected).Select(relation => relation.Name).ToArray();
575+
RelationsNn.Where(relation => relation.IsSelected).Select(relation => relation.Name).OrderBy(p => p).ToArray();
573576
EntityProfile.NToNRenames = RelationsNn.Where(relation => !string.IsNullOrWhiteSpace(relation.Rename))
574577
.ToDictionary(relation => relation.Name, relation => relation.Rename);
575-
EntityProfile.NToNReadOnly = RelationsNn.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
578+
EntityProfile.NToNReadOnly = RelationsNn.Where(relation => relation.IsReadOnly)
579+
.ToDictionary(relation => relation.Name, relation => relation.IsReadOnly);
576580

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

588592
callback?.Invoke();
593+
594+
SortSettings();
595+
}
596+
597+
private void SortSettings()
598+
{
599+
EntityProfile.AttributeRenames = SortValues(EntityProfile.AttributeRenames);
600+
EntityProfile.AttributeLanguages = SortValues(EntityProfile.AttributeLanguages);
601+
EntityProfile.AttributeAnnotations = SortValues(EntityProfile.AttributeAnnotations);
602+
EntityProfile.OneToNRenames = SortValues(EntityProfile.OneToNRenames);
603+
EntityProfile.OneToNReadOnly = SortValues(EntityProfile.OneToNReadOnly);
604+
EntityProfile.NToOneRenames = SortValues(EntityProfile.NToOneRenames);
605+
EntityProfile.NToOneFlatten = SortValues(EntityProfile.NToOneFlatten);
606+
EntityProfile.NToOneReadOnly = SortValues(EntityProfile.NToOneReadOnly);
607+
EntityProfile.NToNRenames = SortValues(EntityProfile.NToNRenames);
608+
EntityProfile.NToNReadOnly = SortValues(EntityProfile.NToNReadOnly);
609+
}
610+
611+
private static IDictionary<string, T> SortValues<T>(IDictionary<string, T> source)
612+
{
613+
var sorted = new SortedDictionary<string, T>();
614+
615+
foreach (var pair in source)
616+
{
617+
sorted[pair.Key] = pair.Value;
618+
}
619+
620+
return sorted;
589621
}
590622

591623
#region CRM
0 Bytes
Binary file not shown.
29 KB
Binary file not shown.

lib/Yagasoft.CrmCodeGenerator.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)