Skip to content

Commit

Permalink
Allow StateCode to be Enum Specifically #393
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllabar committed Apr 6, 2023
1 parent 6576bac commit 5d69da0
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 78 deletions.
4 changes: 3 additions & 1 deletion DLaB.EarlyBoundGenerator/EarlyBoundGeneratorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private void EarlyBoundGenerator_Load(object sender, EventArgs e)
SetConnectionSettingOnLoad();
HydrateUiFromSettings(ConnectionSettings.FullSettingsPath);
Telemetry.Enabled = Options.Instance.AllowLogUsage ?? true;
Telemetry.InitAiConfig("3a079617-6a46-4c46-8db3-719f7d2f51c7");
// Totally security by obscurity
var key = new Guid(Convert.FromBase64String("F5YHOkZqRky" + "Ns3GffS9Rxw=="));
Telemetry.InitAiConnection($"InstrumentationKey={key};IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/");
FormLoaded = true;
}

Expand Down
6 changes: 3 additions & 3 deletions DLaB.EarlyBoundGeneratorV2.Logic/Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ private static string GetJsonConfigPath(EarlyBoundGeneratorConfig earlyBoundGene
/// <summary>
/// The Extensions to the Pac Model Builder will live in a different assembly. To ensure that users can run against the PAC commandline, reset the namespace to the PAC version
/// </summary>
public void RevertEarlyBoundGeneratorSettings()
public void RemoveXrmToolBoxPluginPath()
{
var path = GetJsonConfigPath(EarlyBoundGeneratorConfig);

var contents = EarlyBoundGeneratorConfig.ReplaceEarlyBoundAssemblyName(File.ReadAllText(path));
var contents = File.ReadAllLines(path);

File.WriteAllLines(path, contents.Split(new [] { Environment.NewLine }, StringSplitOptions.None).Where(l => !l.TrimStart().StartsWith("\"xrmToolBoxPluginPath\"")));
File.WriteAllLines(path, contents.Where(l => !l.TrimStart().StartsWith("\"xrmToolBoxPluginPath\"")));
}

private void Speak(string words)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace DLaB.EarlyBoundGeneratorV2.Settings
[XmlRoot("Config")]
public class EarlyBoundGeneratorConfig
{
public const string EarlyBoundGeneratorAssembly = "DLaB.EarlyBoundGeneratorV2";
public const string ModelBuilderAssembly = "DLaB.ModelBuilderExtensions";
private const string EarlyBoundGeneratorV2Name= "DLaB.EarlyBoundGeneratorV2";

#region Properties

Expand Down Expand Up @@ -305,7 +304,7 @@ private void UpdateObsoleteSettings(POCO.Config poco, POCO.ExtensionConfig pocoC

if (!string.IsNullOrWhiteSpace(pocoConfig.CamelCaseNamesDictionaryRelativePath) && pocoConfig.CamelCaseNamesDictionaryRelativePath.Contains(@"DLaB.EarlyBoundGenerator\"))
{
pocoConfig.CamelCaseNamesDictionaryRelativePath = pocoConfig.CamelCaseNamesDictionaryRelativePath.Replace(@"DLaB.EarlyBoundGenerator\", $@"{EarlyBoundGeneratorAssembly}\");
pocoConfig.CamelCaseNamesDictionaryRelativePath = pocoConfig.CamelCaseNamesDictionaryRelativePath.Replace(@"DLaB.EarlyBoundGenerator\", $@"{EarlyBoundGeneratorV2Name}\");
}
pocoConfig.CleanupCrmSvcUtilLocalOptionSets = true;
pocoConfig.GenerateINotifyPattern = true;
Expand Down Expand Up @@ -593,28 +592,22 @@ internal struct BuilderSettingsJsonNames

public void PopulateBuilderProperties(Dictionary<string, JsonProperty> properties)
{
var isXrmToolBoxEarlyBound = typeof(ExtensionConfig).AssemblyQualifiedName?.StartsWith($"{EarlyBoundGeneratorAssembly}.Settings.ExtensionConfig, {EarlyBoundGeneratorAssembly},") ?? true;
var defaultSettings = GetDefault();

SetModelBuilderServiceProperty(BuilderSettingsJsonNames.CodeCustomizationService, CodeCustomizationService);
SetModelBuilderServiceProperty(BuilderSettingsJsonNames.CodeGenerationService, CodeGenerationService);
SetModelBuilderServiceProperty(BuilderSettingsJsonNames.CodeWriterFilterService, CodeWriterFilterService);
SetModelBuilderServiceProperty(BuilderSettingsJsonNames.CodeWriterMessageFilterService, CodeWriterMessageFilterService);
SetModelBuilderServiceProperty(BuilderSettingsJsonNames.MetadataProviderService, MetadataProviderService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.CodeCustomizationService, CodeCustomizationService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.CodeGenerationService, CodeGenerationService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.CodeWriterFilterService, CodeWriterFilterService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.CodeWriterMessageFilterService, CodeWriterMessageFilterService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.MetadataProviderService, MetadataProviderService);

SetOutputFolderProperty(BuilderSettingsJsonNames.EntityTypesFolder, EntityTypesFolder, defaultSettings.EntityTypesFolder);
properties.SetJsonProperty(BuilderSettingsJsonNames.GenerateActions, GenerateMessages);
SetOutputFolderProperty(BuilderSettingsJsonNames.MessagesTypesFolder, MessageTypesFolder, defaultSettings.MessageTypesFolder, !GenerateMessages);
properties.SetJsonProperty(BuilderSettingsJsonNames.Namespace, Namespace);
SetModelBuilderServiceProperty(BuilderSettingsJsonNames.NamingService, NamingService);
properties.SetJsonPropertyIfPopulated(BuilderSettingsJsonNames.NamingService, NamingService);
SetOutputFolderProperty(BuilderSettingsJsonNames.OptionSetsTypesFolder, OptionSetsTypesFolder, defaultSettings.OptionSetsTypesFolder);
properties.SetJsonProperty(BuilderSettingsJsonNames.ServiceContextName, ServiceContextName);

void SetModelBuilderServiceProperty(string propertyName, string typeName)
{
properties.SetJsonPropertyIfPopulated(propertyName, isXrmToolBoxEarlyBound ? ReplaceModelBuilderAssemblyName(typeName) : typeName);
}

void SetOutputFolderProperty(string propertyName, string typeName, string @default, bool remove = false)
{
if (remove)
Expand All @@ -630,19 +623,6 @@ void SetOutputFolderProperty(string propertyName, string typeName, string @defau
properties.SetJsonPropertyIfPopulated(propertyName, typeName.Contains(".cs") ? @default : typeName);
}
}

/// <summary>
/// Handle updating the Assembly name of Services when running via API dll with reference to DLaB.ModelBuilderExtensions vs the XTB. DLaB.ModelBuilderExtensions will be ILMerged into the plugin dll itself.
/// </summary>
internal string ReplaceModelBuilderAssemblyName(string serviceName)
{
return serviceName.Replace($",{ModelBuilderAssembly}", $",{EarlyBoundGeneratorAssembly}");
}

internal string ReplaceEarlyBoundAssemblyName(string serviceName)
{
return serviceName.Replace($",{EarlyBoundGeneratorAssembly}", $",{ModelBuilderAssembly}");
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions DLaB.EarlyBoundGeneratorV2.Logic/Settings/ExtensionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ public class ExtensionConfig
/// </summary>
public bool UseCrmSvcUtilStateEnumNamingConvention { get; set; }
/// <summary>
/// The CrmSvcUtil generates state codes as enums properties. This allows for generating just this property as an enum. Only valid when Replace Option Set Properties with Enum is false.
/// </summary>
public bool UseEnumForStateCodes { get; set; }
/// <summary>
/// Creates Local OptionSets Using the Deprecated Naming Convention. prefix_oobentityname_prefix_attribute
/// </summary>
/// <value>
Expand Down Expand Up @@ -322,6 +326,7 @@ public static ExtensionConfig GetDefault()
TokenCapitalizationOverrides = "AccessTeam|ActiveState|AssignedTo|BusinessAs|CardUci|DefaultOnCase|EmailAnd|EmailSend|EmailSender|FeatureSet|FedEx|ForAn|Geronimo|IsMsTeams|IsPaiEnabled|IsSopIntegration|MsDynCe_|MsDynMkt_|MsDyUsd|O365Admin|OcSkillIdentMlModel|OnHold|OrderId|OwnerOnAssign|PauseStates|PredictiveAddress|PartiesOnEmail|ParticipatesIn|SentOn|SettingsAndSummary|SlaId|SlaKpi|SyncOptIn|Timeout|TradeShow|UserPuid|VoiceMail",
TransliterationRelativePath = @"DLaB.EarlyBoundGeneratorV2\alphabets",
UseCrmSvcUtilStateEnumNamingConvention = false,
UseEnumForStateCodes = false,
UseLogicalNames = false,
UseTfsToCheckoutFiles = false,
WaitForAttachedDebugger = false,
Expand Down Expand Up @@ -385,6 +390,7 @@ public void SetPopulatedValues(POCO.ExtensionConfig poco)
TokenCapitalizationOverrides = GetValueOrDefault(poco.TokenCapitalizationOverrides, TokenCapitalizationOverrides);
TransliterationRelativePath = GetValueOrDefault(poco.TransliterationRelativePath, TransliterationRelativePath);
UseCrmSvcUtilStateEnumNamingConvention = poco.UseCrmSvcUtilStateEnumNamingConvention ?? UseCrmSvcUtilStateEnumNamingConvention;
UseEnumForStateCodes = poco.UseEnumForStateCodes ?? UseEnumForStateCodes;
UseLogicalNames = poco.UseLogicalNames ?? UseLogicalNames;
UseTfsToCheckoutFiles = poco.UseTfsToCheckoutFiles ?? UseTfsToCheckoutFiles;
WaitForAttachedDebugger = poco.WaitForAttachedDebugger ?? WaitForAttachedDebugger;
Expand Down Expand Up @@ -450,6 +456,7 @@ public void WriteDLaBModelBuilderProperties(Utf8JsonWriter writer, EarlyBoundGen
writer.AddProperty(nameof(TransliterationRelativePath), TransliterationRelativePath);
writer.AddProperty(nameof(UseLogicalNames), UseLogicalNames);
writer.AddProperty(nameof(UseCrmSvcUtilStateEnumNamingConvention), UseCrmSvcUtilStateEnumNamingConvention);
AddOptionalBoolProperty(nameof(UseEnumForStateCodes), UseEnumForStateCodes, generateOptionSetProperties && !ReplaceOptionSetPropertiesWithEnum);
writer.AddProperty(nameof(UseTfsToCheckoutFiles), UseTfsToCheckoutFiles);
writer.AddProperty(nameof(WaitForAttachedDebugger), WaitForAttachedDebugger);

Expand Down Expand Up @@ -565,6 +572,7 @@ public class ExtensionConfig
public string TokenCapitalizationOverrides { get; set; }
public string TransliterationRelativePath { get; set; }
public bool? UseCrmSvcUtilStateEnumNamingConvention { get; set; }
public bool? UseEnumForStateCodes { get; set; }
public bool? UseLogicalNames { get; set; }
public bool? UseTfsToCheckoutFiles { get; set; }
public bool? WaitForAttachedDebugger { get; set; }
Expand Down
15 changes: 0 additions & 15 deletions DLaB.EarlyBoundGeneratorV2/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WeifenLuo.WinFormsUI.Docking" publicKeyToken="5cded1a1a0a7b481" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WeifenLuo.WinFormsUI.Docking.ThemeVS2015" publicKeyToken="5cded1a1a0a7b481" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="McTools.Xrm.Connection" publicKeyToken="96037217801d9658" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2021.1.39" newVersion="1.2021.1.39" />
Expand Down Expand Up @@ -88,11 +80,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<applicationSettings>
<DLaB.EarlyBoundGenerator.Properties.Settings>
<setting name="AppInsightsInstrumentationKey" serializeAs="String">
<value>3a079617-6a46-4c46-8db3-719f7d2f51c7</value>
</setting>
</DLaB.EarlyBoundGenerator.Properties.Settings>
</applicationSettings>
</configuration>
6 changes: 0 additions & 6 deletions DLaB.EarlyBoundGeneratorV2/DLaB.EarlyBoundGeneratorV2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="WeifenLuo.WinFormsUI.Docking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5cded1a1a0a7b481, processorArchitecture=MSIL">
<HintPath>..\packages\DockPanelSuite.3.1.0\lib\net40\WeifenLuo.WinFormsUI.Docking.dll</HintPath>
</Reference>
<Reference Include="WeifenLuo.WinFormsUI.Docking.ThemeVS2015, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5cded1a1a0a7b481, processorArchitecture=MSIL">
<HintPath>..\packages\DockPanelSuite.ThemeVS2015.3.1.0\lib\net40\WeifenLuo.WinFormsUI.Docking.ThemeVS2015.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="XrmToolBox, Version=1.2022.10.58, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\XrmToolBoxPackage.1.2022.10.58\lib\net462\XrmToolBox.exe</HintPath>
Expand Down
6 changes: 4 additions & 2 deletions DLaB.EarlyBoundGeneratorV2/EarlyBoundGeneratorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private void EarlyBoundGenerator_Load(object sender, EventArgs e)
SetConnectionSettingOnLoad();
HydrateUiFromSettings(ConnectionSettings.FullSettingsPath);
Telemetry.Enabled = Options.Instance.AllowLogUsage ?? true;
Telemetry.InitAiConfig("3a079617-6a46-4c46-8db3-719f7d2f51c7");
// Totally security by obscurity
var key = new Guid(Convert.FromBase64String("F5YHOkZqRky" + "Ns3GffS9Rxw=="));
Telemetry.InitAiConnection($"InstrumentationKey={key};IngestionEndpoint=https://westus2-1.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/");
FormLoaded = true;
Logger.Instance.OnLog -= OnLoadLog;
}
Expand Down Expand Up @@ -246,7 +248,7 @@ public void CreateCode()
w.ReportProgress(99, "Generation Complete!");
if (settings.UpdateBuilderSettingsJson)
{
generator.RevertEarlyBoundGeneratorSettings();
generator.RemoveXrmToolBoxPluginPath();
}
}
catch (InvalidOperationException ex)
Expand Down
20 changes: 13 additions & 7 deletions DLaB.EarlyBoundGeneratorV2/EarlyBoundGeneratorV2.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>DLaB.Xrm.EarlyBoundGeneratorV2</id>
<version>2.2023.4.5</version>
<version>2.2023.4.6</version>
<title>Early Bound Generator V2</title>
<authors>Daryl LaBar</authors>
<owners>Daryl LaBar</owners>
Expand All @@ -11,7 +11,11 @@
<projectUrl>https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Generates Early Bound Entities/Option Sets/Actions. Uses CrmSvcUtil from the SDK, and shows command line used to create the classes.</description>
<releaseNotes>V2.2023.4.5
<releaseNotes>V2.2023.4.6
Allow StateCode to be Enum Specifically #393
Enum Postfixed Properties are not getting generated #392

V2.2023.4.5
The Updated Settings Are Not Reflected Immediately Until the XrmToolBox is Closed And Reopened #390
Don't write message filter if not generating messages #389
UseCrmSvcUtilStateEnumNamingConvention gets reset #388
Expand Down Expand Up @@ -69,11 +73,13 @@ Fix for Deleting files Deletes from Temporary Folder, not output folder #318
</dependencies>
</metadata>
<files>
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2.dll" target="lib\net462\plugins" />
<file src="bin\Release\DLaB.ModelBuilderExtensions.dll" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\DLaB.ModelBuilderExtensions.dll" />
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2.dll" target="lib\net462\plugins" />
<file src="bin\Release\DLaB.ModelBuilderExtensions.dll" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\DLaB.ModelBuilderExtensions.dll" />
<file src="bin\Release\Microsoft.AI.ServerTelemetryChannel.dll" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\Microsoft.AI.ServerTelemetryChannel.dll" />
<file src="bin\Release\Microsoft.ApplicationInsights.dll" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\Microsoft.ApplicationInsights.dll" />
<file src="bin\Release\Microsoft.PowerPlatform.Dataverse.ModelBuilderLib.dll" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\Microsoft.PowerPlatform.Dataverse.ModelBuilderLib.dll" />
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2\*.*" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2" />
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2\alphabets\*.*" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\alphabets" />
<file src="bin\Release\Images\DLaB_Dynamics_Logo_Square_32x32.png" target="images\" />
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2\*.*" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2" />
<file src="bin\Release\DLaB.EarlyBoundGeneratorV2\alphabets\*.*" target="lib\net462\plugins\DLaB.EarlyBoundGeneratorV2\alphabets" />
<file src="bin\Release\Images\DLaB_Dynamics_Logo_Square_32x32.png" target="images\" />
</files>
</package>
4 changes: 2 additions & 2 deletions DLaB.EarlyBoundGeneratorV2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2023.4.5")]
[assembly: AssemblyFileVersion("2.2023.4.5")]
[assembly: AssemblyVersion("2.2023.4.6")]
[assembly: AssemblyFileVersion("2.2023.4.6")]
9 changes: 9 additions & 0 deletions DLaB.EarlyBoundGeneratorV2/Settings/SettingsMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ public string ServiceContextName
set => Config.ServiceContextName = value;
}

[Category("2 - Entities")]
[DisplayName("Use Enum For State Codes")]
[Description("The CrmSvcUtil generates state codes as enums properties. This allows for generating just this property as an enum. Only valid when Replace Option Set Properties with Enum is false.")]
public bool UseEnumForStateCodes
{
get => Config.ExtensionConfig.UseEnumForStateCodes;
set => Config.ExtensionConfig.UseEnumForStateCodes = value;
}

#endregion Entities

#region Global
Expand Down
Loading

0 comments on commit 5d69da0

Please sign in to comment.