Initial Commit

This commit is contained in:
2020-11-10 21:44:20 +11:00
parent 43e9398507
commit 1aac34878e
44 changed files with 70899 additions and 73 deletions

View File

@ -0,0 +1,166 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Infrastructure.Data.OliVerse
{
public class OutputCommandInterceptor : IDbCommandInterceptor
{
public List<string> NonQueries = new List<string>();
public InterceptionResult<DbCommand> CommandCreating(CommandCorrelatedEventData eventData, InterceptionResult<DbCommand> result)
{
return result;
}
public DbCommand CommandCreated(CommandEndEventData eventData, DbCommand result)
{
return result;
}
public InterceptionResult<DbDataReader> ReaderExecuting(
DbCommand command,
CommandEventData eventData,
InterceptionResult<DbDataReader> result
)
{
var cmd = command.CommandText;
var paramRegex = new Regex("@\\w+");
var matches = paramRegex.Matches(cmd);
//cmd = matches.Cast<Match>().Aggregate(cmd, (current, match) => current.Replace(match.Value, command.Parameters.Cast<SqParameter>().First(p => p.ParameterName == match.Value).Value.ToString())); ;
if (matches.Count > 0)
{
}
NonQueries.Add(command.CommandText);
return result;
}
public InterceptionResult<object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<object> result)
{
return result;
}
public InterceptionResult<int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<int> result)
{
var cmd = command.CommandText;
foreach (DbParameter parameter in command.Parameters)
{
cmd = parameter.DbType == DbType.String
? cmd.Replace(parameter.ParameterName, "'" + parameter.Value + "'")
: cmd.Replace(parameter.ParameterName, parameter.Value.ToString());
}
NonQueries.Add(cmd);
//(command as En SqlCeMultiCommand)
//command.Cancel();
return result;
}
public Task<InterceptionResult<DbDataReader>> ReaderExecutingAsync(
DbCommand command,
CommandEventData eventData,
InterceptionResult<DbDataReader> result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public Task<InterceptionResult<object>> ScalarExecutingAsync(
DbCommand command,
CommandEventData eventData,
InterceptionResult<object> result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public Task<InterceptionResult<int>> NonQueryExecutingAsync(
DbCommand command,
CommandEventData eventData,
InterceptionResult<int> result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public DbDataReader ReaderExecuted(DbCommand command, CommandExecutedEventData eventData, DbDataReader result)
{
return result;
}
public object ScalarExecuted(DbCommand command, CommandExecutedEventData eventData, object result)
{
return result;
}
public int NonQueryExecuted(DbCommand command, CommandExecutedEventData eventData, int result)
{
NonQueries.Add(command.CommandText);
return result;
}
public Task<DbDataReader> ReaderExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
DbDataReader result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public Task<object> ScalarExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
object result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public Task<int> NonQueryExecutedAsync(
DbCommand command,
CommandExecutedEventData eventData,
int result,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.FromResult(result);
}
public void CommandFailed(DbCommand command, CommandErrorEventData eventData)
{
NonQueries.Add(command.CommandText);
}
public Task CommandFailedAsync(
DbCommand command,
CommandErrorEventData eventData,
CancellationToken cancellationToken = new CancellationToken()
)
{
return Task.CompletedTask;
}
public InterceptionResult DataReaderDisposing(DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult result)
{
return result;
}
}
}

View File

@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Data
{
public class ExDbContext : DbContext
{
private string connectionString;
public ExDbContext()
{ }
public ExDbContext(DbContextOptions options) : base(options)
{ }
public ExDbContext(string connectionString)
{
this.connectionString = connectionString;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
if (!string.IsNullOrWhiteSpace(connectionString))
{
optionsBuilder.UseSqlServer(connectionString);
}
//optionsBuilder.UseSqlServer("Server=tcp:kyljx9pxvr-dev.database.windows.net,1433;Database=oliverse_db_dev;User ID=olipos_admin@kyljx9pxvr-dev;Password=Mentor21;Trusted_Connection=False;Encrypt=True;Connection Timeout=150;");
}
}
}