/// <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); }
/// <summary> /// returns or creates an anonymous type from the engine /// </summary> public static LanguageTextType GetDataType(SymbolType cultural, Engine engine, string name = null, bool isNullable = false) { string sig = CreateSignature(structure: new IDataType[] { PrimitiveType.GetPrimitiveType(otDataType.Text), cultural }, isNullable: isNullable); if (!String.IsNullOrEmpty(name) && engine.Repository.HasDataType(name)) { IDataType aDatatype = engine.Repository.GetDatatype(name); if (aDatatype.TypeId == otDataType.LanguageText) return (LanguageTextType) aDatatype; throw new RulezException(RulezException.Types.IdExists, arguments: new object[] { name, aDatatype.Name }); } if (engine.Repository.HasDataTypeSignature(sig)) return (LanguageTextType)engine.Repository.GetDatatypeBySignature(sig).FirstOrDefault(); // create new one return new LanguageTextType(cultural: cultural, isNullable: isNullable, name:name, engine: engine); }
/// <summary> /// constructor /// </summary public ListType(IDataType innerDataType, string name = null, bool isNullable = false, Engine engine = null) : base(typeId: otDataType.List, isNullable: isNullable, name: name, engine: engine, defaultvalue: null) { // check on type this.StructureTypeName = ConstTypeName; this.InnerDataType = innerDataType; this.DefaultValue = GetDefaultValue(otDataType.List); this.Signature = StructureTypeName + (IsNullable ? "?" : "") + "<" + innerDataType.Signature + ">"; // raise event ! RaiseOnCreation(this, datatype: this, engine: engine); }
/// <summary> /// constructor /// </summary public DecimalUnitType(SymbolType unit, string name = null, Boolean isNullable= false, Engine engine = null) : base(typeId: otDataType.DecimalUnit, isNullable:isNullable, defaultvalue: null, engine: engine, name: name) { // anonymous name if (String.IsNullOrEmpty(name)) this.Name = Guid.NewGuid().ToString(); this.ComplexTypeName = ConstTypeName; ; AddMember(ConstValue, PrimitiveType.GetPrimitiveType(otDataType.Decimal)); AddMember(ConstUnit, unit); _signature = CreateSignature(_structure.Values, isNullable: isNullable, typename: ConstTypeName, name: name); // raise event RaiseOnCreation(this, datatype: this, engine: engine); }
/// <summary> /// constructor /// </summary public LanguageTextType(SymbolType cultural, string name = null,Boolean isNullable=false, Engine engine = null) : base(typeId: otDataType.LanguageText, isNullable: isNullable, defaultvalue: null, engine: engine, name: name) { this.ComplexTypeName = ConstTypeName; AddMember(ConstText, PrimitiveType.GetPrimitiveType(otDataType.Text)); AddMember(ConstCultural, cultural); _signature = CreateSignature(_structure.Values, isNullable: isNullable, typename: ConstTypeName, name: name); // raise event RaiseOnCreation(this, datatype: this, engine: engine); }
/// <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) { }
/// <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) { }
/// <summary> /// constructor /// </summary public DataObjectType(string name, Engine engine=null) : base(otDataType.DataObject, isNullable:true, defaultvalue: null, engine: engine, name: name) { //_signature = CreateSignature(_structure.Values, isNullable: isNullable, typename: ConstTypeName, name: name); // raise event ! RaiseOnCreation(this, datatype: this, engine: engine); }
/// <summary> /// returns or creates an anonymous type from the engine /// </summary> public static DataObjectType GetDataType(string name, Engine engine) { if (engine.Repository.HasDataType(name)) { IDataType aDatatype = engine.Repository.GetDatatype(name); if (aDatatype.TypeId == otDataType.DataObject || aDatatype.TypeId == (otDataType.IsNullable | otDataType.DataObject)) return (DataObjectType)aDatatype; // not found as dataobject throw new RulezException(RulezException.Types.IdExists, arguments: new object[] { name, "not a data object type" }); } // create new one return new DataObjectType(name, engine: engine); }
/// <summary> /// returns or creates a type from the engine /// </summary> public static new TupleType GetDataType(IDataType[] structure, Engine engine, string[] memberNames = null, string name = null, bool isNullable = false) { string sig = CreateSignature(structure: structure, typename: ConstTypeName, isNullable: isNullable); if (!String.IsNullOrEmpty(name) && engine.Repository.HasDataType(name)) { IDataType aDatatype = engine.Repository.GetDatatype(name); if (aDatatype.TypeId == otDataType.Tuple) return (TupleType)aDatatype; throw new RulezException(RulezException.Types.IdExists, arguments: new object[] { name, aDatatype.Name }); } if (engine.Repository.HasDataTypeSignature(sig)) return (TupleType)engine.Repository.GetDatatypeBySignature(sig).FirstOrDefault(); // create new one return new TupleType(structure: structure, isNullable: isNullable, memberNames: memberNames, name: name, engine: engine); }
/// <summary> /// constructor /// </summary public TupleType(IDataType[] structure, string[] memberNames = null, string name = null, Boolean isNullable = false, Engine engine = null) : base(typeId: otDataType.Tuple, isNullable: isNullable, defaultvalue: null, engine: engine, name: name) { // anonymous name if (String.IsNullOrEmpty(name)) this.Name = Guid.NewGuid().ToString(); this.ComplexTypeName = ConstTypeName; uint i = 0; foreach (IDataType aType in structure) { string id; if (memberNames != null && i <= memberNames.GetUpperBound(0)) id = memberNames[i]; else id = i.ToString(); AddMember(id, aType); i++; } _signature = CreateSignature(structure: structure, isNullable: isNullable, typename: ConstTypeName, name: name); // raise event RaiseOnCreation(this, datatype: this, engine: engine); }
/// <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); }
/// <summary> /// constructor /// </summary> /// <param name="engine"></param> public Context(Engine engine = null) { if (engine != null) _engine = engine; else _engine = Rules.Engine; }
private eXPressionTree.XPTree _xptree; // the output tree #endregion Fields #region Constructors /// <summary> /// constructor /// </summary> /// <param name="parser"></param> public XPTGenerator(RulezParser parser, Engine engine = null) { _parser = parser; if (engine == null) _engine = parser.Engine; else { _engine = engine; } }