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

Added output to CustomCommant #299

Merged
Merged
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
36 changes: 36 additions & 0 deletions GSA_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using BH.oM.Adapter;
using BH.oM.Base;
using BH.oM.Adapter.Commands;
using System.Linq;

namespace BH.Adapter.GSA
{
Expand All @@ -39,6 +40,13 @@ public partial class GSA87Adapter
/***************************************************/

public override Output<List<object>, bool> Execute(IExecuteCommand command, ActionConfig actionConfig = null)
{
return RunCommandWithOutput(command as dynamic);
}

/***************************************************/

public Output<List<object>, bool> RunCommandWithOutput(IExecuteCommand command)
{
var output = new Output<List<object>, bool>() { Item1 = null, Item2 = false };

Expand All @@ -49,6 +57,34 @@ public override Output<List<object>, bool> Execute(IExecuteCommand command, Acti

/***************************************************/

public Output<List<object>, bool> RunCommandWithOutput(CustomCommand command)
{
object ret = null;
try
{
ret = this.ReturnComCall<object>(command.Command);
}
catch (System.Exception e)
{
BH.Engine.Base.Compute.RecordError(e, "Failed to run custom command.");
}

if (ret == null)
return new Output<List<object>, bool> { Item1 = new List<object>(), Item2 = false };

List<object> returnCollection;
if (!(ret is string) && ret is IEnumerable enumerable)
{
returnCollection = enumerable.Cast<object>().ToList();
}
else
returnCollection = new List<object> { ret };

return new Output<List<object>, bool> { Item1 = returnCollection, Item2 = true };
}

/***************************************************/

public bool RunCommand(ClearResults command)
{
return m_gsaCom.Delete("RESULTS") == 0;
Expand Down