Example #1
0
        /// <summary>
        /// Creates the Audit scope.
        /// </summary>
        public IAuditScope CreateAuditScope(IAuditDbContext context, EntityFrameworkEvent efEvent)
        {
            var typeName     = context.GetType().Name;
            var eventType    = context.AuditEventType?.Replace("{context}", typeName).Replace("{database}", efEvent.Database) ?? typeName;
            var auditEfEvent = new AuditEventEntityFramework
            {
                EntityFrameworkEvent = efEvent
            };

            if (context.ExtraFields != null && context.ExtraFields.Count > 0)
            {
                auditEfEvent.CustomFields = new Dictionary <string, object>(context.ExtraFields);
            }
            var factory = context.AuditScopeFactory ?? Core.Configuration.AuditScopeFactory;
            var options = new AuditScopeOptions()
            {
                EventType       = eventType,
                CreationPolicy  = EventCreationPolicy.Manual,
                DataProvider    = context.AuditDataProvider,
                AuditEvent      = auditEfEvent,
                SkipExtraFrames = 3
            };
            var scope = factory.Create(options);

            context.OnScopeCreated(scope);
            return(scope);
        }
Example #2
0
        /// <summary>
        /// Creates the Audit scope asynchronously.
        /// </summary>
        public async Task <IAuditScope> CreateAuditScopeAsync(IAuditDbContext context, EntityFrameworkEvent efEvent)
        {
            var typeName     = context.GetType().Name;
            var eventType    = context.AuditEventType?.Replace("{context}", typeName).Replace("{database}", efEvent.Database) ?? typeName;
            var auditEfEvent = new AuditEventEntityFramework
            {
                EntityFrameworkEvent = efEvent
            };
            var factory = context.AuditScopeFactory ?? Core.Configuration.AuditScopeFactory;
            var options = new AuditScopeOptions()
            {
                EventType       = eventType,
                CreationPolicy  = EventCreationPolicy.Manual,
                DataProvider    = context.AuditDataProvider,
                AuditEvent      = auditEfEvent,
                SkipExtraFrames = 3
            };
            var scope = await factory.CreateAsync(options);

            if (context.ExtraFields != null)
            {
                foreach (var field in context.ExtraFields)
                {
                    scope.SetCustomField(field.Key, field.Value);
                }
            }
            context.OnScopeCreated(scope);
            return(scope);
        }
Example #3
0
        /// <summary>
        /// Creates the Audit scope asynchronously.
        /// </summary>
        public async Task <AuditScope> CreateAuditScopeAsync(IAuditDbContext context, EntityFrameworkEvent efEvent)
        {
            var typeName     = context.GetType().Name;
            var eventType    = context.AuditEventType?.Replace("{context}", typeName).Replace("{database}", efEvent.Database) ?? typeName;
            var auditEfEvent = new AuditEventEntityFramework();

            auditEfEvent.EntityFrameworkEvent = efEvent;
            var scope = await AuditScope.CreateAsync(eventType, null, null, EventCreationPolicy.Manual, context.AuditDataProvider, auditEfEvent, 3);

            if (context.ExtraFields != null)
            {
                foreach (var field in context.ExtraFields)
                {
                    scope.SetCustomField(field.Key, field.Value);
                }
            }
            context.OnScopeCreated(scope);
            return(scope);
        }
Example #4
0
        /// <summary>
        /// Creates the Audit scope.
        /// </summary>
        private AuditScope CreateAuditScope(EntityFrameworkEvent efEvent)
        {
            var typeName     = GetType().Name;
            var eventType    = AuditEventType?.Replace("{context}", typeName).Replace("{database}", efEvent.Database) ?? typeName;
            var auditEfEvent = new AuditEventEntityFramework();

            auditEfEvent.EntityFrameworkEvent = efEvent;
            var scope = AuditScope.Create(eventType, null, null, EventCreationPolicy.Manual, AuditDataProvider, auditEfEvent, 2);

            if (_extraFields != null)
            {
                foreach (var field in _extraFields)
                {
                    scope.SetCustomField(field.Key, field.Value);
                }
            }
            OnScopeCreated(scope);
            return(scope);
        }