From 929107759ba5a3ad3e2f3a45b265253a5e7d516c Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Fri, 7 Jun 2024 12:02:41 -0300 Subject: [PATCH 1/3] - First implementation of SAP ERP access for netcore. Issue 100856 --- dotnet/DotNetStandardClasses.sln | 7 + .../GxEnterpriseLib/GXECSessionManager.cs | 350 ++++++++++++++++++ .../GxEnterpriseLib/GxEnterpriseConnect.cs | 41 ++ .../GxEnterpriseLib/GxEnterpriseLib.csproj | 20 + 4 files changed, 418 insertions(+) create mode 100644 dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs create mode 100644 dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs create mode 100644 dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj diff --git a/dotnet/DotNetStandardClasses.sln b/dotnet/DotNetStandardClasses.sln index 01e391f0b..a154aef19 100644 --- a/dotnet/DotNetStandardClasses.sln +++ b/dotnet/DotNetStandardClasses.sln @@ -263,6 +263,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogTest", "test\benchmarks\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccessTokenController_Test", "test\NativeAccessControllerTest\AccessTokenController_Test.csproj", "{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GxEnterpriseLib", "src\dotnetcore\GxEnterpriseLib\GxEnterpriseLib.csproj", "{2437D532-75FA-40C5-8384-B08C8417DCB4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -633,6 +635,10 @@ Global {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Debug|Any CPU.Build.0 = Debug|Any CPU {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.Build.0 = Release|Any CPU + {2437D532-75FA-40C5-8384-B08C8417DCB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2437D532-75FA-40C5-8384-B08C8417DCB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2437D532-75FA-40C5-8384-B08C8417DCB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2437D532-75FA-40C5-8384-B08C8417DCB4}.Release|Any CPU.Build.0 = Release|Any CPU {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -767,6 +773,7 @@ Global {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} {A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} {A5589382-DB6F-4450-AE2B-6C6AA1643EF1} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} + {2437D532-75FA-40C5-8384-B08C8417DCB4} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C} diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs b/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs new file mode 100644 index 000000000..10378a21f --- /dev/null +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs @@ -0,0 +1,350 @@ +using System; +using System.ServiceModel; +using System.Xml; +using System.Runtime.Serialization; +using GeneXus.Application; +using SapNwRfc; +using SapNwRfc.Pooling; + +namespace GeneXus.SAP +{ + + public class GXECSessionManager + { + + ISapConnection connection = null; + //GxEnterpriseConnect GxConnect = null; + IGxContext _context; + string _connectionString = null; + static SapConnectionPool _pool; + + public GXECSessionManager(IGxContext context) + { + _context = context; + this.SessionName = _context.GetContextProperty("SAP-Session") as string; + _connectionString = _context.GetContextProperty("SAP-ConnStr") as string; + + } + + String userName; + public String UserName + { + get { return userName; } + set { userName = value; } + } + String password; + + public String Password + { + get { return password; } + set { password = value; } + } + String appServer; + + public String AppServer + { + get { return appServer; } + set { appServer = value; } + } + String instanceNumber; + + public String InstanceNumber + { + get { return instanceNumber; } + set { instanceNumber = value; } + } + String clientNumber; + + public String ClientNumber + { + get { return clientNumber; } + set { clientNumber = value; } + } + String routerString; + + public String RouterString + { + get { return routerString; } + set { routerString = value; } + } + String systemId; + + public String SystemId + { + get { return systemId; } + set { systemId = value; } + } + String sessionName; + + public String SessionName + { + get { return sessionName; } + set { + sessionName = value; + } + } + String sAPGUI; + + public String SAPGUI + { + get { return sAPGUI; } + set { sAPGUI = value; } + } + + String lang; + public String Language + { + get { return lang; } + set { lang = value; } + } + + String msHost; + public string MessageHost + { + get { return msHost; } + set { msHost = value; } + } + + String msServ; + public string MessageSrv + { + get { return msServ; } + set { msServ = value; } + } + + String group; + public String Group + { + get { return group; } + set { group = value; } + } + String sPort; + public String Port + { + get { return sPort; } + set { sPort = value;} + } + + String sapRouter; + public String SAPRouter + { + get { return sapRouter; } + set { sapRouter = value; } + } + + String sGatewayHost; + public String GatewayHost + { + get { return sGatewayHost; } + set { sGatewayHost = value; } + } + + String sGatewaySrv; + public String GatewaySrv + { + get { return sGatewaySrv; } + set { sGatewaySrv = value; } + } + + String sProgramID; + public String ProgramID + { + get { return sProgramID; } + set { sProgramID = value; } + } + + String sRegistrationCount; + public String RegistrationCount + { + get { return sRegistrationCount; } + set { sRegistrationCount = value; } + } + + String sServerName; + public String ServerName + { + get { return sServerName; } + set { sServerName = value; } + } + + int errorCode; + + public string ConnectionString + { + get { + if (String.IsNullOrEmpty(_connectionString)) + { + return "AppServerHost=" + this.RouterString + this.AppServer + ";" + + "SystemNumber=" + this.instanceNumber + ";" + + "User=" + this.UserName + ";" + + "Password=" + this.Password + ";" + + "Client=" + this.ClientNumber + ";" + + "PoolSize=" + "5" + ";" + + "Language=" + this.Language; + } + else + { + return _connectionString; + } + } + } + public int ErrorCode + { + get + { + return errorCode; + } + set + { + errorCode = value; + } + } + String errorMessage; + + public string ErrorMessage + { + get + { + return errorMessage; + } + set + { + errorMessage = value; + } + } + + public void Save() + { + } + + public void Load() + { + + } + + public void DocumentReceiverStart() + { + //connection.StartReceiverServer(); + } + + public void DocumentSenderStart() + { + //connection.StartSenderServer(); + } + + public void DocumentSenderStop() + { + //connection.StopSender(); + } + + public void DocumentReceiverStop() + { + // connection.StopReceiver(); + } + + public void TransactionBegin() + { + // connection.TransactionBegin(); + } + + public void TransactionCommit() + { + // connection.TransactionCommit(); + } + + private ISapConnection FindConnection() + { + /* + if (connection != null) + { + return connection; + } + else + { + string _session = ""; + if (!String.IsNullOrEmpty(this.sessionName)) + { + _session = this.sessionName; + } + else + { + Object objectSession = _context.GetContextProperty("SessionName"); + if (objectSession != null && !String.IsNullOrEmpty((String)objectSession)) + { + this.sessionName = (String)objectSession; + _session = this.sessionName; + } + } + this.sessionName = _session; + connection = new GxEnterpriseConnect(this); + return connection; + } + */ + return null; + + } + public void Disconnect() + { + //connection = FindConnection(); + if (connection != null) + { + connection.Disconnect(); + } + } + + public bool IsConnected() + { + //connection = FindConnection(); + if(connection != null) + return connection.IsValid; + else + return false; + + } + + public void ConnectSession(string SessionName, string Scope) + { + Connect(); + } + + public ISapConnection GetCurrentConnection() + { + if (errorCode == 0) + return connection; + else + return null; + } + + + public void Connect() + { + try + { + if (connection == null) + { + if (_pool==null) + _pool = new SapConnectionPool(ConnectionString); + _context.SetContextProperty("SAP-Session", this.SessionName); + _context.SetContextProperty("SAP-ConnStr", ConnectionString); + connection = _pool.GetConnection(); + //GxConnect = new GxEnterpriseConnect(this); + bool result = connection.Ping(); + if (result) + { + errorCode = 0; + errorMessage = ""; + } + else + { + errorCode = 1; + } + } + } + catch (Exception e) + { + errorCode = 2; + errorMessage = e.Message; + } + } + } +} diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs new file mode 100644 index 000000000..9606990e9 --- /dev/null +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs @@ -0,0 +1,41 @@ +using System; +using GeneXus.Utils; +using GeneXus.Application; +using SapNwRfc; + +namespace GeneXus.SAP +{ + public class GxEnterpriseConnect { + public GxEnterpriseConnect(GXECSessionManager manager) + { + if (manager != null) + { + this.SessionManager = manager; + } + } + public GxEnterpriseConnect(IGxContext context) + { + if (context!=null) + { + _sessionManager = new GXECSessionManager(context); + _sessionManager.Connect(); + _connection = _sessionManager.GetCurrentConnection(); + } + } + public ISapFunction CreateFunction(string functionName) + { + if (_connection != null) + return _connection.CreateFunction(functionName); + else + return null; + } + + ISapConnection _connection = null; + private GXECSessionManager _sessionManager = null; + public string ConnectionString { get => connectionString; set => connectionString = value; } + public GXECSessionManager SessionManager { get => _sessionManager; set => _sessionManager = value; } + public ISapConnection Connection { get => _connection; set => _connection = value; } + + private string connectionString; + } +} diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj new file mode 100644 index 000000000..bd4d0fb06 --- /dev/null +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj @@ -0,0 +1,20 @@ + + + + net6.0;net8.0 + Library + NETCORE;NODATIME + GeneXus.EnterpriseLib.SAP + enable + disable + + + + + + + + + + + From fc12eee6ef44a9f2cf6a9207ef44a26c56e812b5 Mon Sep 17 00:00:00 2001 From: AlejandroP Date: Wed, 3 Jul 2024 12:25:25 -0300 Subject: [PATCH 2/3] - Change ISapConnection for SapPooledConnection --- .../GxEnterpriseLib/GXECSessionManager.cs | 47 ++++++++----------- .../GxEnterpriseLib/GxEnterpriseConnect.cs | 8 +++- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs b/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs index 10378a21f..8e0a85c6e 100644 --- a/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GXECSessionManager.cs @@ -12,7 +12,7 @@ namespace GeneXus.SAP public class GXECSessionManager { - ISapConnection connection = null; + ISapPooledConnection pooledConnection = null; //GxEnterpriseConnect GxConnect = null; IGxContext _context; string _connectionString = null; @@ -244,6 +244,7 @@ public void DocumentReceiverStop() public void TransactionBegin() { + // connection.TransactionBegin(); } @@ -286,58 +287,50 @@ private ISapConnection FindConnection() public void Disconnect() { //connection = FindConnection(); - if (connection != null) - { - connection.Disconnect(); - } + //if (connection != null) + //{ + // connection.Disconnect(); + //} } public bool IsConnected() { //connection = FindConnection(); - if(connection != null) - return connection.IsValid; + + if (pooledConnection != null) + // return connection.IsValid; + return true; else return false; } - + public void ConnectSession(string SessionName, string Scope) { Connect(); } - public ISapConnection GetCurrentConnection() + public ISapPooledConnection GetCurrentConnection() { if (errorCode == 0) - return connection; + return pooledConnection; else return null; } - public void Connect() - { + { try { - if (connection == null) + if (pooledConnection == null) { - if (_pool==null) + if (_pool == null) _pool = new SapConnectionPool(ConnectionString); _context.SetContextProperty("SAP-Session", this.SessionName); _context.SetContextProperty("SAP-ConnStr", ConnectionString); - connection = _pool.GetConnection(); - //GxConnect = new GxEnterpriseConnect(this); - bool result = connection.Ping(); - if (result) - { - errorCode = 0; - errorMessage = ""; - } - else - { - errorCode = 1; - } + //connection = _pool.GetConnection(); + //bool result = connection.Ping(); + pooledConnection = new SapPooledConnection(_pool); } } catch (Exception e) @@ -345,6 +338,6 @@ public void Connect() errorCode = 2; errorMessage = e.Message; } - } + } } } diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs index 9606990e9..e2255794b 100644 --- a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseConnect.cs @@ -2,6 +2,7 @@ using GeneXus.Utils; using GeneXus.Application; using SapNwRfc; +using SapNwRfc.Pooling; namespace GeneXus.SAP { @@ -22,6 +23,8 @@ public GxEnterpriseConnect(IGxContext context) _connection = _sessionManager.GetCurrentConnection(); } } + + /* public ISapFunction CreateFunction(string functionName) { if (_connection != null) @@ -29,12 +32,13 @@ public ISapFunction CreateFunction(string functionName) else return null; } + */ - ISapConnection _connection = null; + ISapPooledConnection _connection = null; private GXECSessionManager _sessionManager = null; public string ConnectionString { get => connectionString; set => connectionString = value; } public GXECSessionManager SessionManager { get => _sessionManager; set => _sessionManager = value; } - public ISapConnection Connection { get => _connection; set => _connection = value; } + public ISapPooledConnection Connection { get => _connection; set => _connection = value; } private string connectionString; } From 77c39cb8d02968b1ad59f293e794d1c7d8711f97 Mon Sep 17 00:00:00 2001 From: claudiamurialdo <33756655+claudiamurialdo@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:25:28 -0300 Subject: [PATCH 3/3] Update GxEnterpriseLib.csproj --- dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj index bd4d0fb06..9d89b6601 100644 --- a/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj +++ b/dotnet/src/dotnetcore/GxEnterpriseLib/GxEnterpriseLib.csproj @@ -1,7 +1,7 @@ - net6.0;net8.0 + net8.0 Library NETCORE;NODATIME GeneXus.EnterpriseLib.SAP