Ejemplo n.º 1
0
        private void Initialize()
        {
            //Initialize lists of factory maps, record maps and record attributes for all plugin assemblies
            foreach (IPlugin plugin in repository.Plugins.Values)
            {
                if (plugin.Enabled)
                {
                    Assembly assembly = plugin.Assembly;
                    foreach (Type type in assembly.GetTypes())
                    {
                        FactoryMap factoryMap = GetFactoryMap(type);
                        if (factoryMap != null)
                        {
                            if (factoryMap.Attribute.IsProxy)
                            {
                                proxyFactoryMaps.Add(factoryMap.Attribute.ProxyType, factoryMap);
                            }
                            else
                            {
                                factoryMaps.Add(factoryMap.Attribute.Id, factoryMap);
                            }
                        }

                        if (type.GetInterface("IRecord") != null)
                        {
                            RecordAttribute recordAttribute = GetRecordAttribute(type);
                            if (recordAttribute != null)
                            {
                                recordAttributes.Add(type, recordAttribute);

                                RecordMap recordMap = GetRecordMap(type, recordAttribute);
                                if (recordMap != null)
                                {
                                    if (recordMap.RecordTypeAttribute.IsProxy)
                                    {
                                        proxyRecordMaps.Add(recordMap.RecordTypeAttribute.ProxyType, recordMap);
                                    }
                                    else
                                    {
                                        recordMaps.Add(recordMap.RecordTypeAttribute.Id, recordMap);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Go back and load the factory maps into their associated record maps
            //This must be done in a second pass because factory methods can be anywhere
            foreach (string mapId in factoryMaps.Keys)
            {
                recordMaps[mapId].FactoryMap = factoryMaps[mapId];
            }
            foreach (Type mapId in proxyFactoryMaps.Keys)
            {
                proxyRecordMaps[mapId].FactoryMap = proxyFactoryMaps[mapId];
            }
        }
Ejemplo n.º 2
0
        private RecordMap GetRecordMap(Type type, RecordAttribute recordAttribute)
        {
            RecordMap           recordMap           = null;
            RecordTypeAttribute recordTypeAttribute = GetRecordTypeAttribute(type);

            if (recordTypeAttribute != null)
            {
                IDictionary <int, FieldMap> basicFieldMaps    = new Dictionary <int, FieldMap>();
                IList <FieldMap>            advancedFieldMaps = new List <FieldMap>();
                IList <IndexMap>            indexMaps         = new List <IndexMap>();
                IList <LinkRecord>          linkRecords       = new List <LinkRecord>();

                foreach (PropertyInfo property in type.GetProperties())
                {
                    foreach (Attribute attribute in property.GetCustomAttributes(typeof(FieldAttribute), true))
                    {
                        FieldAttribute fieldAttribute = (FieldAttribute)attribute;
                        FieldMap       fieldMap       = new FieldMap(fieldAttribute, property);

                        if (fieldAttribute.Location == FieldLocation.Local)
                        {
                            basicFieldMaps.Add(fieldAttribute.Ordinal, fieldMap);
                        }
                        else if (fieldAttribute.Location == FieldLocation.Foreign)
                        {
                            advancedFieldMaps.Add(fieldMap);

                            if (!string.IsNullOrEmpty(fieldAttribute.ForeignParentFieldName))
                            {
                                linkRecords.Add(new LinkRecord(fieldAttribute.ForeignRecordName, fieldAttribute.ForeignParentFieldName, fieldAttribute.ForeignChildFieldName, fieldMap));
                            }
                        }
                    }
                    foreach (IndexAttribute attribute in property.GetCustomAttributes(typeof(IndexAttribute), true))
                    {
                        IndexMap indexMap = new IndexMap(attribute, property);
                        indexMaps.Add(indexMap);
                    }
                }
                foreach (Type interfaceType in type.GetInterfaces())
                {
                    foreach (PropertyInfo interfaceProperty in interfaceType.GetProperties())
                    {
                        foreach (FieldAttribute attribute in interfaceProperty.GetCustomAttributes(typeof(FieldAttribute), true))
                        {
                            FieldMap fieldMap = new FieldMap(attribute, interfaceProperty);

                            if (attribute.Location == FieldLocation.Local)
                            {
                                basicFieldMaps.Add(attribute.Ordinal, fieldMap);
                            }
                            else if (attribute.Location == FieldLocation.Foreign)
                            {
                                advancedFieldMaps.Add(fieldMap);

                                if (!string.IsNullOrEmpty(attribute.ForeignParentFieldName))
                                {
                                    linkRecords.Add(new LinkRecord(attribute.ForeignRecordName, attribute.ForeignParentFieldName, attribute.ForeignChildFieldName, fieldMap));
                                }
                            }
                        }
                        foreach (IndexAttribute attribute in interfaceProperty.GetCustomAttributes(typeof(IndexAttribute), true))
                        {
                            IndexMap indexMap = new IndexMap(attribute, interfaceProperty);
                            indexMaps.Add(indexMap);
                        }
                    }
                }

                recordMap = new RecordMap(type, recordAttribute, recordTypeAttribute, basicFieldMaps, advancedFieldMaps, indexMaps, linkRecords);
            }

            return(recordMap);
        }