Exemple #1
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);
        }
Exemple #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
            };

            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 = await factory.CreateAsync(options);

            context.OnScopeCreated(scope);
            return(scope);
        }
Exemple #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);
        }