From c983af9d83137c48aa557144b1b3ca4ab3014b90 Mon Sep 17 00:00:00 2001 From: Frank Wagner Date: Mon, 2 Dec 2024 12:04:51 +0100 Subject: [PATCH] Allow direct access to connection and datacontainer handles (#317) For calling APIs directly from the functional interfaces handles have to be used for connections and data containers. These are now also exposed on the default interfaces. --- src/YaNco.Abstractions/IConnection.cs | 9 +++++++++ src/YaNco.Abstractions/IDataContainer.cs | 8 ++++++++ src/YaNco.Abstractions/IFunction.cs | 8 +++++++- src/YaNco.Core/Connection.cs | 1 + src/YaNco.Core/ConnectionPlaceholder.cs | 2 +- src/YaNco.Core/DataContainer.cs | 2 ++ test/SAPSystemTests/Program.cs | 14 ++++++++++++++ 7 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/YaNco.Abstractions/IConnection.cs b/src/YaNco.Abstractions/IConnection.cs index 632611a7..085eae81 100644 --- a/src/YaNco.Abstractions/IConnection.cs +++ b/src/YaNco.Abstractions/IConnection.cs @@ -120,4 +120,13 @@ public interface IConnection : IDisposable IRfcRuntime RfcRuntime { get; } IHasEnvRuntimeSettings ConnectionRuntime { get; } + + /// + /// Direct access to the connection handle. + /// + /// + /// Use this property only if you would like to call runtime api methods that are not covered by the interface. + /// When operating on the handle, you have to make sure that the connection is accessed in a thread safe manner. + /// + IConnectionHandle Handle { get; } } \ No newline at end of file diff --git a/src/YaNco.Abstractions/IDataContainer.cs b/src/YaNco.Abstractions/IDataContainer.cs index 13ed3521..1f36e379 100644 --- a/src/YaNco.Abstractions/IDataContainer.cs +++ b/src/YaNco.Abstractions/IDataContainer.cs @@ -14,4 +14,12 @@ public interface IDataContainer : IDisposable Either GetStructure(string name); Either GetTable(string name); Either GetTypeDescription(); + + /// + /// Direct access to the container handle. + /// + /// + /// Use this property only if you would like to call runtime api methods that are not covered by the interface. + /// + IDataContainerHandle Handle { get; } } \ No newline at end of file diff --git a/src/YaNco.Abstractions/IFunction.cs b/src/YaNco.Abstractions/IFunction.cs index f6a5a7c5..f4bca42e 100644 --- a/src/YaNco.Abstractions/IFunction.cs +++ b/src/YaNco.Abstractions/IFunction.cs @@ -4,6 +4,12 @@ namespace Dbosoft.YaNco; public interface IFunction : IDataContainer { + /// + /// Direct access to the function handle. + /// + /// + /// Use this property only if you would like to call runtime api methods that are not covered by the interface. + /// [Browsable(false)] - IFunctionHandle Handle { get; } + new IFunctionHandle Handle { get; } } \ No newline at end of file diff --git a/src/YaNco.Core/Connection.cs b/src/YaNco.Core/Connection.cs index f5b3b01d..3aa7a345 100644 --- a/src/YaNco.Core/Connection.cs +++ b/src/YaNco.Core/Connection.cs @@ -28,6 +28,7 @@ public class Connection : IConnection _runtime.Env.Source, _runtime.Env.Settings)); public IHasEnvRuntimeSettings ConnectionRuntime => _runtime; + public IConnectionHandle Handle => _connectionHandle; public Connection( RT runtime, diff --git a/src/YaNco.Core/ConnectionPlaceholder.cs b/src/YaNco.Core/ConnectionPlaceholder.cs index 1d2b13df..c783f722 100644 --- a/src/YaNco.Core/ConnectionPlaceholder.cs +++ b/src/YaNco.Core/ConnectionPlaceholder.cs @@ -85,5 +85,5 @@ public EitherAsync GetAttributes() [Obsolete(Deprecations.RfcRuntime)] public IRfcRuntime RfcRuntime { get; } = new RfcRuntime(SAPRfcRuntime.Default); public IHasEnvRuntimeSettings ConnectionRuntime { get; } = SAPRfcRuntime.Default; - + public IConnectionHandle Handle { get; } } \ No newline at end of file diff --git a/src/YaNco.Core/DataContainer.cs b/src/YaNco.Core/DataContainer.cs index f1fe9627..d8a86b26 100644 --- a/src/YaNco.Core/DataContainer.cs +++ b/src/YaNco.Core/DataContainer.cs @@ -53,6 +53,8 @@ public Either GetTypeDescription() return IO.GetTypeDescription(_handle); } + public IDataContainerHandle Handle => _handle; + protected virtual void Dispose(bool disposing) { if (disposing) diff --git a/test/SAPSystemTests/Program.cs b/test/SAPSystemTests/Program.cs index c8af2382..82c0bc06 100644 --- a/test/SAPSystemTests/Program.cs +++ b/test/SAPSystemTests/Program.cs @@ -173,6 +173,20 @@ from userName in getValue(structure["FULLNAME"]) result = await withFieldMapping.Run(SAPRfcRuntime.Default); Console.WriteLine("call_getFullName_with_abapValue: " + result); + + var paramsCall = useConnection(connectionEffect, connection => + from getUserFunction in connection.CreateFunction("BAPI_USER_GET_DETAIL").ToAff(l=>l) + from rt in Prelude.runtime() + from functionEff in rt.RfcFunctionsEff + from dataEff in rt.RfcDataEff + from funcDescription in functionEff.GetFunctionDescription(getUserFunction.Handle).ToEff(l => l) + from userParam in functionEff.GetFunctionParameterDescription(funcDescription, "USERNAME").ToEff(l=>l) + from paramsParam in functionEff.GetFunctionParameterDescription(funcDescription, "PARAMETER").ToEff(l => l) + select (UserName: userParam, Params: paramsParam)); + + var paramsResult = await paramsCall.Run(SAPRfcRuntime.Default); + Console.WriteLine("call_getParams_with_connection: " + paramsResult); + return; static RfcError Callback(string command)