Skip to content

Commit

Permalink
Copy the command-line used to generate the tool
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
BetimBeja committed Jan 6, 2021
1 parent 6137da1 commit bf792f8
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 88 deletions.
37 changes: 19 additions & 18 deletions AlbanianXrm.Common.Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
{
internal static class Constants
{
public const string CONSOLE_METADATA = "[AlbanianXrm.EarlyBound:Metadata]";
public const string CONSOLE_ENDSTREAM = "[AlbanianXrm.EarlyBound:EndStream]";
public const string CONSOLE_METADATA = ENVIRONMENT_VARIABLE_PREFIX + "[AlbanianXrm.EarlyBound:Metadata]";
public const string CONSOLE_ENDSTREAM = ENVIRONMENT_VARIABLE_PREFIX + "[AlbanianXrm.EarlyBound:EndStream]";

public const string ENVIRONMENT_ENTITIES = "AlbanianXrm.EarlyBound:Entities";
public const string ENVIRONMENT_ALL_ATTRIBUTES = "AlbanianXrm.EarlyBound:AllAttributes";
public const string ENVIRONMENT_ALL_RELATIONSHIPS = "AlbanianXrm.EarlyBound:AllRelationships";
public const string ENVIRONMENT_ENTITY_ATTRIBUTES = "AlbanianXrm.EarlyBound:Attributes:{0}";
public const string ENVIRONMENT_RELATIONSHIPS1N = "AlbanianXrm.EarlyBound:Relationships1N:{0}";
public const string ENVIRONMENT_RELATIONSHIPSN1 = "AlbanianXrm.EarlyBound:RelationshipsN1:{0}";
public const string ENVIRONMENT_RELATIONSHIPSNN = "AlbanianXrm.EarlyBound:RelationshipsNN:{0}";
public const string ENVIRONMENT_REMOVEPROPERTYCHANGED = "AlbanianXrm.EarlyBound:RemovePropertyChanged";
public const string ENVIRONMENT_ATTACHDEBUGGER = "AlbanianXrm.EarlyBound:AttachDebugger";
public const string ENVIRONMENT_CACHEMEATADATA = "AlbanianXrm.EarlyBound:CacheMetadata";
public const string ENVIRONMENT_OPTIONSETENUMS = "AlbanianXrm.EarlyBound:OptionSetEnums";
public const string ENVIRONMENT_TWOOPTIONS = "AlbanianXrm.EarlyBound:TwoOptions";
public const string ENVIRONMENT_OPTIONSETENUMPROPERTIES = "AlbanianXrm.EarlyBound:OptionSetEnumProperties";
public const string ENVIRONMENT_REMOVEPUBLISHER = "AlbanianXrm.EarlyBound:RemovePublisher";
public const string ENVIRONMENT_GENERATEXML = "AlbanianXrm.EarlyBound:GenerateXML";
public const string ENVIRONMENT_ATTRIBUTECONSTANTS = "AlbanianXrm.EarlyBound:GenerateAttributeConstants";
public const string ENVIRONMENT_VARIABLE_PREFIX = "AlbanianXrm.EarlyBound:";
public const string ENVIRONMENT_ENTITIES = ENVIRONMENT_VARIABLE_PREFIX + "Entities";
public const string ENVIRONMENT_ALL_ATTRIBUTES = ENVIRONMENT_VARIABLE_PREFIX + "AllAttributes";
public const string ENVIRONMENT_ALL_RELATIONSHIPS = ENVIRONMENT_VARIABLE_PREFIX + "AllRelationships";
public const string ENVIRONMENT_ENTITY_ATTRIBUTES = ENVIRONMENT_VARIABLE_PREFIX + "Attributes:{0}";
public const string ENVIRONMENT_RELATIONSHIPS1N = ENVIRONMENT_VARIABLE_PREFIX + "Relationships1N:{0}";
public const string ENVIRONMENT_RELATIONSHIPSN1 = ENVIRONMENT_VARIABLE_PREFIX + "RelationshipsN1:{0}";
public const string ENVIRONMENT_RELATIONSHIPSNN = ENVIRONMENT_VARIABLE_PREFIX + "RelationshipsNN:{0}";
public const string ENVIRONMENT_REMOVEPROPERTYCHANGED = ENVIRONMENT_VARIABLE_PREFIX + "RemovePropertyChanged";
public const string ENVIRONMENT_ATTACHDEBUGGER = ENVIRONMENT_VARIABLE_PREFIX + "AttachDebugger";
public const string ENVIRONMENT_CACHEMEATADATA = ENVIRONMENT_VARIABLE_PREFIX + "CacheMetadata";
public const string ENVIRONMENT_OPTIONSETENUMS = ENVIRONMENT_VARIABLE_PREFIX + "OptionSetEnums";
public const string ENVIRONMENT_TWOOPTIONS = ENVIRONMENT_VARIABLE_PREFIX + "TwoOptions";
public const string ENVIRONMENT_OPTIONSETENUMPROPERTIES = ENVIRONMENT_VARIABLE_PREFIX + "OptionSetEnumProperties";
public const string ENVIRONMENT_REMOVEPUBLISHER = ENVIRONMENT_VARIABLE_PREFIX + "RemovePublisher";
public const string ENVIRONMENT_GENERATEXML = ENVIRONMENT_VARIABLE_PREFIX + "GenerateXML";
public const string ENVIRONMENT_ATTRIBUTECONSTANTS = ENVIRONMENT_VARIABLE_PREFIX + "GenerateAttributeConstants";

public const string EntityLogicalNameAttributeType = "Microsoft.Xrm.Sdk.Client.EntityLogicalNameAttribute";
public const string AttributeLogicalNameAttributeType = "Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute";
Expand Down
2 changes: 1 addition & 1 deletion AlbanianXrm.EarlyBound/AlbanianXrm.EarlyBound.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@
</ItemGroup>
<Import Project="..\AlbanianXrm.Common.Shared\AlbanianXrm.Common.Shared.projitems" Label="Shared" />
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="IF NOT EXIST $(TargetDir)XrmToolBox mkdir $(TargetDir)XrmToolBox&#xD;&#xA;IF NOT EXIST $(TargetDir)XrmToolBox\Plugins mkdir $(TargetDir)XrmToolBox\Plugins&#xD;&#xA;IF NOT EXIST $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound mkdir $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound&#xD;&#xA;move /Y $(TargetDir)ILMerge\AlbanianXrm.EarlyBound.dll $(TargetDir)XrmToolBox\Plugins &#xD;&#xA;move /Y $(TargetDir)AlbanianXrm.CrmSvcUtilExtensions.dll $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\ &#xD;&#xA;move /Y $(TargetDir)Microsoft.IO.RecyclableMemoryStream.dll $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\&#xD;&#xA;&#xD;&#xA;del &quot;$(TargetDir)AlbanianXrm.EarlyBound.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)AlbanianXrm.ForrestSerializer.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)CrmSvcUtil.exe&quot;&#xD;&#xA;del &quot;$(TargetDir)CrmSvcUtil.exe.config&quot;&#xD;&#xA;del &quot;$(TargetDir)CrmSvcUtil.xml&quot;&#xD;&#xA;del &quot;$(TargetDir)EnvDTE.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)stdole.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Core.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Data.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.DataSource.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Grid.Base.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Grid.Windows.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.GridCommon.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Licensing.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.SfDataGrid.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.SfInput.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.SfListView.WinForms.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Shared.Base.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Shared.Windows.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.SpellChecker.Base.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Tools.Base.dll&quot;&#xD;&#xA;del &quot;$(TargetDir)Syncfusion.Tools.Windows.dll&quot;&#xD;&#xA;&#xD;&#xA;IF &quot;$(ConfigurationName)&quot;==&quot;Debug&quot; (&#xD;&#xA; move /Y $(TargetDir)ILMerge\AlbanianXrm.EarlyBound.pdb $(TargetDir)XrmToolBox\Plugins &#xD;&#xA; move /Y $(TargetDir)AlbanianXrm.CrmSvcUtilExtensions.pdb $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\ &#xD;&#xA; move /Y $(TargetDir)Microsoft.IO.RecyclableMemoryStream.pdb $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\&#xD;&#xA;&#xD;&#xA; del &quot;$(TargetDir)AlbanianXrm.EarlyBound.pdb&quot;&#xD;&#xA; del &quot;$(TargetDir)AlbanianXrm.ForrestSerializer.pdb&quot;&#xD;&#xA;)" />
<Exec Command="IF NOT EXIST $(TargetDir)XrmToolBox mkdir $(TargetDir)XrmToolBox&#xD;&#xA;IF NOT EXIST $(TargetDir)XrmToolBox\Plugins mkdir $(TargetDir)XrmToolBox\Plugins&#xD;&#xA;IF NOT EXIST $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound mkdir $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound&#xD;&#xA;move /Y $(TargetDir)AlbanianXrm.CrmSvcUtilExtensions.dll $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\ &#xD;&#xA;move /Y $(TargetDir)Microsoft.IO.RecyclableMemoryStream.dll $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\&#xD;&#xA;del &quot;$(TargetDir)AlbanianXrm.EarlyBound.dll&quot;&#xD;&#xA;&#xD;&#xA;IF &quot;$(ConfigurationName)&quot;==&quot;Debug&quot; (&#xD;&#xA; move /Y $(TargetDir)AlbanianXrm.CrmSvcUtilExtensions.pdb $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\ &#xD;&#xA; move /Y $(TargetDir)Microsoft.IO.RecyclableMemoryStream.pdb $(TargetDir)XrmToolBox\Plugins\AlbanianXrm.EarlyBound\&#xD;&#xA;&#xD;&#xA; del &quot;$(TargetDir)AlbanianXrm.EarlyBound.pdb&quot;&#xD;&#xA; del &quot;$(TargetDir)AlbanianXrm.ForrestSerializer.pdb&quot;&#xD;&#xA;)" />
</Target>
</Project>
3 changes: 2 additions & 1 deletion AlbanianXrm.EarlyBound/AlbanianXrm.EarlyBound.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<description>Generates Early Bound Entities. Uses CrmSvcUtil from the SDK which can be downloaded from any NuGet source (even local directory for isolated environments).</description>
<releaseNotes>
v$version$:
- Fixed bug. Error when decrypting password for authentication types different than username/password.
- Added option to allow the user to copy the command-line used to generate the tool.
* Please note that it is not possible to use the cache metadata option without XrmToolBox (from the command-line)

For older releases go here: https://github.com/albanian-xrm/Early-Bound/releases
</releaseNotes>
Expand Down
30 changes: 20 additions & 10 deletions AlbanianXrm.EarlyBound/Extensions/ConnectionDetailExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,29 @@ static class ConnectionDetailExtensions
private const int KEY_SIZE = 256;
private const int ITERATIONS = 2;

public static string GetConnectionStringWithoutPassword(this ConnectionDetail connection)
{
if (!connection.ClientSecretIsEmpty)
{
return $"AuthType=ClientSecret;url={connection.OriginalUrl};ClientId={connection.UserName};Secret=********;SkipDiscovery=true;";
}
return connection.GetConnectionString();
}

public static string GetConnectionStringWithPassword(this ConnectionDetail connection)
{
string password = "";

if (!connection.ClientSecretIsEmpty)
{
var prop = connection.GetType().GetProperty("ClientSecretEncrypted", BindingFlags.Instance | BindingFlags.Public);
if (prop != null && (string)prop.GetValue(connection) != null)
{
password = Decrypt((string)prop.GetValue(connection));
}
return connection.GetConnectionStringWithoutPassword().Replace("********", password);
}

var field = connection.GetType().GetField("userPassword", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null && (string)field.GetValue(connection)!=null)
{
Expand All @@ -35,17 +54,8 @@ public static string GetConnectionStringWithPassword(this ConnectionDetail conne
password = (string)prop.GetValue(connection);
}
}

if (string.IsNullOrEmpty(password))
{
var prop = connection.GetType().GetProperty("ClientSecretEncrypted", BindingFlags.Instance | BindingFlags.Public);
if (prop != null && (string)prop.GetValue(connection) != null)
{
password = Decrypt((string)prop.GetValue(connection));
}
}

return connection.GetConnectionString().Replace("********", password);
return connection.GetConnectionStringWithoutPassword().Replace("********", password);
}

private static string Decrypt(string cipherText)
Expand Down
30 changes: 30 additions & 0 deletions AlbanianXrm.EarlyBound/Extensions/DatabindExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlbanianXrm.EarlyBound.Extensions
{
static class DatabindExtensions
{
public static Binding Bind<T, TSource, TProperty>(this T target, Expression<Func<T, TProperty>> targetProperty, TSource source, Expression<Func<TSource, TProperty>> sourceProperty)
where T : IBindableComponent
where TSource : INotifyPropertyChanged
{
var targetPropertyInfo = targetProperty.GetProperty();
var sourcePropertyInfo = sourceProperty.GetProperty();
var binding = target.DataBindings.Add(
targetPropertyInfo.Name,
source,
sourcePropertyInfo.Name,
formattingEnabled: true);

targetPropertyInfo.SetValue(target, sourcePropertyInfo.GetValue(source));
return binding;
}
}
}
44 changes: 28 additions & 16 deletions AlbanianXrm.EarlyBound/Extensions/MirrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,43 @@ namespace AlbanianXrm.EarlyBound.Extensions
{
static class MirrorExtensions
{
public const string EXPRESSION_REFERS_METHOD = "Expression '{0}' refers to a method, not a property.";
public const string EXPRESSION_REFERS_FIELD = "Expression '{0}' refers to a method, not a property.";
public const string EXPRESSION_REFERS_OTHER_PROPERTY = "Expression '{0}' refers to a property that is not from type {1}.";

public static void SetPrivateValue<TSource, TProperty>(this TSource target, Expression<Func<TSource, TProperty>> propertyLambda, object value)
{
Type type = typeof(TSource);

if (!(propertyLambda.Body is MemberExpression member))
throw new ArgumentException(string.Format(
CultureInfo.CurrentCulture,
"Expression '{0}' refers to a method, not a property.",
propertyLambda.ToString()));

if (!(member.Member is PropertyInfo propInfo))
throw new ArgumentException(string.Format(
CultureInfo.CurrentCulture,
"Expression '{0}' refers to a field, not a property.",
propertyLambda.ToString()));
var propInfo = propertyLambda.GetProperty();

if (type != propInfo.ReflectedType &&
!type.IsSubclassOf(propInfo.ReflectedType))
throw new ArgumentException(string.Format(
CultureInfo.CurrentCulture,
"Expression '{0}' refers to a property that is not from type {1}.",
propertyLambda.ToString(),
type));
throw new ArgumentException(
string.Format(
CultureInfo.CurrentCulture,
EXPRESSION_REFERS_OTHER_PROPERTY,
propertyLambda.ToString(),
type));

type.GetProperty(propInfo.Name).SetValue(target, value);
}

public static PropertyInfo GetProperty<TObject, TProperty>(this Expression<Func<TObject, TProperty>> propertyLambda)
{
if (!(propertyLambda.Body is MemberExpression member))
throw new ArgumentException(
string.Format(
EXPRESSION_REFERS_METHOD,
propertyLambda.ToString()));

if (!(member.Member is PropertyInfo propInfo))
throw new ArgumentException(
string.Format(
EXPRESSION_REFERS_FIELD,
propertyLambda.ToString()));

return propInfo;
}
}
}
20 changes: 20 additions & 0 deletions AlbanianXrm.EarlyBound/Extensions/StringDictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlbanianXrm.EarlyBound.Extensions
{
static class StringDictionaryExtensions
{
public static IEnumerable<KeyValuePair<string, string>> ToEnumerable(this StringDictionary stringDictionary)
{
foreach (string key in stringDictionary.Keys)
{
yield return new KeyValuePair<string, string>(key, stringDictionary[key]);
}
}
}
}
5 changes: 4 additions & 1 deletion AlbanianXrm.EarlyBound/ILMergeConfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"General": {
"OutputFile": "$(TargetDir)XrmToolBox\\Plugins\\$(TargetFileName)",
"InputAssemblies": [
"AlbanianXrm.ForrestSerializer.dll",
"EnvDTE.dll",
"stdole.dll",
"Syncfusion.Core.WinForms.dll",
"Syncfusion.Data.WinForms.dll",
"Syncfusion.DataSource.WinForms.dll",
Expand All @@ -22,6 +24,7 @@
},
"Advanced": {
"CopyAttributes": false,
"AttributeFile": "$(TargetDir)AlbanianXrm.EarlyBound.dll"
"AttributeFile": "$(TargetDir)AlbanianXrm.EarlyBound.dll",
"DeleteCopiesOverwriteTarget": true
}
}
Loading

0 comments on commit bf792f8

Please sign in to comment.