ibms-dome/BackendWorkerService/Services/Implement/RainApi.cs

229 lines
6.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var welcome = Welcome.FromJson(jsonString);
namespace RainApi
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class Welcome
{
[JsonProperty("?xml")]
public Xml Xml { get; set; }
[JsonProperty("alert")]
public Alert Alert { get; set; }
}
public partial class Alert
{
[JsonProperty("@xmlns")]
public string Xmlns { get; set; }
[JsonProperty("identifier")]
public string Identifier { get; set; }
[JsonProperty("sender")]
public string Sender { get; set; }
[JsonProperty("sent")]
public DateTimeOffset Sent { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("msgType")]
public string MsgType { get; set; }
[JsonProperty("scope")]
public string Scope { get; set; }
[JsonProperty("references")]
public string References { get; set; }
[JsonProperty("info")]
public Info[] Info { get; set; }
}
public partial class Info
{
[JsonProperty("language")]
public string Language { get; set; }
[JsonProperty("category")]
public string Category { get; set; }
[JsonProperty("event")]
public string Event { get; set; }
[JsonProperty("responseType")]
public string ResponseType { get; set; }
[JsonProperty("urgency")]
public string Urgency { get; set; }
[JsonProperty("severity")]
public string Severity { get; set; }
[JsonProperty("certainty")]
public string Certainty { get; set; }
[JsonProperty("eventCode")]
public EventCode EventCode { get; set; }
[JsonProperty("effective")]
public DateTimeOffset Effective { get; set; }
[JsonProperty("onset")]
public DateTimeOffset Onset { get; set; }
[JsonProperty("expires")]
public DateTimeOffset Expires { get; set; }
[JsonProperty("senderName")]
public string SenderName { get; set; }
[JsonProperty("headline")]
public string Headline { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("web")]
public Uri Web { get; set; }
[JsonProperty("parameter")]
public EventCode[] Parameter { get; set; }
[JsonProperty("area")]
public Area[] Area { get; set; }
}
public partial class Area
{
[JsonProperty("areaDesc")]
public string AreaDesc { get; set; }
[JsonProperty("geocode")]
public EventCode Geocode { get; set; }
}
public partial class EventCode
{
[JsonProperty("valueName")]
public ValueName ValueName { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
public partial class Xml
{
[JsonProperty("@version")]
public string Version { get; set; }
[JsonProperty("@encoding")]
public string Encoding { get; set; }
}
public enum ValueName { AlertColor, AlertTitle, ProfileCapTwpEvent10, SeverityLevel, TaiwanGeocode103, WebsiteColor };
public partial class Welcome
{
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
ValueNameConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ValueNameConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(ValueName) || t == typeof(ValueName?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
switch (value)
{
case "Taiwan_Geocode_103":
return ValueName.TaiwanGeocode103;
case "alert_color":
return ValueName.AlertColor;
case "alert_title":
return ValueName.AlertTitle;
case "profile:CAP-TWP:Event:1.0":
return ValueName.ProfileCapTwpEvent10;
case "severity_level":
return ValueName.SeverityLevel;
case "website_color":
return ValueName.WebsiteColor;
}
throw new Exception("Cannot unmarshal type ValueName");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (ValueName)untypedValue;
switch (value)
{
case ValueName.TaiwanGeocode103:
serializer.Serialize(writer, "Taiwan_Geocode_103");
return;
case ValueName.AlertColor:
serializer.Serialize(writer, "alert_color");
return;
case ValueName.AlertTitle:
serializer.Serialize(writer, "alert_title");
return;
case ValueName.ProfileCapTwpEvent10:
serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0");
return;
case ValueName.SeverityLevel:
serializer.Serialize(writer, "severity_level");
return;
case ValueName.WebsiteColor:
serializer.Serialize(writer, "website_color");
return;
}
throw new Exception("Cannot marshal type ValueName");
}
public static readonly ValueNameConverter Singleton = new ValueNameConverter();
}
}