private readonly Cfg.Configuration _configuration;         //for serialization

        private AuditConfiguration(Cfg.Configuration cfg, IMetaDataProvider metaDataProvider)
        {
            //this might be over kill - move back into MetaDataStore later if not needed for other stuff...
            var metaDataAdders = new List <IMetaDataAdder> {
                new AuditMappedByMetaDataAdder(cfg)
            };

            var mds        = new MetaDataStore(cfg, metaDataProvider, metaDataAdders);
            var properties = cfg.Properties;

            GlobalCfg = new GlobalConfiguration(this, properties);

            var revInfoCfg       = new RevisionInfoConfiguration(GlobalCfg, mds);
            var revInfoCfgResult = revInfoCfg.Configure(cfg);

            AuditEntCfg         = new AuditEntitiesConfiguration(properties, revInfoCfgResult.RevisionInfoEntityName);
            AuditProcessManager = new AuditProcessManager(revInfoCfgResult.RevisionInfoGenerator);

            RevisionTimestampGetter = ReflectionTools.GetGetter(revInfoCfgResult.RevisionInfoClass, revInfoCfgResult.RevisionInfoTimestampData);

            RevisionInfoQueryCreator  = revInfoCfgResult.RevisionInfoQueryCreator;
            RevisionInfoNumberReader  = revInfoCfgResult.RevisionInfoNumberReader;
            ModifiedEntityNamesReader = revInfoCfgResult.ModifiedEntityNamesReader;
            EntCfg = new EntitiesConfigurator()
                     .Configure(cfg, mds, GlobalCfg, AuditEntCfg, revInfoCfgResult.RevisionInfoXmlMapping, revInfoCfgResult.RevisionInfoRelationMapping);
            _configuration = cfg;
        }
Пример #2
0
        public override bool MapToEntityFromMap(object obj, IDictionary data)
        {
            if (data == null || obj == null)
            {
                return(false);
            }

            var objType = obj.GetType();
            var getter  = ReflectionTools.GetGetter(objType, _idPropertyData);
            var setter  = ReflectionTools.GetSetter(objType, _idPropertyData);

            try
            {
                var subObj = ReflectionTools.CreateInstanceByDefaultConstructor(getter.ReturnType);
                var ret    = true;
                foreach (var idMapper in Ids.Values)
                {
                    ret &= idMapper.MapToEntityFromMap(subObj, data);
                }
                if (ret)
                {
                    setter.Set(obj, subObj);
                }
                return(ret);
            }
            catch (Exception e)
            {
                throw new AuditException("Cannot create instance of type " + getter.ReturnType, e);
            }
        }
        public bool MapToMapFromEntity(ISessionImplementor session,
                                       IDictionary <string, object> data,
                                       object newObj,
                                       object oldObj)
        {
            var ret = false;

            foreach (var propertyData in Properties.Keys)
            {
                IGetter getter;
                if (newObj != null)
                {
                    getter = ReflectionTools.GetGetter(newObj.GetType(), propertyData);
                }
                else if (oldObj != null)
                {
                    getter = ReflectionTools.GetGetter(oldObj.GetType(), propertyData);
                }
                else
                {
                    return(false);
                }

                ret |= Properties[propertyData].MapToMapFromEntity(session, data,
                                                                   newObj == null ? null : getter.Get(newObj),
                                                                   oldObj == null ? null : getter.Get(oldObj));
            }

            return(ret);
        }
 public object MapToObjectFromFullMap(EntityInstantiator entityInstantiator,
                                      IDictionary data,
                                      object dataObject,
                                      long revision)
 {
     // dataObject is not null, as this mapper can only be used in an index.
     return(ReflectionTools.GetGetter(dataObject.GetType(), _propertyName, _accessType).Get(dataObject));
 }
Пример #5
0
        public override object MapToIdFromEntity(object data)
        {
            if (data == null)
            {
                return(null);
            }
            var getter = ReflectionTools.GetGetter(data.GetType(), _idPropertyData);

            return(getter.Get(data));
        }
Пример #6
0
        public override void MapToMapFromEntity(IDictionary <string, object> data, object obj)
        {
            if (obj == null)
            {
                return;
            }
            var getter = ReflectionTools.GetGetter(obj.GetType(), _idPropertyData);

            MapToMapFromId(data, getter.Get(obj));
        }
Пример #7
0
 public DefaultTrackingModifiedEntitiesRevisionInfoGenerator(string revisionInfoEntityName,
                                                             System.Type revisionInfoType,
                                                             IRevisionListener revisionListener,
                                                             PropertyData revisionInfoTimestampData,
                                                             bool timestampAsDate,
                                                             PropertyData modifiedEntityNamesData)
     : base(revisionInfoEntityName, revisionInfoType, revisionListener, revisionInfoTimestampData, timestampAsDate)
 {
     modifiedEntityTypesGetter = ReflectionTools.GetGetter(revisionInfoType, modifiedEntityNamesData);
     modifiedEntityTypesSetter = ReflectionTools.GetSetter(revisionInfoType, modifiedEntityNamesData);
 }
Пример #8
0
        public override object MapToIdFromEntity(object data)
        {
            if (data == null)
            {
                return(null);
            }

            if (data is INHibernateProxy proxy)
            {
                return(proxy.HibernateLazyInitializer.Identifier);
            }
            var getter = ReflectionTools.GetGetter(data.GetType(), _propertyData);

            return(getter.Get(data));
        }
Пример #9
0
 public override void MapToMapFromEntity(IDictionary <string, object> data, object obj)
 {
     if (obj == null)
     {
         data.Add(_propertyData.Name, null);
     }
     else
     {
         if (obj is INHibernateProxy proxy)
         {
             data.Add(_propertyData.Name, proxy.HibernateLazyInitializer.Identifier);
         }
         else
         {
             var getter = ReflectionTools.GetGetter(obj.GetType(), _propertyData);
             data.Add(_propertyData.Name, getter.Get(obj));
         }
     }
 }
 public void MapModifiedFlagsToMapFromEntity(ISessionImplementor session, IDictionary <string, object> data, object newObj, object oldObj)
 {
     foreach (var propertyData in Properties.Keys)
     {
         IGetter getter;
         if (newObj != null)
         {
             getter = ReflectionTools.GetGetter(newObj.GetType(), propertyData);
         }
         else if (oldObj != null)
         {
             getter = ReflectionTools.GetGetter(oldObj.GetType(), propertyData);
         }
         else
         {
             return;
         }
         Properties[propertyData].MapModifiedFlagsToMapFromEntity(session, data,
                                                                  newObj == null ? null : getter.Get(newObj),
                                                                  oldObj == null ? null : getter.Get(oldObj));
     }
 }
 public ModifiedEntityNamesReader(System.Type revisionInfoClass, PropertyData modifiedEntityTypesData)
 {
     modifiedEntityTypesGetter = ReflectionTools.GetGetter(revisionInfoClass, modifiedEntityTypesData);
 }
 public RevisionInfoNumberReader(System.Type revisionInfoType, PropertyData revisionInfoIdData)
 {
     _getter = ReflectionTools.GetGetter(revisionInfoType, revisionInfoIdData);
 }