diff --git a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs index d6af1f832..2b274d300 100644 --- a/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs +++ b/dotnet/src/dotnetframework/GxClasses/Helpers/GxDynamicCall.cs @@ -1,58 +1,98 @@ -using GeneXus.Application; -using GeneXus.Metadata; -using GeneXus.Utils; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Reflection; +using GeneXus.Application; +using GeneXus.Metadata; +using GeneXus.Utils; +using GxClasses.Helpers; +using Microsoft.IdentityModel.Tokens; namespace GeneXus.DynamicCall { - public class GxDynamicCall - { + public class GxDynamicCall + { private const string defaultMethod = "execute"; + private const string AssemblyNameProperty = "AssemblyName"; + private const string NamespaceProperty = "Namespace"; + private const string DefaultNamespace = "GeneXus.Programs"; 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 { - _properties = Properties; + _properties = value; } } + public GXProperties ExtendedProperties + { + get => _extendedProperties; + set + { + _extendedProperties = value; + } + } 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(AssemblyNameProperty))) { +#if NETCORE + var stackTrace = new StackTrace(); + var frame = stackTrace.GetFrame(5); + var method = frame.GetMethod(); + var assembly = method.DeclaringType.Assembly; + _assembly = assembly; +#else _assembly = Assembly.GetCallingAssembly(); +#endif } else { try { - _assembly = Assembly.LoadFrom(_properties.AssemblyName); +#if NETCORE + _assembly = AssemblyLoader.LoadAssembly(new AssemblyName(_extendedProperties.Get(AssemblyNameProperty))); +#else + _assembly = Assembly.LoadFrom(_extendedProperties.Get(AssemblyNameProperty) + ".dll" ); +#endif } - catch + catch (Exception e) { - throw; + throw new InvalidOperationException("Error loading assembly: " + _extendedProperties.Get(AssemblyNameProperty), e); } } } } - public void Execute(ref IList parameters, out IList errors) { Create(null, out errors); @@ -63,24 +103,19 @@ public void Execute(ref IList parameters, out IList } } - public void Create( IList constructParms, out IList errors) + public void Create(IList constructParms, out IList errors) { errors = new GXBaseCollection(); string objectNameToInvoke; try { VerifyDefaultProperties(); - if (constructParms is null) - { - objectNameToInvoke = ObjectName; - } - else - { - objectNameToInvoke = _properties.ExternalName; - } + + objectNameToInvoke = string.IsNullOrEmpty(_extendedProperties.Get(NamespaceProperty)) ? DefaultNamespace + "." + ExternalName.ToLower().Trim() : _extendedProperties.Get(NamespaceProperty) + "." + ExternalName.ToLower().Trim(); + try { - Type objType = ClassLoader.FindType(objectNameToInvoke, _properties.NameSpace, objectNameToInvoke.ToLower().Trim(), _assembly); + Type objType = ClassLoader.FindType(_assembly.GetName().Name, string.IsNullOrEmpty(_extendedProperties.Get(NamespaceProperty))? DefaultNamespace : _extendedProperties.Get(NamespaceProperty), ExternalName.ToLower().Trim(), _assembly); object[] constructorParameters; if (constructParms != null && constructParms.Count > 0) { @@ -89,13 +124,13 @@ public void Create( IList constructParms, out IList } 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) errors); + GXUtil.ErrorToMessages("CreateInstance Error", e.Message, (GXBaseCollection)errors); } } catch (Exception e) @@ -103,13 +138,13 @@ public void Create( IList constructParms, out IList GXUtil.ErrorToMessages("VerifyProperties Error", e.Message, (GXBaseCollection)errors); } } - public object Execute(ref IList parameters, GxDynCallMethodConf methodconfiguration , out IList errors) + public object Execute(ref IList parameters, GxDynCallMethodConf methodconfiguration, out IList errors) { object result; errors = new GXBaseCollection(); - IList outParms= new List(); + IList outParms = new List(); - string methodName = methodconfiguration.MethodName; + string methodName = methodconfiguration.MethodName; bool isStatic = methodconfiguration.IsStatic; if (!isStatic) @@ -118,7 +153,7 @@ public object Execute(ref IList 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) { @@ -133,7 +168,7 @@ public object Execute(ref IList 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) @@ -167,9 +202,7 @@ public GxDynCallMethodConf() IsStatic = false; MethodName = "execute"; } - } - public class GxDynCallProperties { public string ExternalName @@ -187,7 +220,5 @@ public string NameSpace get; set; } - } -} - +} \ No newline at end of file diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs new file mode 100644 index 000000000..63e9ed510 --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCall.cs @@ -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 gxTp_Parameters , + out GXBaseCollection gxTp_Errors ) + { + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + System.Collections.Generic.IList externalParm0; + System.Collections.Generic.IList externalParm1; + externalParm0 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), gxTp_Parameters.ExternalInstance); + GeneXus_Common_DynamicCall_externalReference.Execute(ref externalParm0, out externalParm1); + gxTp_Parameters.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm0); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm1); + return ; + } + + public object execute( ref GxSimpleCollection gxTp_Parameters , + GeneXus.Core.genexus.common.SdtDynamicCallMethodProperties gxTp_MethodInfo , + out GXBaseCollection gxTp_Errors ) + { + object returnexecute; + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + object externalParm0; + System.Collections.Generic.IList externalParm1; + GeneXus.DynamicCall.GxDynCallMethodConf externalParm2; + System.Collections.Generic.IList externalParm3; + externalParm1 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), 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), externalParm1); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), externalParm3); + return returnexecute ; + } + + public void create( GxSimpleCollection gxTp_Parameters , + out GXBaseCollection gxTp_Errors ) + { + gxTp_Errors = new GXBaseCollection( context, "Message", "GeneXus"); + if ( GeneXus_Common_DynamicCall_externalReference == null ) + { + GeneXus_Common_DynamicCall_externalReference = new GeneXus.DynamicCall.GxDynamicCall(); + } + System.Collections.Generic.IList externalParm0; + System.Collections.Generic.IList externalParm1; + externalParm0 = (System.Collections.Generic.IList)CollectionUtils.ConvertToExternal( typeof(System.Collections.Generic.IList), gxTp_Parameters.ExternalInstance); + GeneXus_Common_DynamicCall_externalReference.Create(externalParm0, out externalParm1); + gxTp_Errors.ExternalInstance = (IList)CollectionUtils.ConvertToInternal( typeof(System.Collections.Generic.IList), 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 ; + } + +} diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs new file mode 100644 index 000000000..60e5c67a3 --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallMethodProperties.cs @@ -0,0 +1,120 @@ +/* + File: genexus.common.type_SdtDynamicCallMethodProperties + Description: DynamicCallMethodProperties + 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 SdtDynamicCallMethodProperties : GxUserType, IGxExternalObject + { + public SdtDynamicCallMethodProperties( ) + { + /* Constructor for serialization */ + } + + public SdtDynamicCallMethodProperties( 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 bool gxTpr_Isstatic + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference.IsStatic ; + } + + set { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + GeneXus_Common_DynamicCallMethodProperties_externalReference.IsStatic = value; + SetDirty("Isstatic"); + } + + } + + public string gxTpr_Methodname + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference.MethodName ; + } + + set { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + GeneXus_Common_DynamicCallMethodProperties_externalReference.MethodName = value; + SetDirty("Methodname"); + } + + } + + public Object ExternalInstance + { + get { + if ( GeneXus_Common_DynamicCallMethodProperties_externalReference == null ) + { + GeneXus_Common_DynamicCallMethodProperties_externalReference = new GeneXus.DynamicCall.GxDynCallMethodConf(); + } + return GeneXus_Common_DynamicCallMethodProperties_externalReference ; + } + + set { + GeneXus_Common_DynamicCallMethodProperties_externalReference = (GeneXus.DynamicCall.GxDynCallMethodConf)(value); + } + + } + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo + { + get { + return _typeProps ; + } + + set { + _typeProps = value ; + } + + } + + public void initialize( ) + { + return ; + } + + protected GeneXus.DynamicCall.GxDynCallMethodConf GeneXus_Common_DynamicCallMethodProperties_externalReference=null ; + } + +} diff --git a/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs new file mode 100644 index 000000000..a2843b72b --- /dev/null +++ b/dotnet/test/DotNetUnitTest/Domain/type_SdtDynamicCallPropertiesNet.cs @@ -0,0 +1,120 @@ +/* + File: genexus.common.type_SdtDynamicCallPropertiesNet + Description: DynamicCallPropertiesNet + Author: GeneXus .NET Generator version 18_0_11-185337 + Generated on: 11/28/2024 9:54:49.49 + 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 SdtDynamicCallPropertiesNet : GxUserType, IGxExternalObject + { + public SdtDynamicCallPropertiesNet( ) + { + /* Constructor for serialization */ + } + + public SdtDynamicCallPropertiesNet( 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 string gxTpr_Externalname + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference.ExternalName ; + } + + set { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + GeneXus_Common_DynamicCallPropertiesNet_externalReference.ExternalName = value; + SetDirty("Externalname"); + } + + } + + public string gxTpr_Assemblyname + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference.AssemblyName ; + } + + set { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + GeneXus_Common_DynamicCallPropertiesNet_externalReference.AssemblyName = value; + SetDirty("Assemblyname"); + } + + } + + public Object ExternalInstance + { + get { + if ( GeneXus_Common_DynamicCallPropertiesNet_externalReference == null ) + { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = new GeneXus.DynamicCall.GxDynCallProperties(); + } + return GeneXus_Common_DynamicCallPropertiesNet_externalReference ; + } + + set { + GeneXus_Common_DynamicCallPropertiesNet_externalReference = (GeneXus.DynamicCall.GxDynCallProperties)(value); + } + + } + + [XmlIgnore] + private static GXTypeInfo _typeProps; + protected override GXTypeInfo TypeInfo + { + get { + return _typeProps ; + } + + set { + _typeProps = value ; + } + + } + + public void initialize( ) + { + return ; + } + + protected GeneXus.DynamicCall.GxDynCallProperties GeneXus_Common_DynamicCallPropertiesNet_externalReference=null ; + } + +}