Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for big Int #511

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions DLaB.AttributeManager/AttributeManagerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void LoadEntities()
WorkAsync(new WorkAsyncInfo("Retrieving Entities...",
e =>
{
e.Result = Service.Execute(new RetrieveAllEntitiesRequest() {EntityFilters = EntityFilters.Entity, RetrieveAsIfPublished = true});
e.Result = Service.Execute(new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity, RetrieveAsIfPublished = true });
})
{
PostWorkCallBack = e =>
Expand All @@ -117,7 +117,7 @@ public void LoadEntities()
cmbEntities.Items.Clear();
OptionSetsMetadata = null; // Clear to be loaded again

var result = ((RetrieveAllEntitiesResponse) e.Result).EntityMetadata.
var result = ((RetrieveAllEntitiesResponse)e.Result).EntityMetadata.
Select(m => new ObjectCollectionItem<EntityMetadata>(m.DisplayName.GetLocalOrDefaultText("N/A") + " (" + m.LogicalName + ")", m)).
OrderBy(r => r.DisplayName);

Expand Down Expand Up @@ -158,10 +158,10 @@ public void LoadAttributes()
{
PostWorkCallBack = e =>
{
Metadata = ((RetrieveEntityResponse) e.Result).EntityMetadata;
var attributes = Metadata.Attributes.Where(a =>
!a.IsManaged.GetValueOrDefault() &&
a.AttributeOf == null &&
Metadata = ((RetrieveEntityResponse)e.Result).EntityMetadata;
var attributes = Metadata.Attributes.Where(a =>
!a.IsManaged.GetValueOrDefault() &&
a.AttributeOf == null &&
a.IsCustomizable.Value &&
!a.IsPrimaryId.GetValueOrDefault() &&
!IsBaseCurrency(a)).
Expand Down Expand Up @@ -191,7 +191,7 @@ public void LoadAttributes()

private bool IsBaseCurrency(AttributeMetadata attribute)
{
return attribute.AttributeType == AttributeTypeCode.Money && ((MoneyAttributeMetadata) attribute).IsBaseCurrency.GetValueOrDefault(false);
return attribute.AttributeType == AttributeTypeCode.Money && ((MoneyAttributeMetadata)attribute).IsBaseCurrency.GetValueOrDefault(false);
}

#region Steps
Expand Down Expand Up @@ -240,7 +240,7 @@ public void ExecuteSteps()
}

if ((steps.HasFlag(Logic.Steps.CreateNewAttribute)
|| steps.HasFlag(Logic.Steps.CreateTemp))
|| steps.HasFlag(Logic.Steps.CreateTemp))
&& cmbNewAttributeType.Text == @"Global Option Set"
&& optAttGlobalOptionSetCmb.SelectedItem == null)
{
Expand All @@ -256,7 +256,7 @@ public void ExecuteSteps()

WorkAsync(new WorkAsyncInfo("Performing Steps...", (w, e) =>
{
var info = (ExecuteStepsInfo) e.Argument;
var info = (ExecuteStepsInfo)e.Argument;
Logic.LogHandler onLog = m => w.ReportProgress(0, m);
info.Migrator.OnLog += onLog;
var result = new ExecuteStepsResult
Expand Down Expand Up @@ -284,7 +284,7 @@ public void ExecuteSteps()
{
PostWorkCallBack = e =>
{
var result = (ExecuteStepsResult) e.Result;
var result = (ExecuteStepsResult)e.Result;
if (result.Steps.HasFlag(Logic.Steps.MigrateToNewAttribute) && result.Successful)
{
AttributesNeedLoaded = true;
Expand Down Expand Up @@ -333,8 +333,8 @@ private AttributeMetadata GetNewAttributeType()
att = NewTypeAttributeCreationLogic.CreateText(int.Parse(strAttTxtMaximumLength.Text), GetStringFormat(), GetStringImeMode());
break;
case "Global Option Set":
var optionSet = (ObjectCollectionItem<OptionSetMetadata>) optAttGlobalOptionSetCmb.SelectedItem;
var defaultValue = (ObjectCollectionItem<int?>) optAttDefaultValueCmb.SelectedItem;
var optionSet = (ObjectCollectionItem<OptionSetMetadata>)optAttGlobalOptionSetCmb.SelectedItem;
var defaultValue = (ObjectCollectionItem<int?>)optAttDefaultValueCmb.SelectedItem;
att = NewTypeAttributeCreationLogic.CreateOptionSet(optionSet.Value, defaultValue?.Value);
break;
case "Local Option Set":
Expand All @@ -361,6 +361,20 @@ private AttributeMetadata GetNewAttributeType()
}
att = NewTypeAttributeCreationLogic.CreateWholeNumber(GetIntergerFormat(), intmin, intmax);
break;
case "Whole Number (big)":
long longtmp;
long? longmin = null;
long? longmax = null;
if (long.TryParse(numAttMinTxt.Text, out longtmp))
{
longmin = longtmp;
}
if (long.TryParse(numAttMaxTxt.Text, out longtmp))
{
longmax = longtmp;
}
att = NewTypeAttributeCreationLogic.CreateWholeNumberBig(longmin, longmax);
break;
case "Floating Point Number":
double dbltmp;
double? dblmin = null;
Expand Down Expand Up @@ -533,7 +547,7 @@ private void HideNumberAttributes()
numAttPrecisionTxt.Text = "";
numAttCurrencyPrecisionCmb.SelectedIndex = -1;
}

private void SetDecimalNumberVisible()
{
HideNumberAttributes();
Expand Down Expand Up @@ -590,6 +604,14 @@ private void SetWholeNumberVisible()
numAttMinTxt.Text = IntegerAttributeMetadata.MinSupportedValue.ToString(CultureInfo.InvariantCulture);
numAttMaxTxt.Text = IntegerAttributeMetadata.MaxSupportedValue.ToString(CultureInfo.InvariantCulture);
}
private void SetWholeNumberBigVisible()
{
HideNumberAttributes();
numAttMinLbl.Visible = true;
numAttMinTxt.Visible = true;
numAttMinTxt.Text = BigIntAttributeMetadata.MinSupportedValue.ToString(CultureInfo.InvariantCulture);
numAttMaxTxt.Text = BigIntAttributeMetadata.MaxSupportedValue.ToString(CultureInfo.InvariantCulture);
}

private IntegerFormat GetIntergerFormat()
{
Expand Down Expand Up @@ -652,7 +674,7 @@ private void tsbClose_Click(object sender, EventArgs e)

private void cmbEntities_SelectedIndexChanged(object sender, EventArgs e)
{

AttributesNeedLoaded = true;
cmbAttributes.Items.Clear();
cmbAttributes.SelectedItem = null;
Expand Down Expand Up @@ -709,7 +731,7 @@ private string GetAttributeTypeDisplayValue(AttributeMetadata attribute)
var optionSetAtt = attribute as PicklistAttributeMetadata;
if (optionSetAtt?.OptionSet != null)
{
displayValue = (optionSetAtt.OptionSet.IsGlobal.GetValueOrDefault() ? "Global Option Set - " : "Local Option Set - ") +
displayValue = (optionSetAtt.OptionSet.IsGlobal.GetValueOrDefault() ? "Global Option Set - " : "Local Option Set - ") +
optionSetAtt.OptionSet.DisplayName.GetLocalOrDefaultText() + $" ({optionSetAtt.OptionSet.Name})";
}

Expand Down Expand Up @@ -791,11 +813,11 @@ private void chkDelete_CheckedChanged(object sender, EventArgs e)
SetTabVisible(tabDelete, chkDelete.Checked);

chkConvertAttributeType.Visible = !chkDelete.Checked;
chkMigrate.Visible = !chkDelete.Checked;
lblNewAttributeGrid.Visible = !chkDelete.Checked;
txtNewAttributeName.Visible = !chkDelete.Checked;
txtDisplayName.Visible = !chkDelete.Checked;
cmbNewAttributeType.Visible = !chkDelete.Checked;
chkMigrate.Visible = !chkDelete.Checked;
lblNewAttributeGrid.Visible = !chkDelete.Checked;
txtNewAttributeName.Visible = !chkDelete.Checked;
txtDisplayName.Visible = !chkDelete.Checked;
cmbNewAttributeType.Visible = !chkDelete.Checked;

UpdateDisplayedSteps();
}
Expand Down Expand Up @@ -824,6 +846,7 @@ private void DisplayTabForNewAttributeSelected()
var stringTabVisible = false;
var optionTabVisible = false;
var numberTabVisible = false;
var numberBigTabVisible = false;
if (cmbNewAttributeType.SelectedIndex == -1)
{
return;
Expand Down Expand Up @@ -866,6 +889,11 @@ private void DisplayTabForNewAttributeSelected()
pNumberType.Visible = true;
SetWholeNumberVisible();
break;
case "Whole Number (big)":
numberBigTabVisible = true;
pNumberType.Visible = true;
SetWholeNumberBigVisible();
break;
case "Floating Point Number":
numberTabVisible = true;
SetFloatNumberVisible();
Expand Down Expand Up @@ -908,11 +936,11 @@ private void RetrieveOptionSets()
return;
}

WorkAsync(new WorkAsyncInfo("Retrieving OptionSets...", e => { e.Result = ((RetrieveAllOptionSetsResponse) Service.Execute(new RetrieveAllOptionSetsRequest())).OptionSetMetadata; })
WorkAsync(new WorkAsyncInfo("Retrieving OptionSets...", e => { e.Result = ((RetrieveAllOptionSetsResponse)Service.Execute(new RetrieveAllOptionSetsRequest())).OptionSetMetadata; })
{
PostWorkCallBack = e =>
{
OptionSetsMetadata = (IEnumerable<OptionSetMetadataBase>) e.Result;
OptionSetsMetadata = (IEnumerable<OptionSetMetadataBase>)e.Result;
LoadOptionSets(OptionSetsMetadata);
}
});
Expand All @@ -926,7 +954,7 @@ private void LoadOptionSets(IEnumerable<OptionSetMetadataBase> optionSets)
optAttGlobalOptionSetCmb.Items.Clear();
optAttGlobalOptionSetCmb.Text = null;

var values = optionSets.Where(m => m.IsGlobal.GetValueOrDefault() && m is OptionSetMetadata).Select(e => new ObjectCollectionItem<OptionSetMetadata>(e.Name, (OptionSetMetadata) e)).OrderBy(r => r.DisplayName).Cast<object>().ToArray();
var values = optionSets.Where(m => m.IsGlobal.GetValueOrDefault() && m is OptionSetMetadata).Select(e => new ObjectCollectionItem<OptionSetMetadata>(e.Name, (OptionSetMetadata)e)).OrderBy(r => r.DisplayName).Cast<object>().ToArray();

optAttGlobalOptionSetCmb.Items.AddRange(values);
}
Expand Down Expand Up @@ -1091,7 +1119,7 @@ private void UpdateDisplayedSteps()
{
// Partial Completion. Need to allow for Migrate to Temp and Remove
var steps = StepMapper.Where(p => (p.Value == Logic.Steps.MigrateDataToTemp && chkMigrate.Checked)
|| p.Value == Logic.Steps.MigrateToNewAttribute
|| p.Value == Logic.Steps.MigrateToNewAttribute
|| p.Value == Logic.Steps.RemoveTemp).Select(v => v.Key);
clbSteps.LoadItems(steps.ToObjectArray());
}
Expand Down Expand Up @@ -1132,15 +1160,15 @@ private void RemoveNonNumber_KeyPress(object sender, KeyPressEventArgs e)
}

// only allow one decimal point
if (e.KeyChar == '.' && (((TextBox) sender).Text.IndexOf('.') > -1))
if (e.KeyChar == '.' && (((TextBox)sender).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}

private void optAttGlobalOptionSetCmb_SelectionChangeCommitted(object sender, EventArgs e)
{
var optionSet = (ObjectCollectionItem<OptionSetMetadata>) optAttGlobalOptionSetCmb.SelectedItem;
var optionSet = (ObjectCollectionItem<OptionSetMetadata>)optAttGlobalOptionSetCmb.SelectedItem;
optAttDefaultValueCmb.BeginUpdate();
optAttDefaultValueCmb.Items.Clear();
try
Expand Down Expand Up @@ -1188,8 +1216,8 @@ private void chkIgnoreUpdateErrors_CheckedChanged(object sender, EventArgs e)
}
}

[Export(typeof (IXrmToolBoxPlugin)),
ExportMetadata("Name", "Attribute Manager"),
[Export(typeof(IXrmToolBoxPlugin)),
ExportMetadata("Name", "Attribute Manager"),
ExportMetadata("Description", "Handles Creating/Updating an attribute for an Entity."),
ExportMetadata("SmallImageBase64", SmallImage32X32), // null for "no logo" image or base64 image content
ExportMetadata("BigImageBase64", LargeImage120X120), // null for "no logo" image or base64 image content
Expand Down
1 change: 1 addition & 0 deletions DLaB.AttributeManager/AttributeManagerPlugin.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions DLaB.AttributeManager/AttributeValueCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ private object CopyValueInternal(AttributeMetadata oldAttribute, IntegerAttribut
return null;
}

private object CopyValueInternal(AttributeMetadata oldAttribute, BigIntAttributeMetadata newAttribute, object value, Dictionary<string, string> migrationMapping)
{
var unformatted = value.ToString();
unformatted = migrationMapping.TryGetValue(unformatted, out var mappedValue) ? mappedValue : unformatted;

// Handle 1.0000
if (unformatted.Contains("."))
{
while (unformatted.EndsWith("0") || unformatted.EndsWith("."))
{
unformatted = unformatted.Substring(0, unformatted.Length - 1);
}
}

if (long.TryParse(unformatted, out var output))
{
return output;
}
Trace("Unable to convert value \"" + value + "\" of type \"" + value.GetType().Name + "\" to Integer");
return null;
}

private object CopyValueInternal(AttributeMetadata oldAttribute, LookupAttributeMetadata newAttribute, object value, Dictionary<string, string> migrationMapping)
{
CopyValueInternal((object)oldAttribute, newAttribute, value, migrationMapping);
Expand Down
5 changes: 3 additions & 2 deletions DLaB.AttributeManager/DLaB.AttributeManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.51\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.52\lib\net462\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.6.1.7600.16394\lib\net35\Microsoft.IdentityModel.dll</HintPath>
Expand All @@ -76,7 +76,7 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.51\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
<HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.52\lib\net462\Microsoft.Xrm.Sdk.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk.Deployment, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CrmSdk.Deployment.9.0.2.34\lib\net462\Microsoft.Xrm.Sdk.Deployment.dll</HintPath>
Expand Down Expand Up @@ -271,6 +271,7 @@
<ItemGroup>
<EmbeddedResource Include="AttributeManagerPlugin.resx">
<DependentUpon>AttributeManagerPlugin.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
14 changes: 11 additions & 3 deletions DLaB.AttributeManager/NewTypeAttributeCreationLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace DLaB.AttributeManager
public class NewTypeAttributeCreationLogic
{
public static AttributeMetadata CreateText(int? maxLength = null, StringFormatName formatName = null, ImeMode? imeMode = ImeMode.Auto, string yomiOf = null, string formulaDefinition = null)
{
{
maxLength = maxLength != null ? maxLength : (formulaDefinition != null ? 4000 : 100);

return new StringAttributeMetadata
Expand All @@ -31,7 +31,7 @@ public static AttributeMetadata CreateMemo(int? maxLength = null, ImeMode? imeMo
public static AttributeMetadata CreateOptionSet(OptionSetMetadata optionSet, int? defaultFormValue = null, string formulaDefinition = null)
{
if (optionSet.IsGlobal.GetValueOrDefault())
{
{
// Can't send Global Option Set Options
optionSet.Options.Clear();
}
Expand Down Expand Up @@ -72,6 +72,14 @@ public static AttributeMetadata CreateWholeNumber(IntegerFormat? format = Intege
FormulaDefinition = formulaDefinition
};
}
public static AttributeMetadata CreateWholeNumberBig(long? minValue = BigIntAttributeMetadata.MinSupportedValue, long? maxValue = BigIntAttributeMetadata.MaxSupportedValue)
{
return new BigIntAttributeMetadata()
{
//MaxValue = maxValue,
//MinValue = minValue,
};
}

public static AttributeMetadata CreateFloatingPoint(double? minValue = 0, double? maxValue = 1000000000, int? precision = 2, ImeMode? mode = ImeMode.Auto)
{
Expand Down Expand Up @@ -137,7 +145,7 @@ public static AttributeMetadata CreateCurrency(double? minValue = -9223372036854
PrecisionSource = precisionSource,
CalculationOf = calculationOf,
FormulaDefinition = formulaDefinition
};
};
}

public static AttributeMetadata CreateDateTime(DateTimeFormat? format = DateTimeFormat.DateOnly, ImeMode? mode = ImeMode.Auto, string formulaDefinition = null)
Expand Down
2 changes: 1 addition & 1 deletion DLaB.AttributeManager/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.5.0.154" newVersion="6.5.0.154" />
<bindingRedirect oldVersion="0.0.0.0-5.9.3.3" newVersion="5.9.3.3" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NuGet.Protocol" publicKeyToken="31bf3856ad364e35" culture="neutral" />
Expand Down
2 changes: 1 addition & 1 deletion DLaB.AttributeManager/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<package id="Microsoft.ApplicationInsights" version="2.18.0" targetFramework="net462" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.18.0" targetFramework="net462" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net48" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.51" targetFramework="net48" />
<package id="Microsoft.CrmSdk.CoreAssemblies" version="9.0.2.52" targetFramework="net48" />
<package id="Microsoft.CrmSdk.Deployment" version="9.0.2.34" targetFramework="net462" />
<package id="Microsoft.CrmSdk.Workflow" version="9.0.2.51" targetFramework="net48" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="9.1.1.44" targetFramework="net48" />
Expand Down
Loading