예제 #1
0
        public bool CanConvertTo(RfcType rfcType)
        {
            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
            switch (rfcType)
            {
            case RfcType.CHAR:
            case RfcType.DATE:
            case RfcType.BCD:
            case RfcType.TIME:
            case RfcType.BYTE:
            case RfcType.NUM:
            case RfcType.FLOAT:
            case RfcType.INT:
            case RfcType.INT2:
            case RfcType.INT1:
            case RfcType.DECF16:
            case RfcType.DECF34:
            case RfcType.STRING:
            case RfcType.INT8:
                return(true);

            default:
                return(false);
            }
        }
예제 #2
0
 public RfcFieldInfo(string name, RfcType type, uint nucLength, uint ucLength, uint decimals)
 {
     Name      = name;
     Type      = type;
     NucLength = nucLength;
     UcLength  = ucLength;
     Decimals  = decimals;
 }
예제 #3
0
 public RfcParameterInfo(string name, RfcType type, RfcDirection direction, uint nucLength, uint ucLength, uint decimals, string defaultValue, string parameterText, bool optional)
     : base(name, type, nucLength, ucLength, decimals)
 {
     Direction     = direction;
     DefaultValue  = defaultValue;
     ParameterText = parameterText;
     Optional      = optional;
 }
예제 #4
0
        private static bool IsSupportedRfcType(RfcType rfcType)
        {
            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
            switch (rfcType)
            {
            case RfcType.INT8:
                return(true);

            default:
                return(false);
            }
        }
예제 #5
0
        private static bool IsSupportedRfcType(RfcType rfcType)
        {
            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
            switch (rfcType)
            {
            case RfcType.CHAR:
            case RfcType.NUM:
            case RfcType.BCD:
            case RfcType.FLOAT:
            case RfcType.DECF16:
            case RfcType.DECF34:
            case RfcType.STRING:
                return(true);

            default:
                return(false);
            }
        }
예제 #6
0
        public IEnumerable <IFromAbapValueConverter <T> > GetFromRfcConverters <T>(RfcType rfcType, Type abapValueType)
        {
            var targetType = typeof(T);
            var key        = $"{rfcType}_{targetType}";

            if (!_fromRfcConverters.ContainsKey(key))
            {
                var converters = _decoratedResolver.GetFromRfcConverters <T>(rfcType, abapValueType).ToArray();
                _fromRfcConverters.Add(key, converters.Length == 0 ? null : converters);
            }

            var entry = _fromRfcConverters[key];

            if (entry != null)
            {
                return((IEnumerable <IFromAbapValueConverter <T> >)entry);
            }
            return(new IFromAbapValueConverter <T> [0]);
        }
예제 #7
0
        public static T GetParameter <T>(this IDataParameter dataContainer, string name, int length, int decimals, RfcType rfcType)
        {
            RfcErrorInfo errorInfo;
            object       result;

            switch (rfcType)
            {
            case RfcType.Char:
            {
                var buffer = new StringBuilder(length);
                UnsafeNativeMethods.RfcGetChars(dataContainer.DataHandle(), name, buffer, buffer.Length, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = buffer;
            }
            break;

            case RfcType.Num:
            {
                var buffer = new char[length];
                UnsafeNativeMethods.RfcGetNum(dataContainer.DataHandle(), name, buffer, buffer.Length, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = new SnwNumeric(new string(buffer));
            }
            break;

            case RfcType.String:
            {
                int stringLength = 200;
                //UnsafeNativeMethods.RfcGetStringLength(dataContainer.DataHandle(), name, out stringLength, out errorInfo);
                //errorInfo.IfErrorThrowException();
                var stringBuffer = new StringBuilder(stringLength + 1);
                int retlength;
                UnsafeNativeMethods.RfcGetString(dataContainer.DataHandle(), name, stringBuffer, stringBuffer.Capacity, out retlength, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = stringBuffer.ToString();
            }
            break;

            case RfcType.Date:
            {
                var date = new char[8];
                UnsafeNativeMethods.RfcGetDate(dataContainer.DataHandle(), name, date, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = new SnwDate(new string(date));
            }
            break;

            case RfcType.Time:
            {
                var time = new char[6];
                UnsafeNativeMethods.RfcGetTime(dataContainer.DataHandle(), name, time, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = new SnwTime(new string(time));
            }
            break;

            case RfcType.Byte:
            {
                var buffer = new byte[length];
                UnsafeNativeMethods.RfcGetBytes(dataContainer.DataHandle(), name, buffer, buffer.Length, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = buffer;
            }
            break;

            case RfcType.Int:
            {
                int value;
                UnsafeNativeMethods.RfcGetInt(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.Int1:
            {
                byte value;
                UnsafeNativeMethods.RfcGetInt1(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.Int2:
            {
                short value;
                UnsafeNativeMethods.RfcGetInt2(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.Float:
            {
                double value;
                UnsafeNativeMethods.RfcGetFloat(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.DecF16:
            {
                decimal value;
                UnsafeNativeMethods.RfcGetDecF16(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.DecF34:
            {
                decimal value;
                UnsafeNativeMethods.RfcGetDecF16(dataContainer.DataHandle(), name, out value, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = value;
            }
            break;

            case RfcType.XString:
            {
                var buffer = new byte[length];
                int outLength;
                UnsafeNativeMethods.RfcGetXString(dataContainer.DataHandle(), name, buffer, buffer.Length,
                                                  out outLength, out errorInfo);
                errorInfo.IfErrorThrowException();
                result = new SnwXString(buffer);
            }
            break;

            case RfcType.Structure:
            {
                IntPtr structureHandle;
                UnsafeNativeMethods.RfcGetStructure(dataContainer.DataHandle(), name, out structureHandle, out errorInfo);
                errorInfo.IfErrorThrowException();
                var structure = new SnwStructure(structureHandle);
                result = typeof(T).GetConstructor(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null, new[] { typeof(SnwStructure) }, null).Invoke(new object[] { structure });
            }
            break;

            case RfcType.Table:
            {
                IntPtr tableHandle;
                UnsafeNativeMethods.RfcGetTable(dataContainer.DataHandle(), name, out tableHandle, out errorInfo);
                errorInfo.IfErrorThrowException();
                var table = new SnwTable <SnwStructure>(tableHandle);
                result = typeof(T).GetConstructor(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, null, new[] { typeof(SnwTable <SnwStructure>) }, null).Invoke(new object[] { table });
            }
            break;

            default:
            {
                throw new SnwConnectorException(string.Format(CultureInfo.InvariantCulture, Messages.TypeNotHandled, typeof(T)));
            }
            }
            return((T)result);
        }
예제 #8
0
 public bool CanConvertFrom(RfcType rfcType)
 {
     return(IsSupportedRfcType(rfcType));
 }