コード例 #1
0
ファイル: coreDatatypes.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="typeId"></param>
 protected DataType(otDataType typeId, bool isNullable = false, object defaultvalue = null, string name = null, Rulez.Engine engine = null)
 {
     _type         = isNullable ? typeId | otDataType.IsNullable : typeId;
     _name         = (String.IsNullOrWhiteSpace(name)) ? this.Signature : name.ToUpper() + (isNullable ? "?" : String.Empty);
     _engine       = engine;
     _defaultvalue = defaultvalue;
 }
コード例 #2
0
ファイル: coreDatatypes.cs プロジェクト: boschn/otRulez
        /// <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" });
            }
        }
コード例 #3
0
ファイル: coreDatatypes.cs プロジェクト: boschn/otRulez
        /// <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" });
            }
        }
コード例 #4
0
ファイル: coreDatatypes.cs プロジェクト: boschn/otRulez
        /// <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" });
            }
        }
コード例 #5
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #6
0
ファイル: rulezXPTree.cs プロジェクト: boschn/otRulez
        /// <summary>
        /// constructor
        /// </summary>
        public Literal(object value = null, otDataType? typeId = null)
            : base()
        {
            this.NodeType = otXPTNodeType.Literal;
            if (typeId != null && typeId.HasValue ) _datatype = Core.DataType.GetDataType(typeId.Value);
            if (value != null) this.Value = value;

            if ((typeId == null) && (value != null))
            {
                throw new NotImplementedException("data type determination by value");
            }
        }
コード例 #7
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #8
0
ファイル: rulezXPTree.cs プロジェクト: boschn/otRulez
        /// <summary>
        /// Adds a Parameter to the Selection Rule
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="typeId"></param>
        /// <returns></returns>
        public ISymbol AddNewVariable(string id, otDataType typeId)
        {
            if (_variables.ContainsKey(id))
            {
                throw new RulezException(RulezException.Types.IdExists, arguments: new object[] { id, this.ID });
            }
            Variable aVar = new Variable(id: id, typeID: typeId, scope: this);
            _variables.Add(aVar.ID, aVar);

            return aVar;
        }
コード例 #9
0
ファイル: rulezXPTree.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="handle"></param>
 /// <param name="typeID"></param>
 /// <param name="scope"></param>
 public Variable(string id, otDataType typeID, IXPTree scope)
     : base(engine: null)
 {
     _id = id;
     _datatype = Core.DataType.GetDataType (typeID);
     _scope = scope;
     this.NodeType = otXPTNodeType.Variable;
 }
コード例 #10
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <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
 }
コード例 #11
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #12
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <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];
 }
コード例 #13
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// returns a stored or new ListType object from otDataType
 /// </summary>
 /// <param name="innerTypeId"></param>
 /// <param name="engine"></param>
 /// <param name="name"></param>
 /// <param name="isNullable"></param>
 /// <returns></returns>
 public static ListType GetDataType(Engine engine, otDataType innerTypeId = otDataType.Text, string name = null, bool isNullable = false)
 {
     IDataType innerDataType = PrimitiveType.GetPrimitiveType(innerTypeId);
     string sig = CreateSignature(innerDataType, isNullable);
     if (!String.IsNullOrEmpty(name) && engine.Repository.HasDataType(name))
     {
         IDataType aDatatype = engine.Repository.GetDatatype(name);
         if (aDatatype.TypeId == otDataType.List) return (ListType)aDatatype;
         throw new RulezException(RulezException.Types.IdExists, arguments: new object[] { name, aDatatype.Name });
     }
     if (engine.Repository.HasDataTypeSignature(sig)) return (ListType)engine.Repository.GetDatatypeBySignature(sig).FirstOrDefault();
     // create new one
     return new ListType(innerDataType: innerDataType, isNullable: isNullable, name: name, engine: engine);
 }
コード例 #14
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #15
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <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" });
     }
 }
コード例 #16
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });
            }
        }
コード例 #17
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// constructor
 /// </summary
 public DataStructureType(otDataType typeId, string name = null, bool isNullable = false, Engine engine = null, object defaultvalue = null)
     : base(typeId: typeId, isNullable: isNullable, defaultvalue: defaultvalue, name: name, engine: engine)
 {
 }
コード例 #18
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #19
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// constructor
 /// </summary
 public SymbolType( otDataType innerTypeId = otDataType.Number, Boolean isNullable= false, Engine engine = null, string name = null)
     : base(typeId: otDataType.Symbol, isNullable: isNullable, defaultvalue: null, engine: engine, name: name)
 {
     this.ComplexTypeName = ConstTypeName;
     // anonymous name
     if (String.IsNullOrEmpty(name)) this.Name = Guid.NewGuid().ToString();
     // define the structure
     AddMember(ConstSYMBOL, DataType.GetDataType(otDataType.Text));
     AddMember(ConstValue, DataType.GetDataType(innerTypeId));
     _signature = CreateSignature(_structure.Values, isNullable: isNullable, typename: ConstTypeName, name: name);
     // raise event
     RaiseOnCreation(this, datatype: this, engine: engine);
 }
コード例 #20
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }
コード例 #21
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
 /// <summary>
 /// constructor
 /// </summary
 public CompositeType(string name, otDataType typeId, Boolean isNullable, Engine engine = null, object defaultvalue = null)
     : base(typeId, isNullable:isNullable, defaultvalue: null, engine: engine, name: name)
 {
 }
コード例 #22
0
ファイル: rulezDataTypes.cs プロジェクト: boschn/otRulez
        /// <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" });

            }
        }