Skip to content

Commit

Permalink
Merge pull request #764 from skadefro/master
Browse files Browse the repository at this point in the history
Let's try with more casting code
  • Loading branch information
skadefro authored Jul 4, 2023
2 parents 6c1bf68 + 03d84eb commit e9ffde4
Showing 1 changed file with 104 additions and 16 deletions.
120 changes: 104 additions & 16 deletions OpenRPA.Script/Activities/InvokeCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
using NLog.Targets;
using Newtonsoft.Json.Linq;
using System.Management.Instrumentation;
using System.Windows.Markup;
using Microsoft.CSharp.RuntimeBinder;
using System.Reflection.Metadata;

namespace OpenRPA.Script.Activities
{
Expand Down Expand Up @@ -199,13 +202,42 @@ protected override void Execute(CodeActivityContext context)
}
else
{
Dictionary<string, object> arguments = (from argument in Arguments
where argument.Value.Direction != ArgumentDirection.In
select argument).ToDictionary((KeyValuePair<string, Argument> argument) => argument.Key, (KeyValuePair<string, Argument> argument) => argument.Value.Get(context));
foreach (var a in arguments)
foreach (var a in Arguments)
{
if (a.Value.Direction == ArgumentDirection.In) continue;
var value = runspace.SessionStateProxy.GetVariable(a.Key);
Arguments[a.Key].Set(context, value);
if (value == null)
{
Arguments[a.Key].Set(context, null);
}
else if (a.Value.ArgumentType == typeof(string))
{
Arguments[a.Key].Set(context, value.ToString());
}
else if (a.Value.ArgumentType == typeof(int))
{
Arguments[a.Key].Set(context, int.Parse(value.ToString()));
}
else if (a.Value.ArgumentType == typeof(float))
{
Arguments[a.Key].Set(context, float.Parse(value.ToString()));
}
else if (a.Value.ArgumentType == typeof(bool))
{
Arguments[a.Key].Set(context, bool.Parse(value.ToString()));
}
else
{
try
{
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(value.ToString(), a.Value.ArgumentType);
Arguments[a.Key].Set(context, value);
}
catch (Exception _ex)
{
Log.Information("Failed variable " + a.Key + " of type " + a.Value.ArgumentType.FullName + " " + _ex.Message);
}
}
}
}
PipelineOutput.Set(context, res);
Expand Down Expand Up @@ -256,14 +288,42 @@ protected override void Execute(CodeActivityContext context)
else
{


Dictionary<string, object> arguments = (from argument in Arguments
where argument.Value.Direction != ArgumentDirection.In
select argument).ToDictionary((KeyValuePair<string, Argument> argument) => argument.Key, (KeyValuePair<string, Argument> argument) => argument.Value.Get(context));
foreach (var a in arguments)
foreach (var a in Arguments)
{
if (a.Value.Direction == ArgumentDirection.In) continue;
var value = ahk.GetVar(a.Key);
Arguments[a.Key].Set(context, value);
if (value == null)
{
Arguments[a.Key].Set(context, null);
}
else if (a.Value.ArgumentType == typeof(string))
{
Arguments[a.Key].Set(context, value.ToString());
}
else if (a.Value.ArgumentType == typeof(int))
{
Arguments[a.Key].Set(context, int.Parse(value.ToString()));
}
else if (a.Value.ArgumentType == typeof(float))
{
Arguments[a.Key].Set(context, float.Parse(value.ToString()));
}
else if (a.Value.ArgumentType == typeof(bool))
{
Arguments[a.Key].Set(context, bool.Parse(value.ToString()));
}
else
{
try
{
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(value.ToString(), a.Value.ArgumentType);
Arguments[a.Key].Set(context, value);
}
catch (Exception _ex)
{
Log.Information("Failed variable " + a.Key + " of type " + a.Value.ArgumentType.FullName + " " + _ex.Message);
}
}
}
}
}
Expand Down Expand Up @@ -369,14 +429,42 @@ protected override void Execute(CodeActivityContext context)
}
else
{
Dictionary<string, object> arguments = (from argument in Arguments
where argument.Value.Direction != ArgumentDirection.In
select argument).ToDictionary((KeyValuePair<string, Argument> argument) => argument.Key, (KeyValuePair<string, Argument> argument) => argument.Value.Get(context));
foreach (var a in arguments)
foreach (var a in Arguments)
{
if (a.Key == parameter.Key)
{
Arguments[a.Key].Set(context, pyobj);
if (pyobj == null)
{
Arguments[a.Key].Set(context, null);
}
else if (a.Value.ArgumentType == typeof(string))
{
Arguments[a.Key].Set(context, pyobj.ToString());
}
else if (a.Value.ArgumentType == typeof(int))
{
Arguments[a.Key].Set(context, int.Parse(pyobj.ToString()));
}
else if (a.Value.ArgumentType == typeof(float))
{
Arguments[a.Key].Set(context, float.Parse(pyobj.ToString()));
}
else if (a.Value.ArgumentType == typeof(bool))
{
Arguments[a.Key].Set(context, bool.Parse(pyobj.ToString()));
}
else
{
try
{
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pyobj.ToString(), a.Value.ArgumentType);
Arguments[a.Key].Set(context, pyobj);
}
catch (Exception _ex)
{
Log.Information("Failed variable " + parameter.Key + " of type " + a.Value.ArgumentType.FullName + " " + _ex.Message);
}
}
}
}

Expand Down

0 comments on commit e9ffde4

Please # to comment.