Skip to content
82 changes: 48 additions & 34 deletions dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
using GeneXus.Application;
using GeneXus.Metadata;
using GeneXus.Utils;
using System;
using System.Collections.Generic;
using System.Reflection;
using GeneXus.Application;
using GeneXus.Metadata;
using GeneXus.Utils;

namespace GeneXus.DynamicCall
{
public class GxDynamicCall
{
public class GxDynamicCall
{
private const string defaultMethod = "execute";
private Assembly _assembly;
private readonly IGxContext _context;
private GXProperties _extendedProperties;
private GxDynCallProperties _properties;
private object _object;

//[Obsolete("ObjectName is deprecated. Use ExternalName instead", false)]
public string ObjectName { get; set; }
public GxDynCallProperties Properties
public string ExternalName { get; set; }

//[Obsolete("Properties is deprecated. Use ExtendedProperties instead", false)]
public GxDynCallProperties Properties
{
get => _properties;
set
Expand All @@ -23,27 +30,43 @@ public GxDynCallProperties Properties
}
}

public GXProperties ExtendedProperties
{
get => _extendedProperties;
set
{
_extendedProperties = ExtendedProperties;
}
}
public GxDynamicCall()
{
_assembly= null;
_extendedProperties = new GXProperties();
_properties = new GxDynCallProperties();
}

public GxDynamicCall(IGxContext context)
{
_context = context;
_assembly = null;
_extendedProperties = new GXProperties();
_properties = new GxDynCallProperties();
_object = null;
}

private void VerifyDefaultProperties() {
_properties.NameSpace = string.IsNullOrEmpty(_properties.NameSpace) ? "GeneXus.Programs" : _properties.NameSpace;
private void VerifyDefaultProperties()
{

if (_assembly is null)
{
if (string.IsNullOrEmpty(_properties.AssemblyName))
if (string.IsNullOrEmpty(_extendedProperties.Get("AssemblyName")))
{
_assembly = Assembly.GetCallingAssembly();
}
else
{
try
{
_assembly = Assembly.LoadFrom(_properties.AssemblyName);
_assembly = Assembly.LoadFrom(_extendedProperties.Get("AssemblyName"));
}
catch
{
Expand All @@ -63,24 +86,19 @@ public void Execute(ref IList<object> parameters, out IList<SdtMessages_Message>
}
}

public void Create( IList<object> constructParms, out IList<SdtMessages_Message> errors)
public void Create(IList<object> constructParms, out IList<SdtMessages_Message> errors)
{
errors = new GXBaseCollection<SdtMessages_Message>();
string objectNameToInvoke;
try
{
VerifyDefaultProperties();
if (constructParms is null)
{
objectNameToInvoke = ObjectName;
}
else
{
objectNameToInvoke = _properties.ExternalName;
}

objectNameToInvoke = ExternalName;

try
{
Type objType = ClassLoader.FindType(objectNameToInvoke, _properties.NameSpace, objectNameToInvoke.ToLower().Trim(), _assembly);
Type objType = ClassLoader.FindType(objectNameToInvoke, objectNameToInvoke.ToLower().Trim(), _assembly);
object[] constructorParameters;
if (constructParms != null && constructParms.Count > 0)
{
Expand All @@ -89,27 +107,27 @@ public void Create( IList<object> constructParms, out IList<SdtMessages_Message>
}
else
{
constructorParameters = new object[] { new GxContext() };
constructorParameters = new object[] { _context };
}
_object = Activator.CreateInstance(objType, constructorParameters);
}
catch (Exception e)
{
GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection<SdtMessages_Message>) errors);
GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection<SdtMessages_Message>)errors);
}
}
catch (Exception e)
{
GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection<SdtMessages_Message>)errors);
}
}
public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodconfiguration , out IList<SdtMessages_Message> errors)
public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodconfiguration, out IList<SdtMessages_Message> errors)
{
object result;
errors = new GXBaseCollection<SdtMessages_Message>();
IList<object> outParms= new List<object>();
IList<object> outParms = new List<object>();

string methodName = methodconfiguration.MethodName;
string methodName = methodconfiguration.MethodName;
bool isStatic = methodconfiguration.IsStatic;

if (!isStatic)
Expand All @@ -118,7 +136,7 @@ public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodco
{
try
{
outParms = ReflectionHelper.CallMethod(_object, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters);
outParms = ReflectionHelper.CallMethod(_object, string.IsNullOrEmpty(methodName) ? defaultMethod : methodName, parameters);
}
catch (Exception e)
{
Expand All @@ -133,7 +151,7 @@ public object Execute(ref IList<object> parameters, GxDynCallMethodConf methodco
else
{
VerifyDefaultProperties();
Type objType = ClassLoader.FindType(_properties.ExternalName, _properties.NameSpace, _properties.ExternalName.ToLower().Trim(), _assembly);
Type objType = ClassLoader.FindType(ExternalName, ExternalName.ToLower().Trim(), _assembly);
outParms = ReflectionHelper.CallMethod(objType, (string.IsNullOrEmpty(methodName) ? defaultMethod : methodName), parameters, isStatic);
}
if (outParms.Count > parameters.Count)
Expand Down Expand Up @@ -167,9 +185,7 @@ public GxDynCallMethodConf()
IsStatic = false;
MethodName = "execute";
}

}

public class GxDynCallProperties
{
public string ExternalName
Expand All @@ -187,7 +203,5 @@ public string NameSpace
get;
set;
}

}
}

}
196 changes: 196 additions & 0 deletions dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
File: genexus.common.type_SdtDynamicCall
Description: DynamicCall
Author: GeneXus .NET Generator version 18_0_11-185337
Generated on: 11/28/2024 9:54:49.46
Program type: Callable routine
Main DBMS: SQL Server
*/
using System;
using System.Collections;
using System.Xml.Serialization;
using GeneXus.Application;
using GeneXus.Utils;
namespace GeneXus.Core.genexus.common
{
[Serializable]
public class SdtDynamicCall : GxUserType, IGxExternalObject
{
public SdtDynamicCall( )
{
/* Constructor for serialization */
}

public SdtDynamicCall( IGxContext context )
{
this.context = context;
initialize();
}

private static Hashtable mapper;
public override string JsonMap( string value )
{
if ( mapper == null )
{
mapper = new Hashtable();
}
return (string)mapper[value]; ;
}

public void execute( ref GxSimpleCollection<object> gxTp_Parameters ,
out GXBaseCollection<GeneXus.Utils.SdtMessages_Message> gxTp_Errors )
{
gxTp_Errors = new GXBaseCollection<GeneXus.Utils.SdtMessages_Message>( context, "Message", "GeneXus");
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
System.Collections.Generic.IList<object> externalParm0;
System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message> externalParm1;
externalParm0 = (System.Collections.Generic.IList<object>)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList<object>), gxTp_Parameters.ExternalInstance);
GeneXus_Common_DynamicCall_externalReference.Execute(ref externalParm0, out externalParm1);
gxTp_Parameters.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList<object>), externalParm0);
gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message>), externalParm1);
return ;
}

public object execute( ref GxSimpleCollection<object> gxTp_Parameters ,
GeneXus.Core.genexus.common.SdtDynamicCallMethodProperties gxTp_MethodInfo ,
out GXBaseCollection<GeneXus.Utils.SdtMessages_Message> gxTp_Errors )
{
object returnexecute;
gxTp_Errors = new GXBaseCollection<GeneXus.Utils.SdtMessages_Message>( context, "Message", "GeneXus");
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
object externalParm0;
System.Collections.Generic.IList<object> externalParm1;
GeneXus.DynamicCall.GxDynCallMethodConf externalParm2;
System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message> externalParm3;
externalParm1 = (System.Collections.Generic.IList<object>)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList<object>), gxTp_Parameters.ExternalInstance);
externalParm2 = (GeneXus.DynamicCall.GxDynCallMethodConf)(gxTp_MethodInfo.ExternalInstance);
externalParm0 = GeneXus_Common_DynamicCall_externalReference.Execute(ref externalParm1, externalParm2, out externalParm3);
returnexecute = (object)(externalParm0);
gxTp_Parameters.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList<object>), externalParm1);
gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message>), externalParm3);
return returnexecute ;
}

public void create( GxSimpleCollection<object> gxTp_Parameters ,
out GXBaseCollection<GeneXus.Utils.SdtMessages_Message> gxTp_Errors )
{
gxTp_Errors = new GXBaseCollection<GeneXus.Utils.SdtMessages_Message>( context, "Message", "GeneXus");
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
System.Collections.Generic.IList<object> externalParm0;
System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message> externalParm1;
externalParm0 = (System.Collections.Generic.IList<object>)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList<object>), gxTp_Parameters.ExternalInstance);
GeneXus_Common_DynamicCall_externalReference.Create(externalParm0, out externalParm1);
gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList<GeneXus.Utils.SdtMessages_Message>), externalParm1);
return ;
}

public void setoption( ref string gxTp_ObjectName ,
ref string gxTp_CallOption ,
ref string gxTp_Value )
{
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
return ;
}

public string gxTpr_Objectname
{
get {
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
return GeneXus_Common_DynamicCall_externalReference.ObjectName ;
}

set {
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
GeneXus_Common_DynamicCall_externalReference.ObjectName = value;
SetDirty("Objectname");
}

}

public GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet gxTpr_Net
{
get {
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet intValue;
intValue = new GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet(context);
GeneXus.DynamicCall.GxDynCallProperties externalParm0;
externalParm0 = GeneXus_Common_DynamicCall_externalReference.Properties;
intValue.ExternalInstance = externalParm0;
return intValue ;
}

set {
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
GeneXus.Core.genexus.common.SdtDynamicCallPropertiesNet intValue;
GeneXus.DynamicCall.GxDynCallProperties externalParm1;
intValue = value;
externalParm1 = (GeneXus.DynamicCall.GxDynCallProperties)(intValue.ExternalInstance);
GeneXus_Common_DynamicCall_externalReference.Properties = externalParm1;
SetDirty("Net");
}

}

public Object ExternalInstance
{
get {
if ( GeneXus_Common_DynamicCall_externalReference == null )
{
GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall();
}
return GeneXus_Common_DynamicCall_externalReference ;
}

set {
GeneXus_Common_DynamicCall_externalReference = (GeneXus.DynamicCall.GxDynamicCall)(value);
}

}

[XmlIgnore]
private static GXTypeInfo _typeProps;
protected override GXTypeInfo TypeInfo
{
get {
return _typeProps ;
}

set {
_typeProps = value ;
}

}

public void initialize( )
{
return ;
}

protected GeneXus.DynamicCall.GxDynamicCall GeneXus_Common_DynamicCall_externalReference=null ;
}

}
Loading
Loading