126 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			126 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text.Json.Serialization;
 | |
| 
 | |
| namespace Adaptation.FileHandlers.Priority;
 | |
| 
 | |
| #nullable enable
 | |
| 
 | |
| public class Notification
 | |
| {
 | |
| 
 | |
|     [JsonConstructor]
 | |
|     public Notification(int? fibonacci,
 | |
|                         string? id,
 | |
|                         int? inverse,
 | |
|                         string? machineId,
 | |
|                         string page,
 | |
|                         string? site,
 | |
|                         string? sessionId,
 | |
|                         string time,
 | |
|                         string? username,
 | |
|                         string? value)
 | |
|     {
 | |
|         int? i = inverse is not null ? inverse : GetInverse(value);
 | |
|         Fibonacci = fibonacci is not null ? fibonacci : i is null ? null : GetFibonacci(i.Value);
 | |
|         Id = id;
 | |
|         Inverse = i;
 | |
|         MachineId = machineId;
 | |
|         Page = page;
 | |
|         Site = site is not null ? site : "MES";
 | |
|         SessionId = sessionId;
 | |
|         Time = time;
 | |
|         Username = username;
 | |
|         Value = value;
 | |
|     }
 | |
| 
 | |
|     [JsonPropertyName("id")] public string? Id { get; }
 | |
|     [JsonPropertyName("fibonacci")] public int? Fibonacci { get; }
 | |
|     [JsonPropertyName("inverse")] public int? Inverse { get; }
 | |
|     [JsonPropertyName("machineId")] public string? MachineId { get; }
 | |
|     [JsonPropertyName("page")] public string Page { get; }
 | |
|     [JsonPropertyName("site")] public string? Site { get; }
 | |
|     [JsonPropertyName("sessionId")] public string? SessionId { get; }
 | |
|     [JsonPropertyName("time")] public string Time { get; }
 | |
|     [JsonPropertyName("username")] public string? Username { get; }
 | |
|     [JsonPropertyName("value")] public string? Value { get; }
 | |
| 
 | |
|     internal static Notification Get(Dictionary<string, string?> keyValuePairs)
 | |
|     {
 | |
|         Notification results;
 | |
|         string? id;
 | |
|         string? fibonacci;
 | |
|         string? inverse;
 | |
|         string? machineId;
 | |
|         string? page;
 | |
|         string? site;
 | |
|         string? sessionId;
 | |
|         string? username;
 | |
|         string? time;
 | |
|         string? value;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(id), out id))
 | |
|             id = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(fibonacci), out fibonacci))
 | |
|             fibonacci = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(inverse), out inverse))
 | |
|             inverse = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(machineId), out machineId))
 | |
|             machineId = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(page), out page))
 | |
|             throw new Exception();
 | |
|         if (!keyValuePairs.TryGetValue(nameof(site), out site))
 | |
|             site = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(sessionId), out sessionId))
 | |
|             sessionId = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(username), out username))
 | |
|             username = null;
 | |
|         if (!keyValuePairs.TryGetValue(nameof(time), out time))
 | |
|             throw new Exception();
 | |
|         if (!keyValuePairs.TryGetValue(nameof(value), out value))
 | |
|             value = null;
 | |
|         results = new(fibonacci: fibonacci is null ? null : int.Parse(fibonacci),
 | |
|                       id: id,
 | |
|                       inverse: inverse is null ? null : int.Parse(inverse),
 | |
|                       machineId: machineId,
 | |
|                       page: page ?? throw new Exception(),
 | |
|                       site: site,
 | |
|                       sessionId: sessionId,
 | |
|                       time: time ?? throw new Exception(),
 | |
|                       username: username,
 | |
|                       value: value);
 | |
|         return results;
 | |
|     }
 | |
| 
 | |
|     internal static int? GetInverse(string? value) =>
 | |
|         value switch
 | |
|         {
 | |
|             "1" => 5,
 | |
|             "2" => 4,
 | |
|             "3" => 3,
 | |
|             "4" => 2,
 | |
|             "5" => 1,
 | |
|             _ => null
 | |
|         };
 | |
| 
 | |
|     private static int? GetFibonacci(int value) =>
 | |
|         value switch
 | |
|         {
 | |
|             9 => 55,
 | |
|             8 => 34,
 | |
|             7 => 21,
 | |
|             6 => 13,
 | |
|             5 => 8,
 | |
|             4 => 5,
 | |
|             3 => 3,
 | |
|             2 => 2,
 | |
|             1 => 1,
 | |
|             _ => null
 | |
|         };
 | |
| 
 | |
| }
 | |
| 
 | |
| [JsonSourceGenerationOptions(WriteIndented = true)]
 | |
| [JsonSerializable(typeof(Notification))]
 | |
| public partial class NotificationSourceGenerationContext : JsonSerializerContext
 | |
| {
 | |
| } |