Skip to content

Commit 11bff40

Browse files
committed
Fixed: mishandling errors.
1 parent 90ef545 commit 11bff40

8 files changed

Lines changed: 128 additions & 98 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Join the chat at https://gitter.im/yagasoft/DynamicsCrm-TemplateBasedCodeGeneratorPlugin](https://badges.gitter.im/yagasoft/DynamicsCrm-TemplateBasedCodeGeneratorPlugin.svg)](https://gitter.im/yagasoft/DynamicsCrm-TemplateBasedCodeGeneratorPlugin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44

5-
### Version: 2.2.1.1
5+
### Version: 2.2.2.1
66
---
77

88
An XrmToolBox plugin that can be used to generate Early-bound code from a CRM Schema using a customisable T4 Template.
@@ -50,6 +50,8 @@ You can read a quick overview of the tool and its functionality [here](http://bl
5050

5151
## Changes
5252

53+
#### _v2.2.2.1 (2020-10-04)_
54+
+ Fixed: mishandling errors
5355
#### _v2.2.1.1 (2020-10-01)_
5456
+ Added: Filter Details window row filtering
5557
+ Fixed: generated code 'labels' syntax error

TemplateCodeGeneratorPlugin/Control/XrmMockGeneratorPluginControl.cs

Lines changed: 115 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
using System.ComponentModel;
66
using System.Data.Linq;
77
using System.Diagnostics;
8-
using System.Drawing;
98
using System.IO;
109
using System.Linq;
1110
using System.Text.RegularExpressions;
11+
using System.Windows;
1212
using System.Windows.Forms;
1313
using System.Windows.Threading;
1414
using CrmCodeGenerator.VSPackage.Dialogs;
@@ -24,6 +24,7 @@
2424
using Yagasoft.CrmCodeGenerator.Mapper;
2525
using Yagasoft.CrmCodeGenerator.Models.Cache;
2626
using Yagasoft.CrmCodeGenerator.Models.Mapper;
27+
using Yagasoft.CrmCodeGenerator.Models.Messages;
2728
using Yagasoft.CrmCodeGenerator.Models.Settings;
2829
using Yagasoft.Libraries.Common;
2930
using Yagasoft.TemplateCodeGeneratorPlugin.Helpers;
@@ -33,6 +34,8 @@
3334
using Yagasoft.TemplateCodeGeneratorPlugin.Model.ViewModels;
3435
using Yagasoft.TemplateCodeGeneratorPlugin.Templates;
3536
using Label = System.Windows.Forms.Label;
37+
using MessageBox = System.Windows.Forms.MessageBox;
38+
using Point = System.Drawing.Point;
3639

3740
#endregion
3841

@@ -1047,6 +1050,110 @@ private void GenerateCode()
10471050
Work =
10481051
(w, e) =>
10491052
{
1053+
Context context = null;
1054+
var isCancelled = false;
1055+
var isError = false;
1056+
1057+
BusyMessage<Style> MapperOnMessage(object o, MapperEventArgs args)
1058+
{
1059+
try
1060+
{
1061+
if (args.Exception == null)
1062+
{
1063+
var message = $"[Generator] {Regex.Replace(args.Message, "^>> ", "[DONE] ")}";
1064+
w.ReportProgress(args.Progress ?? -1, message);
1065+
}
1066+
}
1067+
catch
1068+
{
1069+
// ignored
1070+
}
1071+
1072+
return null;
1073+
}
1074+
1075+
void MapperOnStatusUpdate(object o, MapperEventArgs args)
1076+
{
1077+
try
1078+
{
1079+
switch (args.Status)
1080+
{
1081+
case MapperStatus.Cancelled:
1082+
isCancelled = true;
1083+
UnregisterMapperEvents();
1084+
break;
1085+
1086+
case MapperStatus.Error:
1087+
isError = true;
1088+
UnregisterMapperEvents();
1089+
var message = args.Exception.Message;
1090+
var inner = args.Exception?.InnerException;
1091+
1092+
if (inner?.Message.IsFilled() == true)
1093+
{
1094+
message += $" | {inner.Message}";
1095+
}
1096+
1097+
if (args.Exception is NullReferenceException)
1098+
{
1099+
message = $"Generator failed. Clear the cache and try again.";
1100+
}
1101+
1102+
MessageBox.Show(message, "Generation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1103+
break;
1104+
1105+
case MapperStatus.Finished:
1106+
UnregisterMapperEvents();
1107+
context = mapper.Context;
1108+
context.Namespace = settings.Namespace;
1109+
context.SplitFiles = settings.SplitFiles;
1110+
context.SplitContractFiles = settings.SplitContractFiles;
1111+
context.UseDisplayNames = settings.UseDisplayNames;
1112+
context.IsUseCustomDictionary = settings.IsUseCustomDictionary;
1113+
context.IsUseCustomEntityReference = settings.IsUseCustomEntityReference;
1114+
context.IsAddEntityAnnotations = settings.IsAddEntityAnnotations;
1115+
context.IsAddContractAnnotations = settings.IsAddContractAnnotations;
1116+
context.IsGenerateLoadPerRelation = settings.IsGenerateLoadPerRelation;
1117+
context.IsGenerateEnumNames = settings.IsGenerateEnumNames;
1118+
context.IsGenerateEnumLabels = settings.IsGenerateEnumLabels;
1119+
context.IsGenerateFieldSchemaNames = settings.IsGenerateFieldSchemaNames;
1120+
context.IsGenerateFieldLabels = settings.IsGenerateFieldLabels;
1121+
context.IsGenerateRelationNames = settings.IsGenerateRelationNames;
1122+
context.IsImplementINotifyProperty = settings.IsImplementINotifyProperty;
1123+
context.GenerateGlobalActions = settings.GenerateGlobalActions;
1124+
context.PluginMetadataEntities = settings.PluginMetadataEntitiesSelected.ToList();
1125+
context.OptionsetLabelsEntities = settings.OptionsetLabelsEntitiesSelected.ToList();
1126+
context.LookupLabelsEntities = settings.LookupLabelsEntitiesSelected.ToList();
1127+
context.JsEarlyBoundEntities = settings.JsEarlyBoundEntitiesSelected.ToList();
1128+
context.EarlyBoundFilteredSelected = settings.EarlyBoundFilteredSelected.ToList();
1129+
context.SelectedActions = settings.SelectedActions;
1130+
context.ClearMode = settings.ClearMode;
1131+
context.SelectedEntities = settings.EntitiesSelected.ToArray();
1132+
context.IsGenerateAlternateKeys = settings.IsGenerateAlternateKeys;
1133+
context.IsUseCustomTypeForAltKeys = settings.IsUseCustomTypeForAltKeys;
1134+
context.IsMakeCrmEntitiesJsonFriendly = settings.IsMakeCrmEntitiesJsonFriendly;
1135+
context.CrmEntityProfiles = settings.CrmEntityProfiles;
1136+
break;
1137+
}
1138+
}
1139+
catch
1140+
{
1141+
// ignored
1142+
}
1143+
}
1144+
1145+
void RegisterMapperEvents()
1146+
{
1147+
mapper.Message += MapperOnMessage;
1148+
mapper.StatusUpdate += MapperOnStatusUpdate;
1149+
}
1150+
1151+
void UnregisterMapperEvents()
1152+
{
1153+
mapper.Message -= MapperOnMessage;
1154+
mapper.StatusUpdate -= MapperOnStatusUpdate;
1155+
}
1156+
10501157
try
10511158
{
10521159
w.ReportProgress(0, $"Gathering metadata from server ...");
@@ -1055,98 +1162,9 @@ private void GenerateCode()
10551162

10561163
mapper = new Mapper(settings, connectionManager, metadataCache);
10571164

1058-
Context context = null;
1059-
var isCancelled = false;
1060-
1061-
mapper.Message
1062-
+= (o, args) =>
1063-
{
1064-
try
1065-
{
1066-
if (args.Exception == null)
1067-
{
1068-
var message = $"[Generator] {Regex.Replace(args.Message, "^>> ", "[DONE] ")}";
1069-
w.ReportProgress(args.Progress ?? -1, message);
1070-
}
1071-
}
1072-
catch
1073-
{
1074-
// ignored
1075-
}
1076-
1077-
return null;
1078-
};
1079-
1080-
mapper.StatusUpdate
1081-
+= (o, args) =>
1082-
{
1083-
try
1084-
{
1085-
switch (args.Status)
1086-
{
1087-
case MapperStatus.Cancelled:
1088-
isCancelled = true;
1089-
break;
1090-
1091-
case MapperStatus.Error:
1092-
var message = args.Exception.Message;
1093-
var inner = args.Exception?.InnerException;
1094-
1095-
if (inner?.Message.IsFilled() == true)
1096-
{
1097-
message += $" | {inner.Message}";
1098-
}
1099-
1100-
if (args.Exception is NullReferenceException)
1101-
{
1102-
message = $"Generator failed. Clear the cache and try again.";
1103-
}
1104-
1105-
MessageBox.Show(message, "Generation Error",
1106-
MessageBoxButtons.OK, MessageBoxIcon.Error);
1107-
break;
1108-
1109-
case MapperStatus.Finished:
1110-
context = mapper.Context;
1111-
context.Namespace = settings.Namespace;
1112-
context.SplitFiles = settings.SplitFiles;
1113-
context.SplitContractFiles = settings.SplitContractFiles;
1114-
context.UseDisplayNames = settings.UseDisplayNames;
1115-
context.IsUseCustomDictionary = settings.IsUseCustomDictionary;
1116-
context.IsUseCustomEntityReference = settings.IsUseCustomEntityReference;
1117-
context.IsAddEntityAnnotations = settings.IsAddEntityAnnotations;
1118-
context.IsAddContractAnnotations = settings.IsAddContractAnnotations;
1119-
context.IsGenerateLoadPerRelation = settings.IsGenerateLoadPerRelation;
1120-
context.IsGenerateEnumNames = settings.IsGenerateEnumNames;
1121-
context.IsGenerateEnumLabels = settings.IsGenerateEnumLabels;
1122-
context.IsGenerateFieldSchemaNames = settings.IsGenerateFieldSchemaNames;
1123-
context.IsGenerateFieldLabels = settings.IsGenerateFieldLabels;
1124-
context.IsGenerateRelationNames = settings.IsGenerateRelationNames;
1125-
context.IsImplementINotifyProperty = settings.IsImplementINotifyProperty;
1126-
context.GenerateGlobalActions = settings.GenerateGlobalActions;
1127-
context.PluginMetadataEntities = settings.PluginMetadataEntitiesSelected.ToList();
1128-
context.OptionsetLabelsEntities = settings.OptionsetLabelsEntitiesSelected.ToList();
1129-
context.LookupLabelsEntities = settings.LookupLabelsEntitiesSelected.ToList();
1130-
context.JsEarlyBoundEntities = settings.JsEarlyBoundEntitiesSelected.ToList();
1131-
context.EarlyBoundFilteredSelected = settings.EarlyBoundFilteredSelected.ToList();
1132-
context.SelectedActions = settings.SelectedActions;
1133-
context.ClearMode = settings.ClearMode;
1134-
context.SelectedEntities = settings.EntitiesSelected.ToArray();
1135-
context.IsGenerateAlternateKeys = settings.IsGenerateAlternateKeys;
1136-
context.IsUseCustomTypeForAltKeys = settings.IsUseCustomTypeForAltKeys;
1137-
context.IsMakeCrmEntitiesJsonFriendly = settings.IsMakeCrmEntitiesJsonFriendly;
1138-
context.CrmEntityProfiles = settings.CrmEntityProfiles;
1139-
break;
1140-
}
1141-
}
1142-
catch
1143-
{
1144-
// ignored
1145-
}
1146-
};
1147-
11481165
try
11491166
{
1167+
RegisterMapperEvents();
11501168
mapper.MapContext();
11511169
}
11521170
catch (OperationCanceledException)
@@ -1160,6 +1178,11 @@ private void GenerateCode()
11601178
return;
11611179
}
11621180

1181+
if (isError)
1182+
{
1183+
return;
1184+
}
1185+
11631186
if (isCancelled)
11641187
{
11651188
uiHelper.ShowToast("Generation cancelled.");
@@ -1193,6 +1216,7 @@ private void GenerateCode()
11931216
}
11941217
finally
11951218
{
1219+
UnregisterMapperEvents();
11961220
InvokeSafe(() => buttonCancel.Hide());
11971221
EnableTool();
11981222
}

TemplateCodeGeneratorPlugin/Model/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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.1.1";
7+
public const string AppVersion = "2.2.2.1";
88

99
public const string SettingsVersion = "2.0.0.1";
1010

@@ -18,6 +18,8 @@ public static class Constants
1818
" v" + AppVersion + "\r\n" +
1919
"~~~~~~~~~~\r\n" +
2020
@"
21+
* 2.2.2.1
22+
Fixed: mishandling errors
2123
* 2.2.1.1
2224
Added: Filter Details window row filtering
2325
Fixed: generated code 'labels' syntax error

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.1.1")]
36-
[assembly: AssemblyFileVersion("2.2.1.1")]
35+
[assembly: AssemblyVersion("2.2.2.1")]
36+
[assembly: AssemblyFileVersion("2.2.2.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.1\lib\net462\Yagasoft.Libraries.Common.dll</HintPath>
250+
<HintPath>..\packages\Yagasoft.Libraries.Common.2.3.2\lib\net462\Yagasoft.Libraries.Common.dll</HintPath>
251251
</Reference>
252252
</ItemGroup>
253253
<ItemGroup>

TemplateCodeGeneratorPlugin/TemplateCodeGeneratorPlugin.nuspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<metadata>
55
<id>Template-based-CRM-Code-Generator-Plugin</id>
66
<title>Early-bound Template-based Code Generator</title>
7-
<version>2.2.1.1</version>
7+
<version>2.2.2.1</version>
88
<authors>Ahmed Elsawalhy</authors>
99
<owners>Ahmed Elsawalhy</owners>
1010
<projectUrl>https://github.com/yagasoft/DynamicsCrm-Template-based-Code-Generator-Plugin</projectUrl>
@@ -42,6 +42,8 @@
4242
<copyright>Copyright 2020 Ahmed Elsawalhy</copyright>
4343
<tags>XrmToolBox plugin,tool,CRM,Dynamics,365,yagasoft,xrm,early,bound,code,generate,generator,t4,template</tags>
4444
<releaseNotes>
45+
* 2.2.2.1
46+
Fixed: mishandling errors
4547
* 2.2.1.1
4648
Added: Filter Details window row filtering
4749
Fixed: generated code 'labels' syntax error

TemplateCodeGeneratorPlugin/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net462" />
2222
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net462" />
2323
<package id="XrmToolBoxPackage" version="1.2020.2.36" targetFramework="net462" />
24-
<package id="Yagasoft.Libraries.Common" version="2.3.1" targetFramework="net462" developmentDependency="true" />
24+
<package id="Yagasoft.Libraries.Common" version="2.3.2" targetFramework="net462" developmentDependency="true" />
2525
</packages>

lib/Yagasoft.CrmCodeGenerator.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)