public static StringField Extract(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: Array.Empty <char>(), bufferLength: 0, stringLength: out uint stringLength, errorInfo: out RfcErrorInfo errorInfo); if (resultCode != RfcResultCodes.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 DecimalField Extract(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetString( dataHandle: dataHandle, name: name, stringBuffer: Array.Empty <char>(), bufferLength: 0, stringLength: out uint stringLength, errorInfo: out RfcErrorInfo errorInfo); if (resultCode != RfcResultCodes.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)); }
private RfcFieldDescription GetFieldDescriptionByIndex(IntPtr typeDescriptionHandler, int index) { RfcResultCodes result = _interop.GetFieldDescByIndex(typeDescriptionHandler, index, out RfcFieldDescription fieldDesc, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); return(fieldDesc); }
private RfcParameterDescription GetParameterDescriptionByName(string parameterName) { RfcResultCodes result = _interop.GetParameterDescByName(_functionDescriptionHandle, parameterName, out RfcParameterDescription paramDesc, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); return(paramDesc); }
private RfcParameterDescription GetParameterDescriptionByIndex(int index) { RfcResultCodes result = _interop.GetParameterDescByIndex(_functionDescriptionHandle, index, out RfcParameterDescription paramDesc, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); return(paramDesc); }
private RfcFieldDescription GetFieldDescriptionByName(IntPtr typeDescriptionHandler, string fieldName) { RfcResultCodes result = _interop.GetFieldDescByName(typeDescriptionHandler, fieldName, out RfcFieldDescription fieldDesc, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); return(fieldDesc); }
public static TimeField Extract(IRfcInterop interop, IntPtr dataHandle, string name) { char[] buffer = EmptyRfcTimeString.ToCharArray(); RfcResultCodes 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(IRfcInterop interop, IntPtr dataHandle, string name) { char[] buffer = EmptyRfcDateString.ToCharArray(); RfcResultCodes 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))); }
public void ThrowOnError_NoError_ShouldNotThrow() { RfcResultCodes resultCode = RfcResultCodes.RFC_OK; var errorInfo = default(RfcErrorInfo); Action action = () => resultCode.ThrowOnError(errorInfo); action.Should().NotThrow(); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { RfcResultCodes resultCode = interop.SetFloat( dataHandle: dataHandle, name: Name, value: Value, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public static TableField <T> Extract <T>(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetTable( dataHandle: dataHandle, name: name, tableHandle: out IntPtr tableHandle, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); resultCode = interop.GetRowCount( tableHandle: tableHandle, out uint rowCount, out errorInfo); resultCode.ThrowOnError(errorInfo); var rows = new T[rowCount]; 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 == RfcResultCodes.RFC_TABLE_MOVE_EOF) { return(new TableField <T>(name, rows.Take(i + 1).ToArray())); } resultCode.ThrowOnError(errorInfo); } return(new TableField <T>(name, rows)); }
private IntPtr GetTransactionHandle(IRfcInterop interop) { RfcResultCodes resultCode = _interop.GetTransactionId(_rfcConnectionHandle, out var tid, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); IntPtr result = _interop.CreateTransaction(_rfcConnectionHandle, tid, null, out errorInfo); errorInfo.ThrowOnError(); return(result); }
public void ThrowOnError_NoError_ShouldNotCallBeforeThrowAction() { RfcResultCodes resultCode = RfcResultCodes.RFC_OK; var errorInfo = default(RfcErrorInfo); var beforeThrowActionMock = new Mock <Action>(); resultCode.ThrowOnError(errorInfo, beforeThrowActionMock.Object); beforeThrowActionMock.Verify(x => x(), Times.Never); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { RfcResultCodes resultCode = interop.SetDate( dataHandle: dataHandle, name: Name, date: (Value?.ToString("yyyyMMdd") ?? ZeroRfcDateString).ToCharArray(), errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public virtual void Dispose() { if (_functionHandle == IntPtr.Zero) { return; } RfcResultCodes resultCode = _interop.DestroyFunction(_functionHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
private int GetParameterCount() { RfcResultCodes result = _interop.GetParameterCount(_functionDescriptionHandle, out int count, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); if (count <= 0) { throw new RfcException("Function have not a any parameter"); } return(count); }
private int GetFieldCount(IntPtr typeDescriptionHandler) { RfcResultCodes result = _interop.GetFieldCount(typeDescriptionHandler, out int count, out RfcErrorInfo errorInfo); result.ThrowOnError(errorInfo); if (count <= 0) { throw new RfcException("Parameter have not a any field"); } return(count); }
private void Destroy() { if (_functionHandle == IntPtr.Zero) { return; } RfcResultCodes resultCode = _interop.DestroyFunction(_functionHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public static DoubleField Extract(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetFloat( dataHandle: dataHandle, name: name, out double value, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new DoubleField(name, value)); }
public void ThrowOnError_InvalidParameter_ShouldThrowSapInvalidParameterException() { RfcResultCodes resultCode = RfcResultCodes.RFC_INVALID_PARAMETER; var errorInfo = new RfcErrorInfo { Message = "Wrong parameter message" }; Action action = () => resultCode.ThrowOnError(errorInfo); action.Should().Throw <RfcInvalidParameterException>() .WithMessage("SAP RFC Error: RFC_INVALID_PARAMETER with message: Wrong parameter message"); }
public void ThrowOnError_CommunicationFailure_ShouldThrowSapCommunicationFailedException() { RfcResultCodes resultCode = RfcResultCodes.RFC_COMMUNICATION_FAILURE; var errorInfo = new RfcErrorInfo { Message = "Failure error message" }; Action action = () => resultCode.ThrowOnError(errorInfo); action.Should().Throw <RfcCommunicationFailedException>() .WithMessage("SAP RFC Error: RFC_COMMUNICATION_FAILURE with message: Failure error message"); }
public static LongField Extract(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetInt8( dataHandle: dataHandle, name: name, out long value, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); return(new LongField(name, value)); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { RfcResultCodes resultCode = interop.GetStructure( dataHandle: dataHandle, name: Name, structHandle: out IntPtr structHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); InputMapper.Apply(interop, structHandle, Value); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { string stringValue = Value?.ToString("hhmmss") ?? ZeroRfcTimeString; RfcResultCodes resultCode = interop.SetTime( dataHandle: dataHandle, name: Name, time: stringValue.ToCharArray(), out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { var stringValue = Value.ToString(CultureInfo.InvariantCulture); RfcResultCodes resultCode = interop.SetString( dataHandle: dataHandle, name: Name, value: stringValue, valueLength: (uint)stringValue.Length, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public void ThrowOnError_Error_ShouldCallBeforeThrowActionAndThrowRfcException() { RfcResultCodes resultCode = RfcResultCodes.RFC_CANCELED; var errorInfo = new RfcErrorInfo { Message = "Connection canceled" }; var beforeThrowActionMock = new Mock <Action>(); Action action = () => resultCode.ThrowOnError(errorInfo, beforeThrowActionMock.Object); action.Should().Throw <RfcException>().Which.Message.Should().Be("SAP RFC Error: RFC_CANCELED with message: Connection canceled"); beforeThrowActionMock.Verify(x => x(), Times.Once); }
public static StructureField <T> Extract <T>(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes 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)); }
private void Disconnect(bool disposing) { if (_rfcConnectionHandle == IntPtr.Zero) { return; } RfcResultCodes resultCode = _interop.CloseConnection(rfcHandle: _rfcConnectionHandle, errorInfo: out RfcErrorInfo errorInfo); Clear(); if (!disposing) { resultCode.ThrowOnError(errorInfo); } }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { if (Value == null) { return; } RfcResultCodes resultCode = interop.SetString( dataHandle: dataHandle, name: Name, value: Value, valueLength: (uint)Value.Length, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); }
public override void Apply(IRfcInterop interop, IntPtr dataHandle) { RfcResultCodes resultCode = interop.GetTable( dataHandle: dataHandle, name: Name, out IntPtr tableHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); if (Value == null) { return; } foreach (TItem row in Value) { IntPtr lineHandle = interop.AppendNewRow(tableHandle, out errorInfo); errorInfo.ThrowOnError(); InputMapper.Apply(interop, lineHandle, row); } }