stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StellaOps.Provcache;
|
||||
|
||||
public sealed partial class DecisionDigestBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the verdict hash directly.
|
||||
/// </summary>
|
||||
public DecisionDigestBuilder WithVerdictHash(string verdictHash)
|
||||
{
|
||||
_verdictHash = verdictHash ?? throw new ArgumentNullException(nameof(verdictHash));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes verdict hash from sorted dispositions.
|
||||
/// Dispositions are sorted by key for deterministic hashing.
|
||||
/// </summary>
|
||||
/// <param name="dispositions">Dictionary of finding ID to disposition.</param>
|
||||
public DecisionDigestBuilder WithDispositions(IReadOnlyDictionary<string, string> dispositions)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(dispositions);
|
||||
|
||||
var sorted = dispositions
|
||||
.OrderBy(kvp => kvp.Key, StringComparer.Ordinal)
|
||||
.ToList();
|
||||
|
||||
if (sorted.Count == 0)
|
||||
{
|
||||
_verdictHash = ComputeHash(Encoding.UTF8.GetBytes("empty-verdict"));
|
||||
return this;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var (key, value) in sorted)
|
||||
{
|
||||
if (sb.Length > 0) sb.Append('|');
|
||||
sb.Append(key);
|
||||
sb.Append('=');
|
||||
sb.Append(value);
|
||||
}
|
||||
|
||||
_verdictHash = ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user