Skip to content

Commit

Permalink
Allow direct access to connection and datacontainer handles (#317)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fw2568 authored Dec 2, 2024
1 parent 1cc526f commit c983af9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/YaNco.Abstractions/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,13 @@ public interface IConnection : IDisposable
IRfcRuntime RfcRuntime { get; }

IHasEnvRuntimeSettings ConnectionRuntime { get; }

/// <summary>
/// Direct access to the connection handle.
/// </summary>
/// <remarks>
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IConnection"/> interface.
/// When operating on the handle, you have to make sure that the connection is accessed in a thread safe manner.
/// </remarks>
IConnectionHandle Handle { get; }
}
8 changes: 8 additions & 0 deletions src/YaNco.Abstractions/IDataContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public interface IDataContainer : IDisposable
Either<RfcError, IStructure> GetStructure(string name);
Either<RfcError, ITable> GetTable(string name);
Either<RfcError, ITypeDescriptionHandle> GetTypeDescription();

/// <summary>
/// Direct access to the container handle.
/// </summary>
/// <remarks>
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IDataContainer"/> interface.
/// </remarks>
IDataContainerHandle Handle { get; }
}
8 changes: 7 additions & 1 deletion src/YaNco.Abstractions/IFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Dbosoft.YaNco;

public interface IFunction : IDataContainer
{
/// <summary>
/// Direct access to the function handle.
/// </summary>
/// <remarks>
/// Use this property only if you would like to call runtime api methods that are not covered by the <see cref="IFunction"/> interface.
/// </remarks>
[Browsable(false)]
IFunctionHandle Handle { get; }
new IFunctionHandle Handle { get; }
}
1 change: 1 addition & 0 deletions src/YaNco.Core/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Connection<RT> : IConnection
_runtime.Env.Source, _runtime.Env.Settings));

public IHasEnvRuntimeSettings ConnectionRuntime => _runtime;
public IConnectionHandle Handle => _connectionHandle;

public Connection(
RT runtime,
Expand Down
2 changes: 1 addition & 1 deletion src/YaNco.Core/ConnectionPlaceholder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ public EitherAsync<RfcError, ConnectionAttributes> GetAttributes()
[Obsolete(Deprecations.RfcRuntime)]
public IRfcRuntime RfcRuntime { get; } = new RfcRuntime(SAPRfcRuntime.Default);
public IHasEnvRuntimeSettings ConnectionRuntime { get; } = SAPRfcRuntime.Default;

public IConnectionHandle Handle { get; }
}
2 changes: 2 additions & 0 deletions src/YaNco.Core/DataContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public Either<RfcError, ITypeDescriptionHandle> GetTypeDescription()
return IO.GetTypeDescription(_handle);
}

public IDataContainerHandle Handle => _handle;

protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand Down
14 changes: 14 additions & 0 deletions test/SAPSystemTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ from userName in getValue<string>(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<SAPRfcRuntime>()
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)
Expand Down

0 comments on commit c983af9

Please sign in to comment.