Skip to content

Commit c983af9

Browse files
authored
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.
1 parent 1cc526f commit c983af9

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

src/YaNco.Abstractions/IConnection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,13 @@ public interface IConnection : IDisposable
120120
IRfcRuntime RfcRuntime { get; }
121121

122122
IHasEnvRuntimeSettings ConnectionRuntime { get; }
123+
124+
/// <summary>
125+
/// Direct access to the connection handle.
126+
/// </summary>
127+
/// <remarks>
128+
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IConnection"/> interface.
129+
/// When operating on the handle, you have to make sure that the connection is accessed in a thread safe manner.
130+
/// </remarks>
131+
IConnectionHandle Handle { get; }
123132
}

src/YaNco.Abstractions/IDataContainer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ public interface IDataContainer : IDisposable
1414
Either<RfcError, IStructure> GetStructure(string name);
1515
Either<RfcError, ITable> GetTable(string name);
1616
Either<RfcError, ITypeDescriptionHandle> GetTypeDescription();
17+
18+
/// <summary>
19+
/// Direct access to the container handle.
20+
/// </summary>
21+
/// <remarks>
22+
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IDataContainer"/> interface.
23+
/// </remarks>
24+
IDataContainerHandle Handle { get; }
1725
}

src/YaNco.Abstractions/IFunction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ namespace Dbosoft.YaNco;
44

55
public interface IFunction : IDataContainer
66
{
7+
/// <summary>
8+
/// Direct access to the function handle.
9+
/// </summary>
10+
/// <remarks>
11+
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IFunction"/> interface.
12+
/// </remarks>
713
[Browsable(false)]
8-
IFunctionHandle Handle { get; }
14+
new IFunctionHandle Handle { get; }
915
}

src/YaNco.Core/Connection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Connection<RT> : IConnection
2828
_runtime.Env.Source, _runtime.Env.Settings));
2929

3030
public IHasEnvRuntimeSettings ConnectionRuntime => _runtime;
31+
public IConnectionHandle Handle => _connectionHandle;
3132

3233
public Connection(
3334
RT runtime,

src/YaNco.Core/ConnectionPlaceholder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ public EitherAsync<RfcError, ConnectionAttributes> GetAttributes()
8585
[Obsolete(Deprecations.RfcRuntime)]
8686
public IRfcRuntime RfcRuntime { get; } = new RfcRuntime(SAPRfcRuntime.Default);
8787
public IHasEnvRuntimeSettings ConnectionRuntime { get; } = SAPRfcRuntime.Default;
88-
88+
public IConnectionHandle Handle { get; }
8989
}

src/YaNco.Core/DataContainer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public Either<RfcError, ITypeDescriptionHandle> GetTypeDescription()
5353
return IO.GetTypeDescription(_handle);
5454
}
5555

56+
public IDataContainerHandle Handle => _handle;
57+
5658
protected virtual void Dispose(bool disposing)
5759
{
5860
if (disposing)

test/SAPSystemTests/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ from userName in getValue<string>(structure["FULLNAME"])
173173
result = await withFieldMapping.Run(SAPRfcRuntime.Default);
174174

175175
Console.WriteLine("call_getFullName_with_abapValue: " + result);
176+
177+
var paramsCall = useConnection(connectionEffect, connection =>
178+
from getUserFunction in connection.CreateFunction("BAPI_USER_GET_DETAIL").ToAff(l=>l)
179+
from rt in Prelude.runtime<SAPRfcRuntime>()
180+
from functionEff in rt.RfcFunctionsEff
181+
from dataEff in rt.RfcDataEff
182+
from funcDescription in functionEff.GetFunctionDescription(getUserFunction.Handle).ToEff(l => l)
183+
from userParam in functionEff.GetFunctionParameterDescription(funcDescription, "USERNAME").ToEff(l=>l)
184+
from paramsParam in functionEff.GetFunctionParameterDescription(funcDescription, "PARAMETER").ToEff(l => l)
185+
select (UserName: userParam, Params: paramsParam));
186+
187+
var paramsResult = await paramsCall.Run(SAPRfcRuntime.Default);
188+
Console.WriteLine("call_getParams_with_connection: " + paramsResult);
189+
176190
return;
177191

178192
static RfcError Callback(string command)

0 commit comments

Comments
 (0)