예제 #1
0
        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));
        }
예제 #2
0
        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)));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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)));
        }
예제 #5
0
 internal SapException(RfcResultCode resultCode, string message)
     : base(string.IsNullOrEmpty(message)
         ? $"SAP RFC Error: {resultCode}"
         : $"SAP RFC Error: {resultCode} with message: {message}")
 {
     ResultCode = resultCode;
 }
예제 #6
0
        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);
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
        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);
        }
예제 #9
0
 /// <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);
 }
예제 #10
0
        /// <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);
        }
예제 #11
0
        /// <inheritdoc cref="ISapServer"/>
        public void Launch()
        {
            RfcResultCode resultCode = _interop.LaunchServer(
                rfcHandle: _rfcServerHandle,
                errorInfo: out RfcErrorInfo errorInfo);

            resultCode.ThrowOnError(errorInfo);
        }
예제 #12
0
        /// <inheritdoc cref="ISapServer"/>
        public void Shutdown(uint timeout)
        {
            RfcResultCode resultCode = _interop.ShutdownServer(
                rfcHandle: _rfcServerHandle,
                timeout: timeout,
                errorInfo: out RfcErrorInfo errorInfo);

            resultCode.ThrowOnError(errorInfo);
        }
예제 #13
0
        /// <inheritdoc cref="ISapFunction"/>
        public void Invoke()
        {
            RfcResultCode resultCode = _interop.Invoke(
                rfcHandle: _rfcConnectionHandle,
                funcHandle: _functionHandle,
                out RfcErrorInfo errorInfo);

            resultCode.ThrowOnError(errorInfo);
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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));
        }
예제 #18
0
        /// <inheritdoc cref="ISapTypeMetadata"/>
        public string GetName()
        {
            RfcResultCode resultCode = _interop.GetTypeName(
                rfcHandle: _typeDescription,
                typeName: out string typeName,
                errorInfo: out RfcErrorInfo errorInfo);

            errorInfo.ThrowOnError();

            return(typeName);
        }
예제 #19
0
        public uint GetParameterCount()
        {
            RfcResultCode resultCode = _interop.GetParameterCount(
                funcDesc: _functionDescHandle,
                count: out uint count,
                errorInfo: out RfcErrorInfo errorInfo);

            errorInfo.ThrowOnError();

            return(count);
        }
예제 #20
0
        /// <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));
        }
예제 #21
0
        private int GetExceptionCount()
        {
            RfcResultCode resultCode = _interop.GetExceptionCount(
                funcDesc: _functionDescHandle,
                count: out uint count,
                errorInfo: out RfcErrorInfo errorInfo);

            errorInfo.ThrowOnError();

            return((int)count);
        }
예제 #22
0
        private int GetFieldCount()
        {
            RfcResultCode resultCode = _interop.GetFieldCount(
                typeHandle: _typeDescription,
                count: out uint count,
                errorInfo: out RfcErrorInfo errorInfo);

            errorInfo.ThrowOnError();

            return((int)count);
        }
예제 #23
0
        /// <inheritdoc cref="ISapFunctionMetadata"/>
        public string GetName()
        {
            RfcResultCode resultCode = _interop.GetFunctionName(
                rfcHandle: _functionDescHandle,
                funcName: out string funcName,
                errorInfo: out RfcErrorInfo errorInfo);

            errorInfo.ThrowOnError();

            return(funcName);
        }
예제 #24
0
        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);
        }
예제 #25
0
        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();
        }
예제 #27
0
        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));
        }
예제 #28
0
        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));
        }
예제 #29
0
        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));
        }
예제 #30
0
        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));
        }