public static DecimalField Extract(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: Array.Empty <char>(), bufferLength: 0, stringLength: out uint stringLength, errorInfo: out RfcErrorInfo errorInfo); if (resultCode != RfcResultCode.RFC_BUFFER_TOO_SMALL) { resultCode.ThrowOnError(errorInfo); return(new DecimalField(name, 0)); } var buffer = new char[stringLength + 1]; resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: buffer, bufferLength: (uint)buffer.Length, stringLength: out _, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); var decimalValue = decimal.Parse(new string(buffer, 0, (int)stringLength), CultureInfo.InvariantCulture); return(new DecimalField(name, decimalValue)); }
public static StringField Extract(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: Array.Empty <char>(), bufferLength: 0, stringLength: out uint stringLength, errorInfo: out RfcErrorInfo errorInfo); if (resultCode != RfcResultCode.RFC_BUFFER_TOO_SMALL) { resultCode.ThrowOnError(errorInfo); return(new StringField(name, string.Empty)); } var buffer = new char[stringLength + 1]; resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: buffer, bufferLength: (uint)buffer.Length, stringLength: out _, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); return(new StringField(name, new string(buffer, 0, (int)stringLength))); }
public static TableField <T> Extract <T>(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetTable( dataHandle: dataHandle, name: name, tableHandle: out IntPtr tableHandle, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); resultCode = interop.GetRowCount( tableHandle: tableHandle, rowCount: out uint rowCount, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); if (rowCount == 0) { return(new TableField <T>(name, Array.Empty <T>())); } var rows = new T[rowCount]; resultCode = interop.MoveToFirstRow( tableHandle: tableHandle, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); for (int i = 0; i < rowCount; i++) { IntPtr rowHandle = interop.GetCurrentRow( tableHandle: tableHandle, errorInfo: out errorInfo); errorInfo.ThrowOnError(); rows[i] = OutputMapper.Extract <T>(interop, rowHandle); resultCode = interop.MoveToNextRow( tableHandle: tableHandle, errorInfo: out errorInfo); if (resultCode == RfcResultCode.RFC_TABLE_MOVE_EOF) { Array.Resize(ref rows, i + 1); break; } resultCode.ThrowOnError(errorInfo); } return(new TableField <T>(name, rows)); }
public static TimeField Extract(RfcInterop interop, IntPtr dataHandle, string name) { char[] buffer = EmptyRfcTimeString.ToCharArray(); RfcResultCode resultCode = interop.GetTime( dataHandle: dataHandle, name: name, emptyTime: buffer, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); var timeString = new string(buffer); if (timeString == EmptyRfcTimeString || timeString == ZeroRfcTimeString) return new TimeField(name, null); Match match = Regex.Match(timeString, "^(?<Hours>[0-9]{2})(?<Minutes>[0-9]{2})(?<Seconds>[0-9]{2})$"); if (!match.Success) return new TimeField(name, null); int hours = int.Parse(match.Groups["Hours"].Value); int minutes = int.Parse(match.Groups["Minutes"].Value); int seconds = int.Parse(match.Groups["Seconds"].Value); return new TimeField(name, new TimeSpan(hours, minutes, seconds)); }
public static DateField Extract(RfcInterop interop, IntPtr dataHandle, string name) { char[] buffer = EmptyRfcDateString.ToCharArray(); RfcResultCode resultCode = interop.GetDate( dataHandle: dataHandle, name: name, emptyDate: buffer, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); string dateString = new string(buffer); if (dateString == EmptyRfcDateString || dateString == ZeroRfcDateString) { return(new DateField(name, null)); } Match match = Regex.Match(dateString, "^(?<Year>[0-9]{4})(?<Month>[0-9]{2})(?<Day>[0-9]{2})$"); if (!match.Success) { return(new DateField(name, null)); } int year = int.Parse(match.Groups["Year"].Value); int month = int.Parse(match.Groups["Month"].Value); int day = int.Parse(match.Groups["Day"].Value); return(new DateField(name, new DateTime(year, month, day))); }
/// <inheritdoc cref="ISapServer"/> public void Launch() { RfcResultCode resultCode = _interop.LaunchServer( rfcHandle: _rfcServerHandle, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
/// <summary> /// Disposes the SAP RFC function. Disposing automatically frees the underlying resource tied to this remote function. /// </summary> public void Dispose() { RfcResultCode resultCode = _interop.DestroyFunction( funcHandle: _functionHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
/// <inheritdoc cref="ISapServer"/> public void Shutdown(uint timeout) { RfcResultCode resultCode = _interop.ShutdownServer( rfcHandle: _rfcServerHandle, timeout: timeout, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
/// <inheritdoc cref="ISapFunction"/> public void Invoke() { RfcResultCode resultCode = _interop.Invoke( rfcHandle: _rfcConnectionHandle, funcHandle: _functionHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { RfcResultCode resultCode = interop.SetDate( dataHandle: dataHandle, name: Name, date: (Value?.ToString("yyyyMMdd") ?? ZeroRfcDateString).ToCharArray(), errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { RfcResultCode resultCode = interop.SetFloat( dataHandle: dataHandle, name: Name, value: Value, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
/// <inheritdoc cref="ISapServerFunction"/> public string GetName() { RfcResultCode resultCode = _interop.GetFunctionName( rfcHandle: _functionDescriptionHandle, funcName: out string functionName, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(functionName); }
internal static void InstallGenericServerFunctionHandler(RfcInterop interop, SapConnectionParameters parameters, Action <ISapServerConnection, ISapServerFunction> action) { RfcResultCode resultCode = interop.InstallGenericServerFunction( serverFunction: (IntPtr connectionHandle, IntPtr functionHandle, out RfcErrorInfo errorInfo) => HandleGenericFunction(interop, action, connectionHandle, functionHandle, out errorInfo), funcDescPointer: (string functionName, ref RfcAttributes attributes, out IntPtr funcDescHandle) => HandleGenericMetadata(interop, parameters, functionName, attributes, out funcDescHandle), out RfcErrorInfo installFunctionErrorInfo); resultCode.ThrowOnError(installFunctionErrorInfo); }
/// <inheritdoc cref="ISapServerConnection"/> public SapConnectionAttributes GetAttributes() { RfcResultCode resultCode = _interop.GetConnectionAttributes( rfcHandle: _rfcConnectionHandle, attributes: out RfcAttributes attributes, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new SapConnectionAttributes(attributes)); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { string stringValue = Value?.ToString("hhmmss") ?? ZeroRfcTimeString; RfcResultCode resultCode = interop.SetTime( dataHandle: dataHandle, name: Name, time: stringValue.ToCharArray(), out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public static DoubleField Extract(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetFloat( dataHandle: dataHandle, name: name, out double value, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new DoubleField(name, value)); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { RfcResultCode resultCode = interop.GetStructure( dataHandle: dataHandle, name: Name, structHandle: out IntPtr structHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); InputMapper.Apply(interop, structHandle, Value); }
public static LongField Extract(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetInt8( dataHandle: dataHandle, name: name, out long value, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new LongField(name, value)); }
public void ThrowOnError_NoError_ShouldNotThrow() { // Arrange RfcResultCode resultCode = RfcResultCode.RFC_OK; var errorInfo = default(RfcErrorInfo); // Act Action action = () => resultCode.ThrowOnError(errorInfo); // Assert action.Should().NotThrow(); }
public void ThrowOnError_NoError_ShouldNotCallBeforeThrowAction() { // Arrange RfcResultCode resultCode = RfcResultCode.RFC_OK; var errorInfo = default(RfcErrorInfo); var beforeThrowActionMock = new Mock <Action>(); // Act resultCode.ThrowOnError(errorInfo, beforeThrowActionMock.Object); // Assert beforeThrowActionMock.Verify(x => x(), Times.Never); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { var stringValue = Value.ToString(CultureInfo.InvariantCulture); RfcResultCode resultCode = interop.SetString( dataHandle: dataHandle, name: Name, value: stringValue, valueLength: (uint)stringValue.Length, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public static StructureField <T> Extract <T>(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetStructure( dataHandle: dataHandle, name: name, structHandle: out IntPtr structHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); T structValue = OutputMapper.Extract <T>(interop, structHandle); return(new StructureField <T>(name, structValue)); }
public static BytesField Extract(RfcInterop interop, IntPtr dataHandle, string name, int bufferLength) { var buffer = new byte[bufferLength]; RfcResultCode resultCode = interop.GetBytes( dataHandle: dataHandle, name: name, bytesBuffer: buffer, bufferLength: (uint)buffer.Length, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new BytesField(name, buffer)); }
public void ThrowOnError_InvalidParameter_ShouldThrowSapInvalidParameterException() { // Arrange RfcResultCode resultCode = RfcResultCode.RFC_INVALID_PARAMETER; var errorInfo = new RfcErrorInfo { Message = "Wrong parameter message" }; // Act Action action = () => resultCode.ThrowOnError(errorInfo); // Assert action.Should().Throw <SapInvalidParameterException>() .WithMessage("SAP RFC Error: RFC_INVALID_PARAMETER with message: Wrong parameter message"); }
public void ThrowOnError_CommunicationFailure_ShouldThrowSapCommunicationFailedException() { // Arrange RfcResultCode resultCode = RfcResultCode.RFC_COMMUNICATION_FAILURE; var errorInfo = new RfcErrorInfo { Message = "Failure error message" }; // Act Action action = () => resultCode.ThrowOnError(errorInfo); // Assert action.Should().Throw <SapCommunicationFailedException>() .WithMessage("SAP RFC Error: RFC_COMMUNICATION_FAILURE with message: Failure error message"); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { if (Value == null) { return; } RfcResultCode resultCode = interop.SetBytes( dataHandle: dataHandle, name: Name, value: Value, valueLength: (uint)Value.Length, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public override void Apply(RfcInterop interop, IntPtr dataHandle) { RfcResultCode resultCode = interop.GetTable( dataHandle: dataHandle, name: Name, out IntPtr tableHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); foreach (TItem row in Value) { IntPtr lineHandle = interop.AppendNewRow(tableHandle, out errorInfo); errorInfo.ThrowOnError(); InputMapper.Apply(interop, lineHandle, row); } }
public void ThrowOnError_Error_ShouldCallBeforeThrowActionAndThrowRfcException() { // Arrange RfcResultCode resultCode = RfcResultCode.RFC_CLOSED; var errorInfo = new RfcErrorInfo { Message = "Connection closed" }; var beforeThrowActionMock = new Mock <Action>(); // Act Action action = () => resultCode.ThrowOnError(errorInfo, beforeThrowActionMock.Object); // Assert action.Should().Throw <SapException>() .Which.Message.Should().Be("SAP RFC Error: RFC_CLOSED with message: Connection closed"); beforeThrowActionMock.Verify(x => x(), Times.Once); }
private void Disconnect(bool disposing) { if (_rfcConnectionHandle == IntPtr.Zero) { return; } RfcResultCode resultCode = _interop.CloseConnection( rfcHandle: _rfcConnectionHandle, errorInfo: out RfcErrorInfo errorInfo); Clear(); if (!disposing) { resultCode.ThrowOnError(errorInfo); } }