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); }
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)); } }
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); } }
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 } }
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 } }
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 } }
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)); }