Example #1
0
        // Includes Mapping Inheritance from Jerry Shea (http://www.RenewTek.com)
        // Includes Embedded Objects from Paul Hatcher (http://www.grassoc.co.uk)
        private void AddMember(string member)
        {
            MemberInfo field = null;

            if (member == null || member.Length == 0)
            {
                throw new MappingException("Mapping: Entity member was Missing - " + this.type);
            }

            // Improved Support for Embedded Objects from Chris Schletter (http://www.thzero.com)
            string typeName = this.type;

            string[] memberParts = member.Split('.');
            for (int index = 0; index < memberParts.Length; index++)
            {
                field = FindField(typeName, memberParts[index]);
                if (field != null)
                {
                    typeName = EntityMap.GetType(field).FullName;
                }
                else
                {
                    break;
                }
            }

            if (field == null)
            {
                throw new MappingException("Mapping: Entity member was Invalid - " + member + " : " + type);
            }
            this.members.Add(member, field);
        }
Example #2
0
        // Includes Embedded Objects from Paul Hatcher (http://www.grassoc.co.uk)
        internal static MemberInfo FindField(string typeName, string member)
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
            MemberInfo   field = null;
            Type         type  = EntityMap.GetType(typeName);

            while (type != null && field == null)
            {
                // if we can't find field in type, then try all of type's ancestors
                field = type.GetField(member, flags);
                type  = type.BaseType;
            }

            // Improved Support for Embedded Objects from Chris Schletter (http://www.thzero.com)
            if (field == null)
            {
                type = EntityMap.GetType(typeName);
                while (type != null && field == null)
                {
                    // if we can't find property in type, then try all of type's ancestors
                    field = type.GetProperty(member, flags);
                    type  = type.BaseType;
                }
            }
            return(field);
        }
Example #3
0
        internal EntityMap(string type, string table, string keyMember, KeyType keyType, string sortOrder,
                           bool readOnly, bool changesOnly, bool autoTrack, string hint, string typeField, string typeValue)
        {
            if (type == null || type.Length == 0)
            {
                throw new MappingException("Mapping: Entity type was Missing");
            }
            if (table == null || table.Length == 0)
            {
                throw new MappingException("Mapping: Entity table was Missing - " + type);
            }
            if (keyType != KeyType.None && (keyMember == null || keyMember.Length == 0))
            {
                throw new MappingException("Mapping: Entity keyMember was Missing - " + type);
            }

            this.type        = type;
            this.table       = table;
            this.keyMembers  = keyMember.Replace(", ", ",").Split(',');
            this.keyType     = keyType;
            this.sortOrder   = (sortOrder == null ? String.Empty : sortOrder);
            this.readOnly    = readOnly;
            this.changesOnly = changesOnly;
            this.autoTrack   = autoTrack;
            this.hint        = hint;

            this.baseEntity = null;
            this.typeField  = typeField;
            try {
                if (typeValue == null)
                {
                    this.typeValue = null;
                }
                else
                {
                    this.typeValue = int.Parse(typeValue);
                }
            }
            catch {
                this.typeValue = typeValue.Trim('\'');
            }

            if (EntityMap.GetType(this.type) == null)
            {
                throw new MappingException("Mapping: Entity type was Invalid - " + type);
            }
            if (EntityMap.GetType(this.type).GetInterface(typeof(IObjectHelper).ToString()) != null)
            {
                this.hasHelper = true;
            }
            if (EntityMap.GetType(this.type).GetInterface(typeof(IObjectNotification).ToString()) != null)
            {
                this.hasEvents = true;
            }
        }
Example #4
0
        private void AddRelation(string member, RelationMap relation)
        {
            if (EntityMap.GetType(relation.Type) == null)
            {
                throw new MappingException("Mapping: Relation type was Invalid - " + relation.Type);
            }

            RelationMap[] tempRelations = new RelationMap[this.relations.Length + 1];
            this.relations.CopyTo(tempRelations, 0);
            tempRelations[this.relations.Length] = relation;
            this.relations = tempRelations;
            if (!relation.QueryOnly)
            {
                this.AddMember(member);
            }
        }
Example #5
0
        // Includes Mapping Inheritance by Jim Daugherty and Michael Robin
        public Commands Commands(string type)
        {
            Commands commands = this.commands[type] as Commands;

            if (commands == null)
            {
                // if no commands found then try to find one for ancestor type
                for (Type baseType = EntityMap.GetType(type).BaseType; baseType != null; baseType = baseType.BaseType)
                {
                    commands = this.commands[baseType.ToString()] as Commands;
                    if (commands != null)
                    {
                        this.commands[type] = commands;                         // if found, put into commands so we don't have to do this again
                        break;
                    }
                }
            }
            return(commands);
        }
Example #6
0
        private string GetTypeName(XmlNode node, string name, string defaultNamespace)
        {
            string typeName = this.GetValue(node, name);

            if (typeName.IndexOf(',') > 0)
            {
                string[] typeParts = typeName.Split(new char[] { ',' }, 2);
                typeName = FullTypeName(typeParts[0], defaultNamespace);
                if (typeParts.Length > 1)
                {
                    EntityMap.GetType(typeName, typeParts[1]);
                }
                return(typeName);
            }
            else
            {
                return(FullTypeName(typeName, defaultNamespace));
            }
        }
Example #7
0
 // Includes Mapping Inheritance from Jerry Shea (http://www.RenewTek.com)
 public EntityMap this[string type] {
     get {
         EntityMap entity = this.entities[type] as EntityMap;
         if (entity == null)
         {
             // if no entity map found then try to find one for ancestor type
             for (Type baseType = EntityMap.GetType(type).BaseType; baseType != null; baseType = baseType.BaseType)
             {
                 entity = this.entities[baseType.ToString()] as EntityMap;
                 if (entity != null)
                 {
                     this.entities[type] = entity;                             // if found, put into entity map so we don't have to do this again
                     break;
                 }
             }
         }
         return(entity);
     }
 }
Example #8
0
        // Includes Null-Value Assistance from Tim Byng (http://www.missioninc.com)
        internal void AddField(string member, string field, string nullValue, string alias,
                               string parameter, PersistType persistType, CustomProvider provider)
        {
            this.AddMember(member);
            FieldMap[] tempFields = new FieldMap[this.fields.Length + 1];
            this.fields.CopyTo(tempFields, 0);
            tempFields[this.fields.Length] = new FieldMap(member, field, nullValue,
                                                          parameter, persistType, EntityMap.GetType(this.Member(member)), provider);
            int keyIndex = -1;

            for (int index = 0; index < this.keyMembers.Length; index++)
            {
                if (this.keyMembers[index].Equals(member))
                {
                    keyIndex = index;
                }
            }
            if (keyIndex > -1)
            {
                FieldMap[] tempKeyFields = new FieldMap[this.keyFields.Length + 1];
                this.keyFields.CopyTo(tempKeyFields, 0);
                tempKeyFields[this.keyFields.Length] = tempFields[this.fields.Length];
                this.keyFields = tempKeyFields;
            }
            if (persistType == PersistType.ReadOnly)
            {
                this.readOnlyCount++;
            }
            if (persistType == PersistType.Concurrent)
            {
                this.concurrentCount++;
            }
            this.fields = tempFields;
            this.helper.Add(alias, this.fields.Length - 1);

            if (this.baseEntity != null && !this.baseEntity.subFields.ContainsKey(field))
            {
                this.baseEntity.subFields.Add(field, this.fields[this.fields.Length - 1]);
            }
        }
Example #9
0
        internal void AddLookup(string member, string field, string nullValue, string alias,
                                string parameter, string table, string source, string dest, CustomProvider provider)
        {
            this.AddMember(member);
            FieldMap[] tempFields = new FieldMap[this.fields.Length + 1];
            this.fields.CopyTo(tempFields, 0);
            tempFields[this.fields.Length] = new LookupMap(member, field, nullValue,
                                                           parameter, table, source, dest, EntityMap.GetType(this.Member(member)), provider);
            this.readOnlyCount++;
            this.fields = tempFields;
            this.helper.Add(alias, this.fields.Length - 1);

            if (this.baseEntity != null && !this.baseEntity.subFields.ContainsKey(field))
            {
                this.baseEntity.subFields.Add(field, this.fields[this.fields.Length - 1]);
            }
        }
Example #10
0
        internal EntityMap(string type, EntityMap baseEntity, string typeValue)
        {
            if (type == null || type.Length == 0)
            {
                throw new MappingException("Mapping: SubEntity type was Missing");
            }
            if (baseEntity == null)
            {
                throw new MappingException("Mapping: SubEntity inherits was undefined Entity - " + type);
            }
            if (baseEntity.TypeField == null || baseEntity.TypeField.Length == 0)
            {
                throw new MappingException("Mapping: SubEntity entity had undefined typeField - " + type);
            }
            if (typeValue == null || typeValue.Length == 0)
            {
                throw new MappingException("Mapping: SubEntity typeValue was not defined - " + type);
            }

            this.type        = type;
            this.table       = baseEntity.table;
            this.keyMembers  = baseEntity.keyMembers.Clone() as string[];
            this.keyType     = baseEntity.keyType;
            this.sortOrder   = baseEntity.sortOrder;
            this.readOnly    = baseEntity.readOnly;
            this.changesOnly = baseEntity.changesOnly;
            this.autoTrack   = baseEntity.autoTrack;
            this.hint        = baseEntity.hint;

            this.baseEntity = baseEntity;
            this.typeField  = baseEntity.typeField;
            try {
                if (typeValue == null)
                {
                    this.typeValue = null;
                }
                else
                {
                    this.typeValue = int.Parse(typeValue);
                }
            }
            catch {
                this.typeValue = typeValue.Trim('\'');
            }
            baseEntity.AddSubType(this.typeValue.ToString(), type);

            this.insertSP        = baseEntity.insertSP;
            this.updateSP        = baseEntity.updateSP;
            this.deleteSP        = baseEntity.deleteSP;
            this.readOnlyCount   = baseEntity.readOnlyCount;
            this.concurrentCount = baseEntity.concurrentCount;

            this.fields    = baseEntity.fields.Clone() as FieldMap[];
            this.keyFields = baseEntity.keyFields.Clone() as FieldMap[];
            this.relations = baseEntity.relations.Clone() as RelationMap[];
            this.members   = baseEntity.members.Clone() as Hashtable;
            this.helper    = baseEntity.helper.Clone() as Hashtable;

            if (EntityMap.GetType(this.type) == null)
            {
                throw new MappingException("Mapping: Entity type was Invalid - " + type);
            }
            if (EntityMap.GetType(this.type).GetInterface(typeof(IObjectHelper).ToString()) != null)
            {
                this.hasHelper = true;
            }
            if (EntityMap.GetType(this.type).GetInterface(typeof(IObjectNotification).ToString()) != null)
            {
                this.hasEvents = true;
            }
        }