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))); }
/// <summary> /// Returns the value of the specified field as a pointer to RFCTYPE_STRUCTURE /// </summary> /// <param name="handler"></param> /// <param name="map"></param> /// <returns></returns> protected static IntPtr GetStructure(IntPtr handler, PropertyMap map) { var rc = RfcInterop.RfcGetStructure(handler, map.RfcParameterName, out IntPtr structHandle, out var errorInfo); rc.OnErrorThrowException(errorInfo); return(structHandle); }
public static TOutput Extract <TOutput>(RfcInterop interop, IntPtr dataHandle) { Type outputType = typeof(TOutput); Func <RfcInterop, IntPtr, object> extractFunc = ExtractFuncsCache.GetOrAdd(outputType, BuildExtractFunc); return((TOutput)extractFunc(interop, dataHandle)); }
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))); }
/// <summary> /// sets the value of a RFC STRING field /// </summary> /// <param name="dataHandle">handle to container</param> /// <param name="name">field name</param> internal void SetFieldValue(IntPtr dataHandle, string name) { var buffer = RfcValue.ToCharArray(); var rc = RfcInterop.RfcSetChars(dataHandle, name, buffer, (uint)buffer.Length, out var errorInfo); rc.OnErrorThrowException(errorInfo); }
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)); }
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); }
private static RfcResultCode HandleGenericFunction(RfcInterop interop, Action <ISapServerConnection, ISapServerFunction> action, IntPtr connectionHandle, IntPtr functionHandle, out RfcErrorInfo errorInfo) { IntPtr functionDesc = interop.DescribeFunction( rfcHandle: functionHandle, errorInfo: out RfcErrorInfo functionDescErrorInfo); if (functionDescErrorInfo.Code != RfcResultCode.RFC_OK) { errorInfo = functionDescErrorInfo; return(functionDescErrorInfo.Code); } var connection = new SapServerConnection(interop, connectionHandle); var function = new SapServerFunction(interop, functionHandle, functionDesc); try { action(connection, function); errorInfo = default; return(RfcResultCode.RFC_OK); } catch (Exception ex) { errorInfo = new RfcErrorInfo { Code = RfcResultCode.RFC_EXTERNAL_FAILURE, Message = ex.Message, }; return(RfcResultCode.RFC_EXTERNAL_FAILURE); } }
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)); }
/// <summary> /// Defines Trace Level /// </summary> /// <param name="destination">The server destination definined in sapnwrfc.ini</param> /// <param name="traceLevel">The trace level to use.</param> public void SetTraceLevel(string destination, TraceLevel traceLevel) { ThrowEhenConnectionIsClosed(); var rc = RfcInterop.RfcSetTraceLevel(ConnectionHandle, destination, (uint)traceLevel, out var errorInfo); rc.OnErrorThrowException(errorInfo); }
/// <summary> /// sets the value of a RFC date field /// </summary> /// <param name="dataHandle">handle to container</param> /// <param name="name">field name</param> internal void SetFieldValue(IntPtr dataHandle, string name) { if (RfcValue != null) { var rc = RfcInterop.RfcSetDate(dataHandle, name, ToBuffer(), out var errorInfo); rc.OnErrorThrowException(errorInfo); } }
/// <summary> /// Gets the value of a RFC STRING field /// </summary> /// <param name="dataHandle">handle to container</param> /// <param name="name">field name</param> /// <returns></returns> internal static RfcChar GetFieldValue(IntPtr dataHandle, string name, int length) { char[] buffer = new char[length]; var rc = RfcInterop.RfcGetChars(dataHandle, name, buffer, (uint)buffer.Length, out var errorInfo); rc.OnErrorThrowException(errorInfo); return(new RfcChar(buffer, buffer.Length)); }
/// <summary> /// Opens the connection. /// </summary> public void Open() { ThrowWhenConnectionIsOpen(); var parms = CreateInteropConnectionParameters(options.Parameters); ConnectionHandle = RfcInterop.RfcOpenConnection(parms, (uint)parms.Length, out var errorInfo); errorInfo.OnErrorThrowException(() => Clear()); }
internal SapServerFunction( RfcInterop interop, IntPtr functionHandle, IntPtr functionDescriptionHandle) { _interop = interop; _functionHandle = functionHandle; _functionDescriptionHandle = functionDescriptionHandle; }
private SapFunction( RfcInterop interop, IntPtr rfcConnectionHandle, IntPtr functionHandle) { _interop = interop; _rfcConnectionHandle = rfcConnectionHandle; _functionHandle = functionHandle; }
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); }
/// <summary> /// Closes the connection. /// </summary> public void Close() { if (ConnectionHandle == IntPtr.Zero) { return; } RfcInterop.RfcCloseConnection(ConnectionHandle, out var errorInfo); errorInfo.OnErrorThrowException(() => Clear()); Clear(); }
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 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)); }
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); }
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 static void Apply(RfcInterop interop, IntPtr dataHandle, object input) { if (input == null) { return; } Type inputType = input.GetType(); Action <RfcInterop, IntPtr, object> applyAction = ApplyActionsCache.GetOrAdd(inputType, BuildApplyAction); applyAction(interop, dataHandle, input); }
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 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); }
/// <summary> /// Closes current RFC function call. /// </summary> public void Close() { if (FunctionHandle == IntPtr.Zero) { return; } var rc = RfcInterop.RfcDestroyFunction(FunctionHandle, out var errorInfo); rc.OnErrorThrowException(errorInfo, () => Clear()); Clear(); }
internal static ISapServer Create(RfcInterop rfcInterop, SapConnectionParameters parameters) { RfcConnectionParameter[] interopParameters = parameters.ToInterop(); IntPtr rfcServerHandle = rfcInterop.CreateServer( connectionParams: interopParameters, paramCount: (uint)interopParameters.Length, errorInfo: out RfcErrorInfo errorInfo); errorInfo.ThrowOnError(); return(new SapServer(rfcInterop, rfcServerHandle, parameters)); }
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)); }