Converters does not accept decimal values.

Feb 24, 2015 at 3:55 PM
Edited Feb 24, 2015 at 3:55 PM
The Methods in MiosService.cs does not accept decimal values.

I propose this change:

        protected SByte FromLuupSByte(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if ((dRetValue >= SByte.MinValue) & (dRetValue <= SByte.MaxValue))
                    return Convert.ToSByte(dRetValue);

            }

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(SByte);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to SByte!", luupValue));
        }


        protected Byte FromLuupByte(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if ((dRetValue >= Byte.MinValue) & (dRetValue <= Byte.MaxValue))
                    return Convert.ToByte(dRetValue);

            }

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(Byte);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to Byte!", luupValue));
        }

        protected Int16 FromLuupInt16(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if ((dRetValue >= Int16.MinValue) & (dRetValue <= Int16.MaxValue))
                    return Convert.ToInt16(dRetValue);

            }

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(Int16);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to Int16!", luupValue));
        }
        
        protected UInt16 FromLuupUInt16(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if ((dRetValue >= UInt16.MinValue) & (dRetValue <= UInt16.MaxValue))
                    return Convert.ToUInt16(dRetValue);

            }

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(UInt16);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to UInt16!", luupValue));
        }
        
        protected Int32 FromLuupInt32(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if ((dRetValue >= Int32.MinValue) & (dRetValue <= Int32.MaxValue))
                    return Convert.ToInt32(dRetValue);

            }

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(Int32);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to Int32!", luupValue));
        }
        
        protected UInt32 FromLuupUInt32(String luupValue)
        {
            Double dRetValue;
            if (Double.TryParse(luupValue, out dRetValue))
            {
                if  ((dRetValue >= UInt32.MinValue) & (dRetValue <= UInt32.MaxValue))
                    return Convert.ToUInt32(dRetValue);
                
            }
           // if (UInt32.TryParse(dRetValue, out retValue))
           //     return retValue;

            if (String.IsNullOrEmpty(luupValue))
                // WARNING: We will ignore this case and return default<T> for now.
                return default(UInt32);

            throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to UInt32!", luupValue));
        }
Makes sense?

Regards,
Jasper
Mar 22, 2015 at 2:17 AM
Hi Jasper,

Could you share the service file that defines double StateVariable or Action parameter?

If we need this functionality, shouldn't we just add a method like this?
    protected Double FromLuupDouble(String luupValue)
    {
        Double retValue;
        if (Double.TryParse(luupValue, out retValue))
            return retValue;

        if (String.IsNullOrEmpty(luupValue))
            // WARNING: We will ignore this case and return default<T> for now.
            return default(Double);

        throw new MiosFormatException(String.Format("Could not parse returned value [{0}] to Double!", luupValue));
    }
Thanks,

Ercan