Skip to content
Merged
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
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
43 changes: 39 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public virtual Task MethodBodyExecute(object key)
if (IsCoreEventReplicator(_procWorker))
{
bodyParameters = ReadBodyParameters();
string synchronizer = PreProcessReplicatorParameteres(_procWorker, innerMethod, bodyParameters);
string synchronizer = PreProcessReplicatorParameteres( _procWorker, innerMethod, bodyParameters);
if (!IsAuthenticated(synchronizer))
return Task.CompletedTask;
}
Expand Down 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, this._variableAlias);
}
Dictionary<string, object> outputParameters = ReflectionHelper.CallMethod(_procWorker, innerMethod, bodyParameters, _gxContext);
Dictionary<string, string> formatParameters = ReflectionHelper.ParametersFormat(_procWorker, innerMethod);
Expand All @@ -150,9 +151,7 @@ public virtual Task MethodBodyExecute(object key)
finally
{
Cleanup();

}

}
}

public virtual Task Post()
Expand Down Expand Up @@ -186,6 +185,42 @@ private Dictionary<string, object> ReadBodyParameters()
return ReadRequestParameters(_httpContext.Request.GetInputStream());
#endif
}


private Dictionary<string, object> SetAlias(Dictionary<string, object> bodyParameters, Dictionary<string, string> varAlias)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
foreach (string k in bodyParameters.Keys)
{
if (k != null)
{
string keyLowercase = k.ToLower();
if (varAlias == null)
parameters[keyLowercase] = bodyParameters[k];
else
{
if (varAlias.ContainsKey(keyLowercase))
{
string alias = varAlias[keyLowercase].ToLower();
parameters[alias] = bodyParameters[k];
}
else if (!varAlias.ContainsValue(keyLowercase))
{
parameters[keyLowercase] = bodyParameters[k];
}
}
}
}
return parameters;
}

private Dictionary<string, object> PreProcessApiSdtParameter(GXBaseObject procWorker, string innerMethod,
Dictionary<string,object> bodyParameters, Dictionary<string, string> varAlias)
{
Dictionary<string, object> bP = SetAlias(bodyParameters, varAlias);
return ReflectionHelper.GetWrappedParameter(procWorker, innerMethod, bP);
}

private string PreProcessReplicatorParameteres(GXBaseObject procWorker, string innerMethod, Dictionary<string, object> bodyParameters)
{
var methodInfo = procWorker.GetType().GetMethod(innerMethod);
Expand Down
29 changes: 29 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,34 @@ public static bool MethodHasInputParameters(object instance, String methodName)
return false;
}

public static Dictionary<string, object> GetWrappedParameter(object instance, String methodName, Dictionary<string, object> bodyParameters)
{
System.Diagnostics.Debugger.Launch();
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