diff --git a/TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs b/TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs index 49a9cfd..469ffc2 100644 --- a/TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs +++ b/TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs @@ -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; @@ -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 @@ -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(Settings.EntitiesSelected.OrderBy(p => p)); + Settings.EarlyBoundFilteredSelected = new ObservableCollection(Settings.EarlyBoundFilteredSelected.OrderBy(p => p)); + + Settings.EarlyBoundLinkedSelected = new ObservableCollection(Settings.EarlyBoundLinkedSelected.OrderBy(p => p)); + + Settings.PluginMetadataEntitiesSelected = new ObservableCollection(Settings.PluginMetadataEntitiesSelected.OrderBy(p => p)); + Settings.JsEarlyBoundEntitiesSelected = new ObservableCollection(Settings.JsEarlyBoundEntitiesSelected.OrderBy(p => p)); + + Settings.OptionsetLabelsEntitiesSelected = new ObservableCollection(Settings.OptionsetLabelsEntitiesSelected.OrderBy(p => p)); + Settings.LookupLabelsEntitiesSelected = new ObservableCollection(Settings.LookupLabelsEntitiesSelected.OrderBy(p => p)); + + var tempSelectedActions = Settings.SelectedActions; + Settings.SelectedActions = new SortedDictionary(); + + foreach (var pair in tempSelectedActions) + { + Settings.SelectedActions[pair.Key] = pair.Value.OrderBy(p => p).ToArray(); + } } #region CRM diff --git a/TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs b/TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs index f322730..0b88bc4 100644 --- a/TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs +++ b/TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs @@ -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) @@ -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 SortValues(IDictionary source) + { + var sorted = new SortedDictionary(); + + foreach (var pair in source) + { + sorted[pair.Key] = pair.Value; + } + + return sorted; } #region CRM diff --git a/lib/ILMerge/Yagasoft.CrmCodeGenerator.dll b/lib/ILMerge/Yagasoft.CrmCodeGenerator.dll index 840caf6..f5f1733 100644 Binary files a/lib/ILMerge/Yagasoft.CrmCodeGenerator.dll and b/lib/ILMerge/Yagasoft.CrmCodeGenerator.dll differ diff --git a/lib/ILMerge/Yagasoft.TemplateCodeGeneratorPlugin.dll b/lib/ILMerge/Yagasoft.TemplateCodeGeneratorPlugin.dll index 0d83982..0b4031b 100644 Binary files a/lib/ILMerge/Yagasoft.TemplateCodeGeneratorPlugin.dll and b/lib/ILMerge/Yagasoft.TemplateCodeGeneratorPlugin.dll differ diff --git a/lib/Yagasoft.CrmCodeGenerator.dll b/lib/Yagasoft.CrmCodeGenerator.dll index 840caf6..f5f1733 100644 Binary files a/lib/Yagasoft.CrmCodeGenerator.dll and b/lib/Yagasoft.CrmCodeGenerator.dll differ