Example #1
0
        public override bool FillFromAttribute(Attributes.BaseAttribute attr)
        {
            if (base.FillFromAttribute(attr))
            {
                return(true);
            }

            //Check campi automatici
            if (attr is BaseAutomaticAttribute)
            {
                if (this.IsAutomatic)
                {
                    throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_NoMultipleAutomatic);
                }

                this.IsAutomatic = true;
                this.Schema.AutoProperties.Add(this);
                this.IsReadonly = true;

                //AUTOINCREMENT
                if (attr is AutoIncrement)
                {
                    this.Schema.AutoIncPk = true;
                    this.ExcludeInsert    = true;
                    this.ExcludeUpdate    = true;

                    //Deve essere numerico e almeno Int32
                    if (!TypeHelper.IsIntegerType(this.Type) || TypeHelper.IntegerSize(this.Type) < 4)
                    {
                        throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_AutoInc_32_Bit);
                    }
                }
                //AUTO INSERT TIMESTAMP
                else if (attr is AutoInsertTimestamp)
                {
                    this.ExcludeUpdate = true;
                }
                //AUTO UPDATE TIMESTAMP
                else if (attr is AutoUpdateTimestamp)
                {
                    //nulla
                }
            }
            //DEFAULT VALUE
            else if (attr is Attributes.DefaultValue)
            {
                this.mDefaultValue = ((Attributes.DefaultValue)attr).ConvertTo(this.Type);
            }
            //CARICA SUL PRIMO ACCESSO
            else if (attr is LoadOnAccess)
            {
                this.LoadOnAccess = true;
            }
            //MODIFICATORI
            else if (attr is BaseModifierAttribute)
            {
                BaseModifierAttribute bm = (BaseModifierAttribute)attr;

                if (bm.CanApplyToProperty(this))
                {
                    if (!this.HasModifiers)
                    {
                        this.AttrModifiers = new List <BaseModifierAttribute>();
                    }

                    this.AttrModifiers.Add(bm);
                }
            }
            //VALIDATORI
            else if (attr is BaseValidatorAttribute)
            {
                BaseValidatorAttribute bv = (BaseValidatorAttribute)attr;

                if (bv.CanApplyToProperty(this))
                {
                    if (!this.HasValidators)
                    {
                        this.AttrValidators = new List <BaseValidatorAttribute>();
                    }

                    this.AttrValidators.Add(bv);
                }
            }
            //Proprieta' criptata su DB
            else if (attr is Encrypted)
            {
                if (!Utils.TypeHelper.IsString(this.Type))
                {
                    throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_Encryped_Only_String);
                }

                this.mEncAttr = (Encrypted)attr;
            }
            //XmlFormatString
            else if (attr is XmlFormatString)
            {
                this.XmlFormatString = ((XmlFormatString)attr).Format;
            }
            else
            {
                throw new NotImplementedException();
            }

            return(true);
        }
Example #2
0
        public override bool FillFromAttribute(Attributes.BaseAttribute attr)
        {
            if (base.FillFromAttribute(attr))
            {
                return(true);
            }

            //Property Map
            if (attr is PropertyMap)
            {
                //Aggiunge il mapping
                try
                {
                    PropertyMap oAttrMap = (PropertyMap)attr;

                    //Se non ci sono nomi errore
                    if (oAttrMap.Names == null || oAttrMap.Names.Length == 0)
                    {
                        throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_PropertyMapMissingNames);
                    }

                    //Viene modificato il tipo di proprieta'
                    this.IsMapped      = true;
                    this.ExcludeInsert = true;
                    this.ExcludeUpdate = true;

                    //Se non ha map lo crea
                    if (!this.HasPropertyMaps)
                    {
                        this.PropertyMap = new PropertyList(2);
                    }

                    //Aggiunge a che mappa il riferimento della mappata
                    foreach (var s in oAttrMap.Names)
                    {
                        Property oPropToMap = this.Schema.Properties.GetPropertyByName(s);

                        //Se non esiste map lo crea
                        if (!oPropToMap.HasPropertyMaps)
                        {
                            oPropToMap.PropertyMap = new PropertyList(1);
                        }

                        //Check
                        if (!(oPropToMap is PropertySimple))
                        {
                            throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_PropertyMapToSimple);
                        }

                        //Aggiunge alla corrente il riferimento alla mappata
                        this.PropertyMap.Add(oPropToMap);

                        //Aggiunge alla puntata il riferimento di chi la punta
                        oPropToMap.PropertyMap.Add(this);
                    }
                }
                catch (Bdo.Objects.ObjectException ex)
                {
                    throw new SchemaReaderException(this, Resources.SchemaMessages.Prop_PropertyMapMustBeFirst, ex.Message);
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(true);
        }