예제 #1
0
        /// <summary>
        /// return the category for a otDataType ID
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static otDataTypeCategory GetCategory(otDataType typeId)
        {
            // extract nullable
            if ((typeId & otDataType.IsNullable) == otDataType.IsNullable)
            {
                typeId ^= otDataType.IsNullable;
            }

            switch (typeId)
            {
            // primitives
            case otDataType.Bool:
            case otDataType.Binary:
            case otDataType.Date:
            case otDataType.Decimal:
            case otDataType.Memo:
            case otDataType.Number:
            case otDataType.Null:
            case otDataType.Text:
            case otDataType.Timespan:
            case otDataType.Timestamp:
                return(otDataTypeCategory.Primitive);

            // complex
            case otDataType.DecimalUnit:
            case otDataType.LanguageText:
            case otDataType.Symbol:
                return(otDataTypeCategory.Composite);

            // data structure
            case otDataType.DataObject:
            case otDataType.List:
                return(otDataTypeCategory.DataStructure);

            // not found
            default:
                throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "DataType.GetCategory" });
            }
        }
예제 #2
0
        /// <summary>
        /// returns a default value for the OnTrack Datatypes
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static object GetDefaultValue(otDataType typeId)
        {
            switch (GetCategory(typeId))
            {
            case otDataTypeCategory.Primitive:
                return(Rulez.PrimitiveType.GetDefaultValue(typeId));

            case otDataTypeCategory.Composite:
                return(Rulez.CompositeType.GetDefaultValue(typeId));

            case otDataTypeCategory.DataStructure:
                return(Rulez.DataStructureType.GetDefaultValue(typeId));

            default:
                throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByClass, arguments: new object[] { typeId.ToString(), "DataType.GetDefaultValue" });
            }
        }
예제 #3
0
        /// <summary>
        /// converts a value to an representing value of the outvalue
        /// </summary>
        /// <param name="value"></param>
        /// <param name="outvalue"></param>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static object To(object value, otDataType typeId)
        {
            switch (GetCategory(typeId))
            {
            case otDataTypeCategory.Primitive:
                return(Rulez.PrimitiveType.To(value, typeId));

            default:
                throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByClass, arguments: new object[] { typeId.ToString(), "DataType.To" });
            }
        }
예제 #4
0
 /// <summary>
 /// constructor
 /// </summary
 private PrimitiveType(otDataType typeId, bool isNullable = false)
     : base(typeId,  isNullable,  defaultvalue:GetDefaultValue(typeId), name: null, engine:null)
 {
     // check on type
     if ((uint) typeId > PrimitiveTypeMaxRange)
         throw new RulezException(RulezException.Types.DataTypeNotImplementedByClass,arguments: new object[]  {typeId.ToString (), "ValueType"});
     // no event for Primitives
 }
예제 #5
0
        /// <summary>
        /// returns a default value for the OnTrack Datatypes
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new object GetDefaultValue(otDataType typeId)
        {
            // if nullable than return the null
            if ((typeId & otDataType.IsNullable ) == otDataType.IsNullable) return null;

            // make a case
            switch (typeId)
            {
                 case otDataType.Null:
                    return null;
                case otDataType.Bool:
                    return false;
                case otDataType.Date:
                    return DateTime.Parse(ConstNullTimestampString).Date;
                /*case otDataType.List:
                    /// To do implement inner Type or accept Object()
                    List<string> aValue = new List<string>();
                    return aValue.ToArray();*/
                case otDataType.Number:
                    return (long)0;
                case otDataType.Memo:
                    return string.Empty;
                case otDataType.Decimal:
                    return (double)0;
                case otDataType.Text:
                    return string.Empty;
                case otDataType.Timespan:
                    return new TimeSpan();
                case otDataType.Timestamp:
                    return DateTime.Parse(DataType.ConstNullTimestampString);
                case otDataType.Binary:
                    return new byte[]{0x00};

                default:
                    if ((uint)typeId < PrimitiveTypeMaxRange)
                        throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.DataType.GetTypeFor" });
                    else throw new RulezException(RulezException.Types.DataTypeNotImplementedByClass, arguments: new object[] { typeId.ToString(), "PrimitiveType" });

            }
        }
예제 #6
0
        /// <summary>
        /// Get native datatype
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new System.Type GetNativeType(otDataType typeId)
        {
            switch (typeId)
            {
                case otDataType.List:
                    return typeof(List<>);
                case otDataType.DataObject:
                    return typeof(iDataObject);
                default:
                    if (typeId != otDataType.List)
                        throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase,
                            arguments: new object[] { typeId.ToString(), "Rulez.StructuredType.GetTypeFor" });
                    else throw new RulezException(RulezException.Types.DataTypeNotImplementedByClass,
                        arguments: new object[] { typeId.ToString(), "Structured" });

            }
        }
예제 #7
0
        /// <summary>
        /// returns a complex type of typeId if possible to make one
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static IDataType GetStructuredType(otDataType typeId)
        {
            // strip off
            if ((typeId & otDataType.IsNullable) == otDataType.IsNullable) typeId ^= otDataType.IsNullable ;
            switch (typeId)
            {
                case otDataType.List:
                    return ListType.GetDataType (engine: Rules.Engine);
                case otDataType.DataObject:
                    // not implementable
                default:
                    throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.StructuredType.GetStructuredType" });

            }
        }
예제 #8
0
        /// <summary>
        /// returns the best fit System.Type for a OnTrack Datatype
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new System.Type GetNativeType(otDataType typeId)
        {
            // strip off
            if ((typeId & otDataType.IsNullable) == otDataType.IsNullable) typeId ^= otDataType.IsNullable;

            switch (typeId)
            {
                case otDataType.Symbol:
                    return typeof(string);
                case otDataType.DecimalUnit:
                    return typeof(DecimalUnitType.DecimalUnit);
                case otDataType.LanguageText:
                    return typeof(LanguageTextType.LanguageText);
                case otDataType.Tuple:
                    return typeof(TupleType.Tuple);
                default:
                    throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.DataType.GetNativeType" });

            }
        }
예제 #9
0
        /// <summary>
        /// returns a default value for the OnTrack Datatypes
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new object GetDefaultValue(otDataType typeId)
        {
            // if nullable than return the null
            if ((typeId & otDataType.IsNullable) == otDataType.IsNullable) return null;

            switch (typeId)
            {
                case otDataType.List:
                    return new List<string>();
                case otDataType.DataObject:
                    // return String.Empty;
                default:
                    throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.StructuredType.GetDefaultValue" });
            }
        }
예제 #10
0
        /// <summary>
        /// returns a default value for the OnTrack Datatypes
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new object GetDefaultValue(otDataType typeId)
        {
            // if nullable than return the null
            if ((typeId & otDataType.IsNullable) == otDataType.IsNullable) return null;

            switch (typeId)
            {
             case otDataType.Symbol:
                    return String.Empty;
             case otDataType.DecimalUnit:
                    return new DecimalUnitType.DecimalUnit ();
             case otDataType.LanguageText:
                    return new LanguageTextType.LanguageText();
                case otDataType.Tuple:
                    return new TupleType.Tuple();
             default:
                    throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.DataType.GetDefaultValue" });

            }
        }
예제 #11
0
 /// <summary>
 /// converts a value to an representing value of the outvalue
 /// </summary>
 /// <param name="value"></param>
 /// <param name="outvalue"></param>
 /// <param name="typeId"></param>
 /// <returns></returns>
 public static new object To(object value, otDataType typeId)
 {
     switch (typeId)
     {
         case otDataType.Null:
             return null;
         case otDataType.Bool:
             return ToBool(value);
         case otDataType.Date:
             return ToDate(value);
         case otDataType.List:
             return ToList(value);
         case otDataType.Number:
             return ToNumber(value);
         case otDataType.Memo:
             return ToMemo(value);
         case otDataType.Decimal:
             return ToDecimal(value);
         case otDataType.Text:
             return ToText(value);
         case otDataType.Timespan:
             return ToTimespan(value);
         case otDataType.Timestamp:
             return ToTimeStamp(value);
         case otDataType.Binary:
             return ToBinary(value);
         default:
             throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "PrimitiveType.To" });
     }
 }
예제 #12
0
        /// <summary>
        /// returns a composite type of typeId if possible to make one
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new IDataType GetCompositeType(otDataType typeId)
        {
            switch (typeId)
            {
                case otDataType.Symbol:
                    return SymbolType.GetDataType(engine: Rules.Engine);
                case otDataType.DecimalUnit:
                    // return DecimalUnitType.GetDataType(unit: unit,engine: Rules.Engine);
                case otDataType.LanguageText:
                // return LanguageTextType.GetDataType (cultural: cultural, engine: Rules.Engine);
                case otDataType.Tuple:
                    // not possible without a name
                default:
                   throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.CompositeType.GetCompositeType" });

            }
        }
예제 #13
0
 /// <summary>
 /// get the Value Type Data Type object
 /// </summary>
 /// <param name="typeId"></param>
 /// <param name="isNullable"></param>
 /// <returns></returns>
 public static PrimitiveType GetPrimitiveType(otDataType typeId, bool isNullable = false)
 {
     typeId = isNullable ? typeId | otDataType.IsNullable : typeId;
        // check if in store
        if (!_primitives .ContainsKey ((uint)typeId))
         throw new RulezException(RulezException.Types.DataTypeNotImplementedByClass, arguments: new object[] { typeId.ToString(), "ValueType" });
        // return
        return _primitives[(uint)typeId];
 }
예제 #14
0
        /// <summary>
        /// returns the best fit System.Type for a OnTrack Datatype
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public static new System.Type GetNativeType(otDataType typeId)
        {
            switch (typeId)
            {
                case otDataType.@Null:
                    return typeof(void);
                case otDataType.Date:
                    return typeof(DateTime);
                case otDataType.Bool:
                    return typeof(bool);
                case otDataType.Number:
                    return typeof(long);
                case otDataType.Memo:
                    return typeof(string);
                case otDataType.Text:
                    return typeof(string);
                case otDataType.Timespan:
                    return typeof(TimeSpan);
                case otDataType.Decimal:
                    return typeof(double);
                case otDataType.Timestamp:
                    return typeof(DateTime);
                case otDataType.Binary:
                    return typeof(byte[]);
                default:
                    if ((uint)typeId < PrimitiveTypeMaxRange)
                        throw new Rulez.RulezException(Rulez.RulezException.Types.DataTypeNotImplementedByCase, arguments: new object[] { typeId.ToString(), "Core.DataType.GetTypeFor" });
                    else throw new RulezException(RulezException.Types.DataTypeNotImplementedByClass, arguments: new object[] { typeId.ToString(), "ValueType" });

            }
        }