-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: entity framework core to ado.net (#47)
- Loading branch information
Showing
31 changed files
with
1,029 additions
and
545 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.idea/.idea.AzureAppConfigurationEmulator/.idea/sqldialects.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/AzureAppConfigurationEmulator/Contexts/ApplicationDbContext.cs
This file was deleted.
Oops, something went wrong.
15 changes: 9 additions & 6 deletions
15
src/AzureAppConfigurationEmulator/Entities/ConfigurationSetting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
namespace AzureAppConfigurationEmulator.Entities; | ||
|
||
public class ConfigurationSetting( | ||
string eTag, | ||
string etag, | ||
string key, | ||
string label, | ||
string? label, | ||
string? contentType, | ||
string? value, | ||
DateTimeOffset lastModified, | ||
bool isReadOnly) | ||
bool locked, | ||
IDictionary<string, object?>? tags) | ||
{ | ||
public string ETag { get; set; } = eTag; | ||
public string Etag { get; set; } = etag; | ||
|
||
public string Key { get; set; } = key; | ||
|
||
public string Label { get; set; } = label; | ||
public string? Label { get; set; } = label; | ||
|
||
public string? ContentType { get; set; } = contentType; | ||
|
||
public string? Value { get; set; } = value; | ||
|
||
public DateTimeOffset LastModified { get; set; } = lastModified; | ||
|
||
public bool IsReadOnly { get; set; } = isReadOnly; | ||
public bool Locked { get; set; } = locked; | ||
|
||
public IDictionary<string, object?>? Tags { get; set; } = tags; | ||
} |
44 changes: 0 additions & 44 deletions
44
src/AzureAppConfigurationEmulator/Entities/ConfigurationSettingRevision.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
src/AzureAppConfigurationEmulator/Extensions/StringExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/AzureAppConfigurationEmulator/Factories/DbCommandFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections; | ||
using System.Data.Common; | ||
|
||
namespace AzureAppConfigurationEmulator.Factories; | ||
|
||
public class DbCommandFactory(ILogger<DbCommandFactory>? logger = null) : IDbCommandFactory | ||
{ | ||
private ILogger<DbCommandFactory>? Logger { get; } = logger; | ||
|
||
public DbCommand Create(DbConnection connection, string? text = null, IEnumerable<DbParameter>? parameters = null) | ||
{ | ||
Logger?.LogDebug("Creating the command."); | ||
var command = connection.CreateCommand(); | ||
|
||
if (text is not null) | ||
{ | ||
Logger?.LogDebug("Setting the command text."); | ||
command.CommandText = text; | ||
} | ||
|
||
if (parameters is not null) | ||
{ | ||
Logger?.LogDebug("Enumerating the parameters."); | ||
foreach (var parameter in parameters) | ||
{ | ||
using (Logger?.BeginScope(new DbParameterLogScope(parameter))) | ||
{ | ||
Logger?.LogDebug("Adding the parameter."); | ||
command.Parameters.Add(parameter); | ||
} | ||
} | ||
} | ||
|
||
return command; | ||
} | ||
|
||
private class DbParameterLogScope(DbParameter parameter) : IEnumerable<KeyValuePair<string, object?>> | ||
{ | ||
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator() | ||
{ | ||
yield return new KeyValuePair<string, object?>("ParameterName", parameter.ParameterName); | ||
|
||
yield return new KeyValuePair<string, object?>("ParameterValue", parameter.Value); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"ParameterName:{parameter.ParameterName} ParameterValue:{parameter.Value}"; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/AzureAppConfigurationEmulator/Factories/DbConnectionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Data.Common; | ||
using Microsoft.Data.Sqlite; | ||
|
||
namespace AzureAppConfigurationEmulator.Factories; | ||
|
||
public class DbConnectionFactory(IConfiguration? configuration = null) : IDbConnectionFactory | ||
{ | ||
private string ConnectionString { get; } = configuration?.GetConnectionString("DefaultConnection") ?? $"Data Source={DatabasePath}"; | ||
|
||
private static string DatabasePath { get; } = Environment.OSVersion.Platform switch | ||
{ | ||
PlatformID.Win32S => @"C:\ProgramData\Azure App Configuration Emulator\emulator.db", | ||
PlatformID.Win32Windows => @"C:\ProgramData\Azure App Configuration Emulator\emulator.db", | ||
PlatformID.Win32NT => @"C:\ProgramData\Azure App Configuration Emulator\emulator.db", | ||
PlatformID.WinCE => @"C:\ProgramData\Azure App Configuration Emulator\emulator.db", | ||
PlatformID.Unix => "/var/lib/azureappconfigurationemulator/emulator.db", | ||
PlatformID.MacOSX => "/var/lib/azureappconfigurationemulator/emulator.db", | ||
_ => throw new ArgumentOutOfRangeException() | ||
}; | ||
|
||
public DbConnection Create() | ||
{ | ||
return new SqliteConnection(ConnectionString); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/AzureAppConfigurationEmulator/Factories/DbParameterFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Data.Common; | ||
using System.Text.Json; | ||
using Microsoft.Data.Sqlite; | ||
|
||
namespace AzureAppConfigurationEmulator.Factories; | ||
|
||
public class DbParameterFactory : IDbParameterFactory | ||
{ | ||
public DbParameter Create<TValue>(string name, TValue? value) | ||
{ | ||
return value switch | ||
{ | ||
bool b => new SqliteParameter(name, SqliteType.Integer) { Value = b ? 1 : 0 }, | ||
DateTime d => new SqliteParameter(name, SqliteType.Text) { Value = d.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") }, | ||
DateTimeOffset d => new SqliteParameter(name, SqliteType.Text) { Value = d.UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss") }, | ||
IDictionary<string, object?> d => new SqliteParameter(name, SqliteType.Text) { Value = JsonSerializer.Serialize(d) }, | ||
int i => new SqliteParameter(name, SqliteType.Integer) { Value = i }, | ||
null => new SqliteParameter(name, SqliteType.Text) { Value = DBNull.Value }, | ||
string s => new SqliteParameter(name, SqliteType.Text) { Value = s }, | ||
_ => new SqliteParameter(name, SqliteType.Text) { Value = value.ToString() } | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/AzureAppConfigurationEmulator/Factories/IDbCommandFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Data.Common; | ||
|
||
namespace AzureAppConfigurationEmulator.Factories; | ||
|
||
public interface IDbCommandFactory | ||
{ | ||
public DbCommand Create(DbConnection connection, string? text = null, IEnumerable<DbParameter>? parameters = null); | ||
} |
Oops, something went wrong.