Skip to content

Commit ba63033

Browse files
committed
Improved: filtering feature now works over logical and display names, and renames.
Updated: latest custom libraries. Fixed: template issues.
1 parent 11bff40 commit ba63033

15 files changed

Lines changed: 412 additions & 315 deletions

TemplateCodeGeneratorPlugin/Control/EntitySelectorForms.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using CrmCodeGenerator.VSPackage.Dialogs;
1313
using Microsoft.Xrm.Sdk;
1414
using Yagasoft.CrmCodeGenerator.Connection;
15-
using Yagasoft.CrmCodeGenerator.Connection.OrgSvcs;
1615
using Yagasoft.CrmCodeGenerator.Models.Cache;
1716
using Yagasoft.CrmCodeGenerator.Models.Settings;
1817
using Yagasoft.TemplateCodeGeneratorPlugin.Helpers;
@@ -31,7 +30,7 @@ public Settings Settings
3130
}
3231
}
3332

34-
private readonly IConnectionManager<IDisposableOrgSvc> connectionManager;
33+
private readonly IConnectionManager connectionManager;
3534
private readonly MetadataCache metadataCache;
3635
private readonly WorkerHelper workerHelper;
3736

@@ -40,7 +39,7 @@ public Settings Settings
4039
private FilterDetails currentFilterDetails;
4140
private Options currentOptions;
4241

43-
public EntitySelectorForms(IConnectionManager<IDisposableOrgSvc> connectionManager, MetadataCache metadataCache,
42+
public EntitySelectorForms(IConnectionManager connectionManager, MetadataCache metadataCache,
4443
WorkerHelper workerHelper)
4544
{
4645
this.connectionManager = connectionManager;

TemplateCodeGeneratorPlugin/Control/XrmMockGeneratorPluginControl.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using XrmToolBox.Extensibility.Args;
2121
using XrmToolBox.Extensibility.Interfaces;
2222
using Yagasoft.CrmCodeGenerator.Connection;
23-
using Yagasoft.CrmCodeGenerator.Connection.OrgSvcs;
2423
using Yagasoft.CrmCodeGenerator.Mapper;
2524
using Yagasoft.CrmCodeGenerator.Models.Cache;
2625
using Yagasoft.CrmCodeGenerator.Models.Mapper;
@@ -41,8 +40,18 @@
4140

4241
namespace Yagasoft.TemplateCodeGeneratorPlugin.Control
4342
{
44-
public partial class PluginControl : PluginControlBase, IStatusBarMessenger
43+
public partial class PluginControl : PluginControlBase, IStatusBarMessenger, IGitHubPlugin, IPayPalPlugin, IHelpPlugin
4544
{
45+
public string UserName => "yagasoft";
46+
47+
public string RepositoryName => "DynamicsCrm-Template-based-Code-Generator-Plugin";
48+
49+
public string EmailAccount => "mail@yagasoft.com";
50+
51+
public string DonationDescription => "Thank you!";
52+
53+
public string HelpUrl => "https://blog.yagasoft.com/2020/09/dynamics-template-based-code-generator-supercharged";
54+
4655
//private bool SettingsSaved
4756
//{
4857
// get => settingsSaved;
@@ -827,7 +836,7 @@ private void textBoxNamespace_TextChanged(object sender, EventArgs e)
827836

828837
private void labelYagasoft_Click(object sender, EventArgs e)
829838
{
830-
Process.Start(new ProcessStartInfo("http://yagasoft.com"));
839+
Process.Start(new ProcessStartInfo("https://yagasoft.com"));
831840
}
832841

833842
private void linkDownVs_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -837,7 +846,7 @@ private void linkDownVs_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
837846

838847
private void linkQuickGuide_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
839848
{
840-
Process.Start(new ProcessStartInfo("http://blog.yagasoft.com/2020/09/dynamics-template-based-code-generator-supercharged"));
849+
Process.Start(new ProcessStartInfo("https://blog.yagasoft.com/2020/09/dynamics-template-based-code-generator-supercharged"));
841850
}
842851

843852
private void buttonCancel_Click(object sender, EventArgs e)
@@ -1133,6 +1142,7 @@ void MapperOnStatusUpdate(object o, MapperEventArgs args)
11331142
context.IsUseCustomTypeForAltKeys = settings.IsUseCustomTypeForAltKeys;
11341143
context.IsMakeCrmEntitiesJsonFriendly = settings.IsMakeCrmEntitiesJsonFriendly;
11351144
context.CrmEntityProfiles = settings.CrmEntityProfiles;
1145+
context.EntityProfilesHeaderSelector = settings.EntityProfilesHeaderSelector;
11361146
break;
11371147
}
11381148
}
@@ -1327,27 +1337,12 @@ private void ShowOptions()
13271337
}
13281338
}
13291339

1330-
public class ConnectionManager : IConnectionManager<IDisposableOrgSvc>
1340+
public class ConnectionManager : IConnectionManager
13311341
{
13321342
public Func<IOrganizationService> ServiceGetter { get; set; }
13331343

1334-
public ConnectionManager(Func<IOrganizationService> serviceGetter)
1335-
{
1336-
ServiceGetter = serviceGetter;
1337-
}
1338-
1339-
public IDisposableOrgSvc Get(string connectionString = null)
1340-
{
1341-
return new DisposableOrgSvc(ServiceGetter());
1342-
}
1343-
}
1344-
1345-
public class DisposableOrgSvc : DisposableOrgSvcBase
1346-
{
1347-
public DisposableOrgSvc(IOrganizationService innerService) : base(innerService)
1348-
{ }
1344+
public ConnectionManager(Func<IOrganizationService> serviceGetter) => ServiceGetter = serviceGetter;
13491345

1350-
public override void Dispose()
1351-
{ }
1346+
public IOrganizationService Get() => ServiceGetter();
13521347
}
13531348
}

TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@
7070
<ColumnDefinition MaxWidth="50" />
7171
<ColumnDefinition MaxWidth="50" />
7272
</Grid.ColumnDefinitions>
73-
<CheckBox x:Name="CheckBoxDisplayFilter" IsChecked="{Binding DisplayFilter}"
74-
VerticalAlignment="Center" Margin="6,0,0,0"
75-
HorizontalAlignment="Stretch">
76-
Filter by Display Name
77-
</CheckBox>
7873
<TextBox x:Name="TextBoxFilter" Margin="5,0,0,0" Grid.Column="1"
7974
KeyDown="TextBoxFilter_OnKeyDown"
8075
Text="{Binding Filter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

TemplateCodeGeneratorPlugin/Dialogues/EntitySelection.xaml.cs

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using Microsoft.Xrm.Sdk.Metadata;
2424
using Yagasoft.CrmCodeGenerator;
2525
using Yagasoft.CrmCodeGenerator.Connection;
26-
using Yagasoft.CrmCodeGenerator.Connection.OrgSvcs;
2726
using Yagasoft.CrmCodeGenerator.Helpers;
2827
using Yagasoft.CrmCodeGenerator.Models.Cache;
2928
using Yagasoft.CrmCodeGenerator.Models.Settings;
@@ -47,7 +46,7 @@ namespace CrmCodeGenerator.VSPackage.Dialogs
4746
/// </summary>
4847
public partial class EntitySelection : INotifyPropertyChanged
4948
{
50-
private readonly IConnectionManager<IDisposableOrgSvc> connectionManager;
49+
private readonly IConnectionManager connectionManager;
5150
private readonly MetadataCache metadataCache;
5251
private readonly EntitySelectorForms entitySelectorForms;
5352
private readonly WorkerHelper workerHelper;
@@ -58,18 +57,6 @@ public partial class EntitySelection : INotifyPropertyChanged
5857

5958
public List<EntityMetadata> EntityMetadataCache;
6059

61-
private bool displayFilter;
62-
63-
public bool DisplayFilter
64-
{
65-
get => displayFilter;
66-
set
67-
{
68-
displayFilter = value;
69-
OnPropertyChanged();
70-
}
71-
}
72-
7360
private bool entitiesSelectAll;
7461

7562
public bool EntitiesSelectAll
@@ -157,7 +144,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
157144

158145
#region Init
159146

160-
public EntitySelection(Settings settings, IConnectionManager<IDisposableOrgSvc> connectionManager, MetadataCache metadataCache,
147+
public EntitySelection(Settings settings, IConnectionManager connectionManager, MetadataCache metadataCache,
161148
EntitySelectorForms entitySelectorForms, WorkerHelper workerHelper)
162149
{
163150
InitializeComponent();
@@ -802,45 +789,18 @@ private void SelectEntitiesByRegex()
802789
{
803790
IEnumerable<string> customEntities = null;
804791

805-
if (!string.IsNullOrEmpty(TextBoxFilter.Text))
806-
{
807-
808-
// get all regex
809-
var prefixes = TextBoxFilter.Text.ToLower()
810-
.Split(',').Select(prefix => prefix.Trim())
811-
.Where(prefix => !string.IsNullOrEmpty(prefix))
812-
.Distinct();
813-
814-
// get entity names that match any regex from the fetched list
815-
if (DisplayFilter)
816-
{
817-
customEntities =
818-
EntityMetadataCache
819-
.ToDictionary(key => key.LogicalName,
820-
value =>
821-
{
822-
var rename = Settings.CrmEntityProfiles
823-
.FirstOrDefault(filter => filter.LogicalName == value.LogicalName)?.EntityRename;
824-
825-
return "("
826-
+ (string.IsNullOrEmpty(rename)
827-
? value.DisplayName?.UserLocalizedLabel == null || !Settings.UseDisplayNames
828-
? Naming.GetProperHybridName(value.SchemaName, value.LogicalName)
829-
: Naming.Clean(value.DisplayName.UserLocalizedLabel.Label)
830-
: rename)
831-
+ ")";
832-
})
833-
.Where(keyValue => prefixes.Any(
834-
prefix => Regex.IsMatch(keyValue.Value.ToLower().Replace("(", "").Replace(")", ""), prefix)))
835-
.Select(keyValue => keyValue.Key)
836-
.Distinct();
837-
}
838-
else
839-
{
840-
customEntities = Settings.EntityList
841-
.Where(entity => prefixes.Any(prefix => Regex.IsMatch(entity, prefix)))
842-
.Distinct();
843-
}
792+
if (TextBoxFilter.Text.IsFilled())
793+
{
794+
var filters = TextBoxFilter.Text.ToLower()
795+
.Split(',').Select(t => t.Trim())
796+
.Where(t => t.IsFilled())
797+
.Distinct();
798+
799+
customEntities = rowListSource
800+
.Where(e => filters.Any(f => Regex.IsMatch(e.Name, f)
801+
|| (e.DisplayName.IsFilled() && Regex.IsMatch(e.DisplayName.ToLower(), f))
802+
|| (e.Rename.IsFilled() && Regex.IsMatch(e.Rename.ToLower(), f))))
803+
.Select(e => e.Name).Distinct().ToList();
844804
}
845805

846806
// filter entities

TemplateCodeGeneratorPlugin/Dialogues/FilterDetails.xaml.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using Microsoft.Xrm.Sdk.Metadata.Query;
2222
using Microsoft.Xrm.Sdk.Query;
2323
using Yagasoft.CrmCodeGenerator.Connection;
24-
using Yagasoft.CrmCodeGenerator.Connection.OrgSvcs;
2524
using Yagasoft.CrmCodeGenerator.Helpers;
2625
using Yagasoft.CrmCodeGenerator.Models.Cache;
2726
using Yagasoft.CrmCodeGenerator.Models.Settings;
@@ -209,7 +208,7 @@ public bool IsEnglishLabelEnabled
209208
private readonly WorkerHelper workerHelper;
210209
private readonly Action callback;
211210
private readonly Action closeAction;
212-
private readonly IConnectionManager<IDisposableOrgSvc> connectionManager;
211+
private readonly IConnectionManager connectionManager;
213212
private EntityMetadata metadata;
214213

215214
private readonly ConcurrentBag<EntityFilterGridRow> rowListAttrSource = new ConcurrentBag<EntityFilterGridRow>();
@@ -235,7 +234,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
235234

236235
public FilterDetails(string logicalName, Settings settings,
237236
EntityProfile entityProfile, ObservableCollection<GridRow> entities,
238-
IConnectionManager<IDisposableOrgSvc> connectionManager, MetadataCache metadataCache,
237+
IConnectionManager connectionManager, MetadataCache metadataCache,
239238
WorkerHelper workerHelper, Action callback, Action closeAction)
240239
{
241240
InitializeComponent();
@@ -421,7 +420,7 @@ private void GenerateLists(string controlName = null)
421420
var row = rowList1NSource.FirstOrDefault(r => r.Name == relation1NAsync.SchemaName)
422421
?? new Relations1NGridRow
423422
{
424-
IsSelected = EntityProfile.OneToN == null || EntityProfile.OneToN.Contains(relation1NAsync.SchemaName),
423+
IsSelected = EntityProfile.OneToN?.Contains(relation1NAsync.SchemaName) == true,
425424
Name = relation1NAsync.SchemaName,
426425
ToEntity = relation1NAsync.ReferencingEntity ?? "",
427426
ToField = relation1NAsync.ReferencingAttribute ?? "",
@@ -466,7 +465,7 @@ private void GenerateLists(string controlName = null)
466465
var row = rowListN1Source.FirstOrDefault(r => r.Name == relationN1Async.SchemaName)
467466
?? new RelationsN1GridRow
468467
{
469-
IsSelected = EntityProfile.NToOne == null || EntityProfile.NToOne.Contains(relationN1Async.SchemaName),
468+
IsSelected = EntityProfile.NToOne?.Contains(relationN1Async.SchemaName) == true,
470469
Name = relationN1Async.SchemaName,
471470
ToEntity = relationN1Async.ReferencedEntity ?? "",
472471
FromField = relationN1Async.ReferencingAttribute ?? "",
@@ -516,7 +515,7 @@ private void GenerateLists(string controlName = null)
516515
var row =
517516
new RelationsNnGridRow
518517
{
519-
IsSelected = EntityProfile.NToN == null || EntityProfile.NToN.Contains(relationNnAsync.SchemaName),
518+
IsSelected = EntityProfile.NToN?.Contains(relationNnAsync.SchemaName) == true,
520519
Name = relationNnAsync.SchemaName,
521520
ToEntity = relationNnAsync.Entity1LogicalName == LogicalName
522521
? relationNnAsync.Entity2LogicalName
@@ -646,10 +645,7 @@ private RetrieveMetadataChangesResponse GetEntityMetadata()
646645
Query = entityQueryExpression,
647646
};
648647

649-
using (var service = connectionManager.Get(Settings.ConnectionString))
650-
{
651-
return (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);
652-
}
648+
return (RetrieveMetadataChangesResponse)connectionManager.Get().Execute(retrieveMetadataChangesRequest);
653649
}
654650

655651
#endregion
@@ -754,10 +750,15 @@ private List<string> FilterSource<T>(TextBox filterBox, ConcurrentBag<T> source)
754750
.Where(t => t.IsFilled())
755751
.Distinct();
756752

757-
return source
758-
.Where(e => filters.Any(f => Regex.IsMatch(e.Name, f)
759-
|| (e.DisplayName.IsFilled() && Regex.IsMatch(e.DisplayName, f)) || (e.Rename.IsFilled() && Regex.IsMatch(e.Rename, f))))
760-
.Select(e => e.Name).Distinct().ToList();
753+
return source
754+
.Where(e => filters.Any(f => Regex.IsMatch(e.Name, f)
755+
|| (e.DisplayName.IsFilled() && Regex.IsMatch(e.DisplayName.ToLower(), f))
756+
|| (e.Rename.IsFilled() && Regex.IsMatch(e.Rename.ToLower(), f))
757+
|| (e is Relations1NGridRow oneN && ((oneN.ToEntity.IsFilled() && Regex.IsMatch(oneN.ToEntity.ToLower(), f))
758+
|| (oneN.ToField.IsFilled() && Regex.IsMatch(oneN.ToField.ToLower(), f))))
759+
|| (e is RelationsN1GridRow nOne && ((nOne.ToEntity.IsFilled() && Regex.IsMatch(nOne.ToEntity.ToLower(), f))
760+
|| (nOne.FromField.IsFilled() && Regex.IsMatch(nOne.FromField.ToLower(), f))))))
761+
.Select(e => e.Name).Distinct().ToList();
761762
}
762763

763764
return null;

TemplateCodeGeneratorPlugin/Dialogues/Options.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using CrmCodeGenerator.VSPackage.Helpers;
1818
using Yagasoft.CrmCodeGenerator;
1919
using Yagasoft.CrmCodeGenerator.Connection;
20-
using Yagasoft.CrmCodeGenerator.Connection.OrgSvcs;
2120
using Yagasoft.CrmCodeGenerator.Helpers;
2221
using Yagasoft.CrmCodeGenerator.Models.Cache;
2322
using Yagasoft.CrmCodeGenerator.Models.Settings;
@@ -35,7 +34,7 @@ namespace CrmCodeGenerator.VSPackage.Dialogs
3534
/// </summary>
3635
public partial class Options : INotifyPropertyChanged
3736
{
38-
private readonly IConnectionManager<IDisposableOrgSvc> connectionManager;
37+
private readonly IConnectionManager connectionManager;
3938
private readonly MetadataCache metadataCache;
4039
private readonly WorkerHelper workerHelper;
4140

@@ -96,7 +95,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
9695

9796
#region Init
9897

99-
public Options(Settings settings, IConnectionManager<IDisposableOrgSvc> connectionManager, MetadataCache metadataCache,
98+
public Options(Settings settings, IConnectionManager connectionManager, MetadataCache metadataCache,
10099
WorkerHelper workerHelper)
101100
{
102101
InitializeComponent();

TemplateCodeGeneratorPlugin/Model/Constants.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ public static class Constants
44
{
55
public const string AppName = "Dynamics Template-based Code Generator";
66
public const string AppId = "xrmtoolbox-code-gen-plugin";
7-
public const string AppVersion = "2.2.2.1";
7+
public const string AppVersion = "2.3.1.1";
88

99
public const string SettingsVersion = "2.0.0.1";
1010

1111
public const string MinTemplateVersion = "2.0.0.1";
12-
public const string LatestTemplateVersion = "2.2.1.1";
12+
public const string LatestTemplateVersion = "2.3.1.1";
1313

1414
public const string MetaCacheMemKey = "ys_CrmGen_Meta_639156";
1515
public const string ConnCacheMemKey = "ys_CrmGen_Conn_185599";
@@ -18,6 +18,14 @@ public static class Constants
1818
" v" + AppVersion + "\r\n" +
1919
"~~~~~~~~~~\r\n" +
2020
@"
21+
>> IMPORTANT VERSION UPDATE <<
22+
- FIX: If you are using an unmodified template, please reset (button) the template to get the latest version; otherwise, backup yours, reset, and then using CodeCompare or a similar tool, check the updates.
23+
- REQUEST: Please report issues and improvement suggestions on the generator's GitHub repository. Use the 'Help' menu above to access the page.
24+
25+
* 2.3.1.1
26+
Improved: filtering feature now works over logical and display names, and renames
27+
Updated: latest custom libraries
28+
Fixed: template issues
2129
* 2.2.2.1
2230
Fixed: mishandling errors
2331
* 2.2.1.1

TemplateCodeGeneratorPlugin/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.2.1")]
36-
[assembly: AssemblyFileVersion("2.2.2.1")]
35+
[assembly: AssemblyVersion("2.3.1.1")]
36+
[assembly: AssemblyFileVersion("2.3.1.1")]

TemplateCodeGeneratorPlugin/TemplateCodeGeneratorPlugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
<HintPath>..\lib\Yagasoft.CrmCodeGenerator.dll</HintPath>
248248
</Reference>
249249
<Reference Include="Yagasoft.Libraries.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d99f90f6e31ed2df, processorArchitecture=MSIL">
250-
<HintPath>..\packages\Yagasoft.Libraries.Common.2.3.2\lib\net462\Yagasoft.Libraries.Common.dll</HintPath>
250+
<HintPath>..\packages\Yagasoft.Libraries.Common.2.4.5\lib\net462\Yagasoft.Libraries.Common.dll</HintPath>
251251
</Reference>
252252
</ItemGroup>
253253
<ItemGroup>

0 commit comments

Comments
 (0)