示例#1
0
        public override async Task <T> GetEventAsync <T>(object eventId)
        {
            if (JsonColumnNameBuilder == null)
            {
                return(null);
            }
            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(null)))
            {
                var cmdText = GetSelectCommandText(null);
#if NET45
                var result = ctx.Database.SqlQuery <string>(cmdText, new SqlParameter("@eventId", eventId));
                var json   = await result.FirstOrDefaultAsync();
#elif NETSTANDARD1_3 || NETSTANDARD2_0
                var result = ctx.FakeIdSet.FromSql(cmdText, new SqlParameter("@eventId", eventId));
                var json   = (await result.FirstOrDefaultAsync())?.Id;
#elif NETSTANDARD2_1
                var result = ctx.FakeIdSet.FromSqlRaw(cmdText, new SqlParameter("@eventId", eventId));
                var json   = (await result.FirstOrDefaultAsync())?.Id;
#endif
                if (json != null)
                {
                    return(AuditEvent.FromJson <T>(json));
                }
            }
            return(null);
        }
示例#2
0
        private AuditContext CreateContext(AuditEvent auditEvent)
        {
#if NET45
            return(new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent), SetDatabaseInitializerNull));
#else
            return(new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)));
#endif
        }
        public override void ReplaceEvent(object eventId, AuditEvent auditEvent)
        {
            var json = auditEvent.ToJson();

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetReplaceCommandText(auditEvent);
                ctx.Database.ExecuteSqlCommand(cmdText, new SqlParameter("@json", json), new SqlParameter("@eventId", eventId));
            }
        }
示例#4
0
        public override void ReplaceEvent(object eventId, AuditEvent auditEvent)
        {
            var parameters = GetParametersForReplace(eventId, auditEvent);

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetReplaceCommandText(auditEvent);
                ctx.Database.ExecuteSqlCommand(cmdText, parameters);
            }
        }
示例#5
0
        private IDocumentClient InitializeClient(AuditEvent auditEvent)
        {
            var policy = ConnectionPolicyBuilder?.Invoke(auditEvent)
                         ?? new ConnectionPolicy
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            };

            DocumentClient = new DocumentClient(new Uri(ConnectionStringBuilder?.Invoke(auditEvent)), AuthKeyBuilder?.Invoke(auditEvent), Configuration.JsonSettings, policy);
            Task.Run(() => { ((DocumentClient)DocumentClient).OpenAsync(); });

            return(DocumentClient);
        }
        public override async Task ReplaceEventAsync(object eventId, AuditEvent auditEvent)
        {
            var json = auditEvent.ToJson();

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetReplaceCommandText(auditEvent);
#if NETSTANDARD1_3
                await ctx.Database.ExecuteSqlCommandAsync(cmdText, default(CancellationToken), new SqlParameter("@json", json), new SqlParameter("@eventId", eventId));
#else
                await ctx.Database.ExecuteSqlCommandAsync(cmdText, new SqlParameter("@json", json), new SqlParameter("@eventId", eventId));
#endif
            }
        }
示例#7
0
        public override async Task ReplaceEventAsync(object eventId, AuditEvent auditEvent)
        {
            var parameters = GetParametersForReplace(eventId, auditEvent);

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetReplaceCommandText(auditEvent);
#if NETSTANDARD1_3
                await ctx.Database.ExecuteSqlCommandAsync(cmdText, default(CancellationToken), parameters);
#else
                await ctx.Database.ExecuteSqlCommandAsync(cmdText, parameters);
#endif
            }
        }
示例#8
0
        private AuditContext CreateContext(AuditEvent auditEvent)
        {
#if NET45
            return(new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent), SetDatabaseInitializerNull));
#else
            if (DbContextOptionsBuilder != null)
            {
                return(new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent), DbContextOptionsBuilder.Invoke(auditEvent)));
            }
            else
            {
                return(new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)));
            }
#endif
        }
        public override async Task <object> InsertEventAsync(AuditEvent auditEvent)
        {
            var json = new SqlParameter("json", auditEvent.ToJson());

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetInsertCommandText(auditEvent);
#if NET45
                var result = ctx.Database.SqlQuery <string>(cmdText, json);
                return(await result.FirstOrDefaultAsync());
#elif NETSTANDARD1_3 || NETSTANDARD2_0
                var result = ctx.FakeIdSet.FromSql(cmdText, json);
                return((await result.FirstOrDefaultAsync()).Id);
#endif
            }
        }
示例#10
0
        public override object InsertEvent(AuditEvent auditEvent)
        {
            var parameters = GetParametersForInsert(auditEvent);

            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(auditEvent)))
            {
                var cmdText = GetInsertCommandText(auditEvent);
#if NET45
                var result = ctx.Database.SqlQuery <string>(cmdText, parameters);
                return(result.FirstOrDefault());
#elif NETSTANDARD1_3 || NETSTANDARD2_0
                var result = ctx.FakeIdSet.FromSql(cmdText, parameters);
                return(result.FirstOrDefault().Id);
#endif
            }
        }
        public override T GetEvent <T>(object eventId)
        {
            using (var ctx = new AuditContext(ConnectionStringBuilder?.Invoke(null)))
            {
                var cmdText = GetSelectCommandText(null);
#if NET45
                var result = ctx.Database.SqlQuery <string>(cmdText, new SqlParameter("eventId", eventId));
                var json   = result.FirstOrDefault();
#elif NETSTANDARD1_3 || NETSTANDARD2_0
                var result = ctx.FakeIdSet.FromSql(cmdText, new SqlParameter("eventId", eventId));
                var json   = result.FirstOrDefault()?.Id;
#endif
                if (json != null)
                {
                    return(AuditEvent.FromJson <T>(json));
                }
            }
            return(null);
        }
 protected string GetConnectionString(AuditEvent auditEvent)
 {
     return(ConnectionStringBuilder?.Invoke(auditEvent));
 }