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 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))); }
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 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))); }
internal SapException(RfcResultCode resultCode, string message) : base(string.IsNullOrEmpty(message) ? $"SAP RFC Error: {resultCode}" : $"SAP RFC Error: {resultCode} with message: {message}") { ResultCode = resultCode; }
private static RfcResultCode HandleGenericMetadata(RfcInterop interop, SapConnectionParameters parameters, string functionName, RfcAttributes attributes, out IntPtr funcDescHandle) { RfcConnectionParameter[] interopParameters = parameters.ToInterop(); IntPtr connection = interop.OpenConnection( connectionParams: interopParameters, paramCount: (uint)interopParameters.Length, errorInfo: out RfcErrorInfo connectionErrorInfo); if (connectionErrorInfo.Code != RfcResultCode.RFC_OK) { funcDescHandle = IntPtr.Zero; return(connectionErrorInfo.Code); } funcDescHandle = interop.GetFunctionDesc( rfcHandle: connection, funcName: functionName, errorInfo: out RfcErrorInfo errorInfo); RfcResultCode resultCode = interop.CloseConnection( rfcHandle: connection, errorInfo: out RfcErrorInfo closeErrorInfo); return(errorInfo.Code); }
/// <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); }
public virtual RfcResultCode GetFunctionName(IntPtr rfcHandle, out string funcName, out RfcErrorInfo errorInfo) { var buffer = new StringBuilder(31); RfcResultCode resultCode = RfcGetFunctionName(rfcHandle, buffer, out errorInfo); funcName = buffer.ToString(); return(resultCode); }
/// <summary> /// Initializes a new instance of the <see cref="SapException"/> class. /// </summary> /// <param name="resultCode">The RFC result code.</param> /// <param name="errorInfo">The RFC error info object.</param> internal SapException(RfcResultCode resultCode, RfcErrorInfo errorInfo) : base(string.IsNullOrEmpty(errorInfo.Message) ? $"SAP RFC Error: {resultCode}" : $"SAP RFC Error: {resultCode} with message: {errorInfo.Message}") { ResultCode = SapResultCodeMapper.Map(resultCode); ErrorInfo = SapErrorInfo.Map(errorInfo); }
/// <summary> /// Disposes the server. Disposing automatically disconnects from the SAP application server. /// </summary> public void Dispose() { RfcResultCode resultCode = _interop.DestroyServer( rfcHandle: _rfcServerHandle, errorInfo: out RfcErrorInfo errorInfo); // resultCode.ThrowOnError(errorInfo); }
/// <inheritdoc cref="ISapServer"/> public void Launch() { RfcResultCode resultCode = _interop.LaunchServer( rfcHandle: _rfcServerHandle, errorInfo: 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); }
/// <inheritdoc cref="ISapFunction"/> public bool HasParameter(string parameterName) { RfcResultCode resultCode = _interop.GetParameterDescByName( funcDescHandle: _functionDescriptionHandle, parameterName: parameterName, parameterDescHandle: out IntPtr parameterDescHandle, errorInfo: out RfcErrorInfo errorInfo); return(resultCode == RfcResultCode.RFC_OK); }
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); }
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 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)); }
/// <inheritdoc cref="ISapTypeMetadata"/> public string GetName() { RfcResultCode resultCode = _interop.GetTypeName( rfcHandle: _typeDescription, typeName: out string typeName, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(typeName); }
public uint GetParameterCount() { RfcResultCode resultCode = _interop.GetParameterCount( funcDesc: _functionDescHandle, count: out uint count, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(count); }
/// <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)); }
private int GetExceptionCount() { RfcResultCode resultCode = _interop.GetExceptionCount( funcDesc: _functionDescHandle, count: out uint count, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return((int)count); }
private int GetFieldCount() { RfcResultCode resultCode = _interop.GetFieldCount( typeHandle: _typeDescription, count: out uint count, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return((int)count); }
/// <inheritdoc cref="ISapFunctionMetadata"/> public string GetName() { RfcResultCode resultCode = _interop.GetFunctionName( rfcHandle: _functionDescHandle, funcName: out string funcName, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(funcName); }
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); }
private ISapParameterMetadata GetParameterByIndex(int index) { RfcResultCode resultCode = _interop.GetParameterDescByIndex( funcDesc: _functionDescHandle, index: (uint)index, paramDesc: out RfcParameterDescription paramDesc, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(new SapParameterMetadata(_interop, paramDesc)); }
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(); }
private ISapExceptionMetadata GetExceptionByIndex(int index) { RfcResultCode resultCode = _interop.GetExceptionDescByIndex( funcDesc: _functionDescHandle, index: (uint)index, excDesc: out RfcExceptionDescription excDesc, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(new SapExceptionMetadata(excDesc)); }
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)); }
private ISapFieldMetadata GetFieldByIndex(int index) { RfcResultCode resultCode = _interop.GetFieldDescByIndex( typeHandle: _typeDescription, index: (uint)index, fieldDesc: out RfcFieldDescription fieldDesc, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(new SapFieldMetadata(_interop, fieldDesc)); }
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)); }