Enhance MemoryCacheExtensions and update HistoryController
- Modified `GetEnumAsDictionary` to accept a key and ignores for better caching and filtering of enum values. - Updated XML documentation in `HistoryController.cs` to correct status code descriptions. - Adjusted `GetEnvelopeStatus` to use the new parameters for improved control over cached enum values.
This commit is contained in:
parent
3fa113003c
commit
ce41090979
@ -6,11 +6,15 @@ public static class MemoryCacheExtensions
|
|||||||
{
|
{
|
||||||
private static readonly Guid BaseId = Guid.NewGuid();
|
private static readonly Guid BaseId = Guid.NewGuid();
|
||||||
|
|
||||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache)
|
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params IEnumerable<TEnum>[] ignores)
|
||||||
where TEnum : Enum
|
where TEnum : Enum
|
||||||
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName, _ =>
|
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName + key, _ =>
|
||||||
Enum.GetValues(typeof(TEnum))
|
{
|
||||||
|
List<TEnum> mergedIgnores = ignores.SelectMany(x => x).ToList();
|
||||||
|
return Enum.GetValues(typeof(TEnum))
|
||||||
.Cast<TEnum>()
|
.Cast<TEnum>()
|
||||||
.ToDictionary(e => e.ToString(), e => Convert.ToInt32(e)))
|
.Where(e => !mergedIgnores.Contains(e))
|
||||||
|
.ToDictionary(e => e.ToString(), e => Convert.ToInt32(e));
|
||||||
|
})
|
||||||
?? throw new InvalidOperationException($"Failed to cache or retrieve enum dictionary for type '{typeof(TEnum).FullName}'.");
|
?? throw new InvalidOperationException($"Failed to cache or retrieve enum dictionary for type '{typeof(TEnum).FullName}'.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,13 +39,13 @@ public class HistoryController : ControllerBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gibt alle möglichen Verweise auf alle möglichen Status in einem Verlaufsdatensatz zurück. (z. B. DocumentSigned bezieht sich auf Receiver.)
|
/// Gibt alle möglichen Verweise auf alle möglichen Status in einem Verlaufsdatensatz zurück. (z. B. DocumentSigned bezieht sich auf Receiver.)
|
||||||
/// Dies wird hinzugefügt, damit Client-Anwendungen sich selbst auf dem neuesten Stand halten können.
|
/// Dies wird hinzugefügt, damit Client-Anwendungen sich selbst auf dem neuesten Stand halten können.
|
||||||
/// 0 - Receiver:
|
|
||||||
/// Historische Datensätze, die sich auf den Status des Absenders beziehen. Sie haben Statuscodes, die mit 1* beginnen.
|
|
||||||
/// 1 - Sender:
|
/// 1 - Sender:
|
||||||
/// Historische Datensätze über den Status der Empfänger. Diese haben Statuscodes, die mit 2* beginnen.
|
/// Historische Datensätze über den Status der Empfänger. Diese haben Statuscodes, die mit 1* beginnen.
|
||||||
/// 2 - System:
|
/// 2 - Receiver:
|
||||||
|
/// Historische Datensätze, die sich auf den Status des Absenders beziehen. Sie haben Statuscodes, die mit 2* beginnen.
|
||||||
|
/// 3 - System:
|
||||||
/// Historische Datensätze, die sich auf den allgemeinen Zustand des Umschlags beziehen. Diese haben Statuscodes, die mit 3* beginnen.
|
/// Historische Datensätze, die sich auf den allgemeinen Zustand des Umschlags beziehen. Diese haben Statuscodes, die mit 3* beginnen.
|
||||||
/// 3 - Unknown:
|
/// 4 - Unknown:
|
||||||
/// Ein unbekannter Datensatz weist auf einen möglichen Mangel oder eine Unstimmigkeit im Aktualisierungsprozess der Anwendung hin.
|
/// Ein unbekannter Datensatz weist auf einen möglichen Mangel oder eine Unstimmigkeit im Aktualisierungsprozess der Anwendung hin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -95,7 +95,7 @@ public class HistoryController : ControllerBase
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public IActionResult GetEnvelopeStatus([FromQuery] EnvelopeStatus? status = null)
|
public IActionResult GetEnvelopeStatus([FromQuery] EnvelopeStatus? status = null)
|
||||||
{
|
{
|
||||||
return status is null ? Ok(_memoryCache.GetEnumAsDictionary<EnvelopeStatus>()) : Ok(status.ToString());
|
return status is null ? Ok(_memoryCache.GetEnumAsDictionary<EnvelopeStatus>("gen.api", Status.NonHist, Status.RelatedToFormApp)) : Ok(status.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user