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

- Unwrapped input support for SDTs in API Objects. #572

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public void ServicesGroupSetting()
{
object p = JSONHelper.Deserialize<MapGroup>(content);
MapGroup m = p as MapGroup;
if (m != null)
if (m != null && m.Name != null && m.Mappings != null)
{

if (String.IsNullOrEmpty(m.BasePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void ServicesGroupSetting(string webPath)
object p = JSONHelper.Deserialize<MapGroup>(File.ReadAllText(grp));
#pragma warning restore SCS0018
MapGroup m = p as MapGroup;
if (m != null)
if (m != null && m.Name != null && m.Mappings != null )
{

if (String.IsNullOrEmpty(m.BasePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public override void webExecute()
GxFile gxFile = new GxFile(tempDir, FileUtil.getTempFileName(tempDir), GxFileType.PrivateAttribute);

gxFile.Create(hpf.InputStream);

string uri = gxFile.GetURI();
string url = (PathUtil.IsAbsoluteUrl(uri)) ? uri : context.PathToUrl(uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public virtual Task MethodBodyExecute(object key)
if (!String.IsNullOrEmpty(this._serviceMethod))
{
innerMethod = this._serviceMethod;
bodyParameters = PreProcessApiSdtParameter(_procWorker, innerMethod, bodyParameters);
}
Dictionary<string, object> outputParameters = ReflectionHelper.CallMethod(_procWorker, innerMethod, bodyParameters, _gxContext);
Dictionary<string, string> formatParameters = ReflectionHelper.ParametersFormat(_procWorker, innerMethod);
Expand Down Expand Up @@ -186,6 +187,11 @@ private Dictionary<string, object> ReadBodyParameters()
return ReadRequestParameters(_httpContext.Request.GetInputStream());
#endif
}

private Dictionary<string, object> PreProcessApiSdtParameter(GXBaseObject procWorker, string innerMethod, Dictionary<string,object> bodyParameters)
{
return ReflectionHelper.GetWrappedParameter(procWorker, innerMethod, bodyParameters);
}
private string PreProcessReplicatorParameteres(GXBaseObject procWorker, string innerMethod, Dictionary<string, object> bodyParameters)
{
var methodInfo = procWorker.GetType().GetMethod(innerMethod);
Expand Down
28 changes: 28 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Services/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.RegularExpressions;
using GeneXus.Utils;
using System.Linq;
using Jayrock.Json;

using Type = System.Type;

Expand Down Expand Up @@ -67,6 +68,33 @@ public static bool MethodHasInputParameters(object instance, String methodName)
return false;
}

public static Dictionary<string, object> GetWrappedParameter(object instance, String methodName, Dictionary<string, object> bodyParameters)
{
MethodInfo methodInfo = instance.GetType().GetMethod(methodName);
var methodParameters = methodInfo.GetParameters();
List<ParameterInfo> inputParameters = new List<ParameterInfo>();
foreach (var methodParameter in methodParameters)
{
if (!methodParameter.IsOut)
{
inputParameters.Add(methodParameter);
}
}
if (inputParameters.Count == 1 && bodyParameters.Count>1)
{
ParameterInfo pInfo = inputParameters[0];
if (pInfo.ParameterType.IsSubclassOf(typeof(GxUserType)))
{
var gxParameterName = GxParameterName(pInfo.Name).ToLower();
Dictionary<string, object> parameters = new Dictionary<string,object>();
JObject jparms = new JObject(bodyParameters);
parameters.Add(gxParameterName,jparms);
return parameters;
}
}
return bodyParameters;
}

private static object ConvertSingleJsonItem(object value, Type newType, IGxContext context)
{
if (value!= null && value.GetType() == newType)
Expand Down