153 lines
3.3 KiB
C#
153 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
using gehGassiApp.Domain.Common;
|
|
|
|
namespace gehGassiApp.Domain.Pushnotifications
|
|
{
|
|
/// <summary>
|
|
/// Hilfsklasse zum abspeichern der referenz-Info für Server PushNotifications
|
|
/// </summary>
|
|
public class ServerPushNotificationInfo
|
|
{
|
|
/// <summary>
|
|
/// Title der Nachricht
|
|
/// </summary>
|
|
[JsonPropertyName("title")]
|
|
public string Title { get; set; }
|
|
|
|
/// <summary>
|
|
/// Inhalt der Nachricht
|
|
/// </summary>
|
|
[JsonPropertyName("body")]
|
|
public string Body { get; set; }
|
|
|
|
/// <summary>
|
|
/// Daten der Nachricht
|
|
/// </summary>
|
|
[JsonPropertyName("data")]
|
|
public string Data { get; set; }
|
|
|
|
/// <summary>
|
|
/// Typ des Appusers damit man bei jenen die beides sind auch unterscheiden kann
|
|
/// </summary>
|
|
[JsonPropertyName("appMode")]
|
|
[JsonConverter(typeof(AppModeConverter))]
|
|
public AppMode? AppMode { get; set; }
|
|
|
|
/// <summary>
|
|
/// Id des verknüpften Objektes
|
|
/// </summary>
|
|
[JsonPropertyName("key")]
|
|
public string Key { get; set; }
|
|
|
|
/// <summary>
|
|
/// Typ des Objektes das verbunden wurde
|
|
/// </summary>
|
|
[JsonPropertyName("table")]
|
|
public string Table { get; set; }
|
|
|
|
/// <summary>
|
|
/// Typ der Systemnachricht
|
|
/// </summary>
|
|
[JsonPropertyName("type")]
|
|
[JsonConverter(typeof(SystemMessageTypeConverter))]
|
|
public SystemMessageType? Type { get; set; }
|
|
}
|
|
|
|
public class SystemMessageTypeConverter : JsonConverter<SystemMessageType?>
|
|
{
|
|
public override SystemMessageType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
try
|
|
{
|
|
var value = reader.GetInt32();
|
|
return (SystemMessageType)value;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
}
|
|
|
|
try
|
|
{
|
|
var stringVal = reader.GetString();
|
|
if (string.IsNullOrEmpty(stringVal))
|
|
{
|
|
return null;
|
|
}
|
|
var intVal = int.Parse(stringVal);
|
|
return (SystemMessageType)intVal;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, SystemMessageType? value, JsonSerializerOptions options)
|
|
{
|
|
if (value == null)
|
|
{
|
|
writer.WriteNullValue();
|
|
return;
|
|
}
|
|
|
|
var intVal = (int)value;
|
|
writer.WriteNumberValue(intVal);
|
|
}
|
|
}
|
|
|
|
public class AppModeConverter : JsonConverter<AppMode?>
|
|
{
|
|
public override AppMode? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
try
|
|
{
|
|
var value = reader.GetInt32();
|
|
return (AppMode)value;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
}
|
|
|
|
try
|
|
{
|
|
var stringVal = reader.GetString();
|
|
if (string.IsNullOrEmpty(stringVal))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var intVal = int.Parse(stringVal);
|
|
return (AppMode)intVal;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, AppMode? value, JsonSerializerOptions options)
|
|
{
|
|
if (value == null)
|
|
{
|
|
writer.WriteNullValue();
|
|
return;
|
|
}
|
|
|
|
var intVal = (int)value;
|
|
writer.WriteNumberValue(intVal);
|
|
}
|
|
}
|
|
}
|