Skip to content

Commit

Permalink
exception and type helper unification
Browse files Browse the repository at this point in the history
  • Loading branch information
wickedmachinator committed Nov 11, 2024
1 parent e78ebb8 commit 80ca8c8
Show file tree
Hide file tree
Showing 30 changed files with 244 additions and 372 deletions.
2 changes: 1 addition & 1 deletion EtLast.AdoNet.MsSql/EtLast.AdoNet.MsSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FizzCode.LightWeight.AdoNet.DbConnection" Version="8.0.23" />
<PackageReference Include="FizzCode.LightWeight.AdoNet.DbConnection" Version="8.0.36" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 4 additions & 4 deletions EtLast.AdoNet/AdoNetDbReader/AbstractAdoNetDbReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public abstract class AbstractAdoNetDbReader : AbstractRowSource
/// <summary>
/// If initialized with a list, then the column info returned by the ADO.NET connector based on the given query will be stored in it.
/// </summary>
public List<ColumnDataTypeInfo> ColumnInfoList { get; init; } = [];
public List<DataTypeInfo> ColumnInfoList { get; init; } = [];

public Action<IReadOnlyList<ColumnDataTypeInfo>> ColumnInfoListTester { get; init; }
public Action<IReadOnlyList<DataTypeInfo>> ColumnInfoListTester { get; init; }

public Func<string, string> SqlStatementCustomizer { get; init; }

Expand Down Expand Up @@ -225,7 +225,7 @@ protected override IEnumerable<IRow> Produce()
var clrType = reader.GetFieldType(i);
var hasPrecisionOrScale = clrType == typeof(decimal) || clrType == typeof(double) || clrType == typeof(float);

var info = new ColumnDataTypeInfo()
var info = new DataTypeInfo()
{
Name = columns[i].NameInRow,
ClrType = reader.GetFieldType(i),
Expand Down Expand Up @@ -454,7 +454,7 @@ private class MappedColumn
{
public string NameInRow { get; init; }
public ReaderColumn Config { get; init; }
public ColumnDataTypeInfo Info { get; set; }
public DataTypeInfo Info { get; set; }
}

protected abstract IoCommand RegisterIoCommand(string transactionId, int timeout, string statement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface ISqlValueProcessor
{
bool Init(IAdoNetSqlConnectionString connectionString);
object ProcessValue(object value, ColumnDataTypeInfo info);
object ProcessValue(object value, DataTypeInfo info);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public bool Init(IAdoNetSqlConnectionString connectionString)
return connectionString.SqlEngine == AdoNetEngine.MsSql;
}

public object ProcessValue(object value, ColumnDataTypeInfo info)
public object ProcessValue(object value, DataTypeInfo info)
{
if (value == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public bool Init(IAdoNetSqlConnectionString connectionString)
return connectionString.SqlEngine == AdoNetEngine.MySql;
}

public object ProcessValue(object value, ColumnDataTypeInfo info)
public object ProcessValue(object value, DataTypeInfo info)
{
if (value == null)
return null;
Expand Down
2 changes: 1 addition & 1 deletion EtLast.AdoNet/EtLast.AdoNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FizzCode.LightWeight.AdoNet.DbConnection" Version="8.0.23" />
<PackageReference Include="FizzCode.LightWeight.AdoNet.DbConnection" Version="8.0.36" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion EtLast.CommandService/CommandService.RunTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override IExecutionResult RunTasks(string commandId, string moduleName
}
catch (Exception ex)
{
var formattedMessage = ex.FormatExceptionWithDetails();
var formattedMessage = ex.FormatWithEtlDetails();
context.Log(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
context.LogOps(LogSeverity.Error, null, "{ErrorMessage}", formattedMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion EtLast.CommandService/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArg
if (e?.ExceptionObject is not Exception ex)
return;

var formattedMessage = ex.FormatExceptionWithDetails();
var formattedMessage = ex.FormatWithEtlDetails();

if (Logger != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void SaveManifest(ContextManifest manifest)
}
catch (Exception ex)
{
_context.Log(LogSeverity.Warning, null, "error while writing manifest: {ErrorMessage}", ex.FormatExceptionWithDetails(false));
_context.Log(LogSeverity.Warning, null, "error while writing manifest: {ErrorMessage}", ex.FormatWithEtlDetails(false));
}
}
}
2 changes: 1 addition & 1 deletion EtLast.CommandService/EtLast.CommandService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FizzCode.LightWeight.Configuration" Version="8.0.23" />
<PackageReference Include="FizzCode.LightWeight.Configuration" Version="8.0.36" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion EtLast.Diagnostics.HttpSender/DiagnosticsHttpSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void OnContextIoCommandEnd(IoCommand ioCommand)
{
writer.Write7BitEncodedInt64(ioCommand.Id);
writer.WriteNullable7BitEncodedInt64(ioCommand.AffectedDataCount);
writer.WriteNullable(ioCommand.Exception?.FormatExceptionWithDetails());
writer.WriteNullable(ioCommand.Exception?.FormatWithEtlDetails());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public IExecutionResult RunCommand(string source, string commandId, string origi
}
catch (Exception ex)
{
var formattedMessage = ex.FormatExceptionWithDetails();
var formattedMessage = ex.FormatWithEtlDetails();
Logger.Write(LogEventLevel.Fatal, "unexpected error during execution of command {CommandId}: {ErrorMessage}", commandId, formattedMessage);

result = new ExecutionResult(ExecutionStatusCode.UnexpectedError);
Expand All @@ -331,7 +331,7 @@ private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArg
if (e?.ExceptionObject is not Exception ex)
return;

var formattedMessage = ex.FormatExceptionWithDetails();
var formattedMessage = ex.FormatWithEtlDetails();

if (Logger != null)
{
Expand Down
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void OnCustomLog(bool forOps, string fileName, IProcess process, string t

public void OnException(IProcess process, Exception exception)
{
var msg = exception.FormatExceptionWithDetails();
var msg = exception.FormatWithEtlDetails();
Log(LogSeverity.Error, false, null, process, "{ErrorMessage}", msg);
}

Expand Down
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextDevToFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void OnCustomLog(bool forOps, string fileName, IProcess process, string t

public void OnException(IProcess process, Exception exception)
{
var msg = exception.FormatExceptionWithDetails();
var msg = exception.FormatWithEtlDetails();
Log(LogSeverity.Error, false, null, process, "{ErrorMessage}", msg);
}

Expand Down
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextDevToSeqLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void OnCustomLog(bool forOps, string fileName, IProcess process, string t

public void OnException(IProcess process, Exception exception)
{
var msg = exception.FormatExceptionWithDetails();
var msg = exception.FormatWithEtlDetails();
Log(LogSeverity.Error, false, null, process, "{ErrorMessage}", msg);
}

Expand Down
2 changes: 1 addition & 1 deletion EtLast.Hosting/Logging/EtlContextIoToFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void OnContextIoCommandEnd(IoCommand ioCommand)
if (ioCommand.Exception != null)
{
sb.Append('\t').Append("exception"); // message
sb.Append(ioCommand.Exception.FormatExceptionWithDetails().ReplaceLineEndings("\\n")); // messageExtra
sb.Append(ioCommand.Exception.FormatWithEtlDetails().ReplaceLineEndings("\\n")); // messageExtra
}

_logger.Write(LogEventLevel.Information, sb.ToString());
Expand Down
2 changes: 1 addition & 1 deletion EtLast.LocalFiles/LocalJsonFileManifestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void SaveManifest(ContextManifest manifest)
}
catch (Exception ex)
{
_context.Log(LogSeverity.Warning, null, "error while writing manifest: {ErrorMessage}", ex.FormatExceptionWithDetails(false));
_context.Log(LogSeverity.Warning, null, "error while writing manifest: {ErrorMessage}", ex.FormatWithEtlDetails(false));
}
}
}
44 changes: 43 additions & 1 deletion EtLast/ColumnDataTypeInfo.cs → EtLast/DataTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FizzCode.EtLast;

public class ColumnDataTypeInfo
public class DataTypeInfo
{
public string Name { get; init; }

Expand Down Expand Up @@ -46,4 +46,46 @@ public override string ToString()
{
return Name + ", " + ClrTypeName + ", " + DataTypeName + (Precision != null && Scale != null ? " (" + Precision.Value.ToString(CultureInfo.InvariantCulture) + ", " + Scale.Value.ToString(CultureInfo.InvariantCulture) + ")" : "");
}

public static string GetSchemaVer(List<DataTypeInfo> columns, string[] keyColumns)
{
var keySet = keyColumns.ToHashSet(StringComparer.InvariantCultureIgnoreCase);

var sb = new StringBuilder();
foreach (var col in columns.OrderBy(x => x.Name.ToLowerInvariant()))
{
sb
.AppendJoin('\t',
col.Name.ToLowerInvariant(),
col.ClrTypeName.ToLowerInvariant(),
col.DataTypeName.ToLowerInvariant(),
col.Precision?.ToString(CultureInfo.InvariantCulture) ?? "-",
col.Scale?.ToString(CultureInfo.InvariantCulture) ?? "-",
col.Size?.ToString(CultureInfo.InvariantCulture) ?? "-",
keySet.Contains(col.Name) ? "key" : "-"
)
.Append('\n');
}

var content = sb.ToString();
var data = Encoding.UTF8.GetBytes(content);

var hash1 = 0x811C9DC5;
var hash2 = 0x811C9DC5;

for (var i = 0; i < data.Length; i++)
{
hash1 ^= data[i];
hash1 *= 0x01000193;
}

for (var i = data.Length; i >= 0; i--)
{
hash2 ^= data[i];
hash2 *= 0x01000193;
}

var hashStr = (columns.Count % 256).ToString("X2") + hash1.ToString("X8") + (hash2 % 256).ToString("X2");
return hashStr;
}
}
2 changes: 1 addition & 1 deletion EtLast/EtLast.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FizzCode.LightWeight.ConnectionString" Version="8.0.23" />
<PackageReference Include="FizzCode.LightWeight" Version="8.0.36" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit 80ca8c8

Please sign in to comment.