Initial Commit
This commit is contained in:
0
Infrastructure/.keep
Normal file
0
Infrastructure/.keep
Normal file
166
Infrastructure/Database/DbCommandInterceptor.cs
Normal file
166
Infrastructure/Database/DbCommandInterceptor.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
37
Infrastructure/Database/ExDbContext.cs
Normal file
37
Infrastructure/Database/ExDbContext.cs
Normal 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;");
|
||||
}
|
||||
}
|
||||
}
|
33
Infrastructure/Infrastructure.csproj
Normal file
33
Infrastructure/Infrastructure.csproj
Normal file
@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Services\**" />
|
||||
<EmbeddedResource Remove="Services\**" />
|
||||
<None Remove="Services\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0" />
|
||||
<PackageReference Include="NLog" Version="4.6.8" />
|
||||
<PackageReference Include="NLog.Config" Version="4.6.8" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.1" />
|
||||
<PackageReference Include="NLog.Schema" Version="4.6.8" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user