Skip to content

Commit

Permalink
Parameter data type validation is added. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lotaked authored Oct 12, 2023
1 parent 168173a commit 7afb569
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/ConsoleConnector/Commands/AddParamCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public override Task<bool> Execute()
var parameterName = this.GetOption<ParameterName>();
var parameterValue = this.GetOption<ParameterValue>();
var parameterValueType = this.GetOption<ParameterValueDataType>();
if (parameterValueType.IsValidDataType == false)
{
Console.WriteLine("Invalid data type. Please try Help command to get more details.");
return Task.FromResult(false);
}
var exchangeData = ConsoleAppHelper.GetExchangeData(exchangeTitle.Value);
if (exchangeData == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override Task<bool> Execute()
}
else if (primitiveGeometryOption.Value == PrimitiveGeometryType.Polyline)
{
element = ConsoleAppHelper.GetGeometryHelper().AddPolyline(revitExchangeData);
element = ConsoleAppHelper.GetGeometryHelper().AddPolyline(elementDataModel);
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions src/ConsoleConnector/Commands/Options/ParameterValueDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Autodesk.DataExchange.ConsoleApp.Commands.Options
{
internal class ParameterValueDataType:CommandOption
{
public bool IsValidDataType { get; private set; } = false;
public new ParameterDataType Value { get; private set; } = ParameterDataType.String;
public ParameterValueDataType()
{
Expand All @@ -17,22 +18,31 @@ public ParameterValueDataType()

public override void SetValue(string value)
{
IsValidDataType = false;
if (Enum.TryParse(value, true, out ParameterDataType parameterDataType))
{
switch (parameterDataType)
{
case ParameterDataType.Float64:
IsValidDataType = true;
Value = ParameterDataType.Float64;
break;
case ParameterDataType.Bool:
IsValidDataType = true;
Value = ParameterDataType.Bool;
break;
case ParameterDataType.Int64:
IsValidDataType = true;
Value = ParameterDataType.Float64;
break;
case ParameterDataType.Int32:
IsValidDataType = true;
Value = ParameterDataType.Int32;
break;
case ParameterDataType.String:
IsValidDataType = true;
Value = ParameterDataType.String;
break;
}
}
}
Expand Down

0 comments on commit 7afb569

Please sign in to comment.