[后台] 修改api_weather fix problem api of rain, and typhoon with model

This commit is contained in:
dev02 2023-06-01 16:43:39 +08:00
parent 0c6b9e465f
commit 371e80eb89
6 changed files with 167 additions and 585 deletions

View File

@ -200,71 +200,71 @@ namespace Backend.Quartz.Jobs
doc.Load("root/PowerfulRain.xml"); doc.Load("root/PowerfulRain.xml");
var json = JsonConvert.SerializeXmlNode(doc); var json = JsonConvert.SerializeXmlNode(doc);
var haveinfo = json.Split("info"); var haveinfo = json.Split("info");
//if (haveinfo.Length > 2) if (haveinfo.Length > 2)
//{ {
// var observation = RainApi.Welcome.FromJson(json); var observation = RainApi.Welcome.FromJson(json);
// var area = observation.Alert.Info[0].Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault();
// var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'";
// var NeedCallApi = await backendRepository.GetOneAsync<int>(sql); var NeedCallApi = await backendRepository.GetOneAsync<int>(sql);
// Dictionary<string, object> RainAPIdb = new Dictionary<string, object>() Dictionary<string, object> RainAPIdb = new Dictionary<string, object>()
// { {
// { "@msgType", observation.Alert.MsgType}, { "@msgType", observation.Alert.MsgType},
// { "@headline", observation.Alert.Info[0].Headline}, { "@headline", observation.Alert.Info.Headline},
// { "@areaDesc", area}, { "@areaDesc", area},
// { "@onset", observation.Alert.Info[0].Onset}, { "@onset", observation.Alert.Info.Onset},
// { "@expires", observation.Alert.Info[0].Expires}, { "@expires", observation.Alert.Info.Expires},
// { "@created_by", "system"}, { "@created_by", "system"},
// { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
// }; };
// var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain");
// if (NeedCallApi != 0) if (NeedCallApi != 0)
// { {
// var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline);
// if (val < 5) if (val < 5)
// { {
// var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString());
// UpdatedNiagara("api_rain", ReStr, id); UpdatedNiagara("api_rain", ReStr, id);
// } }
// } }
// FolderFunction folderFunction = new FolderFunction(); FolderFunction folderFunction = new FolderFunction();
// folderFunction.DeleteFile("root/PowerfulRain.xml"); folderFunction.DeleteFile("root/PowerfulRain.xml");
// await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain");
//} }
//else else
//{ {
// var observation = RainApi.Welcome.FromJson(json); var observation = RainApi.Welcome.FromJson(json);
// var area = observation.Alert.Info[0].Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault();
// var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; var sql = $"select id from api_rain where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'";
// var NeedCallApi = await backendRepository.GetOneAsync<int>(sql); var NeedCallApi = await backendRepository.GetOneAsync<int>(sql);
// Dictionary<string, object> RainAPIdb = new Dictionary<string, object>() Dictionary<string, object> RainAPIdb = new Dictionary<string, object>()
// { {
// { "@msgType", observation.Alert.MsgType}, { "@msgType", observation.Alert.MsgType},
// { "@headline", observation.Alert.Info[0].Headline}, { "@headline", observation.Alert.Info.Headline},
// { "@areaDesc", area}, { "@areaDesc", area},
// { "@onset", observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}, { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")},
// { "@expires", observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}, { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")},
// { "@created_by", "system"}, { "@created_by", "system"},
// { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
// }; };
// var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain");
// if (NeedCallApi != 0) if (NeedCallApi != 0)
// { {
// var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline);
// if (val < 5) if (val < 5)
// { {
// var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString()); var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET1/SeverityLEVL_RAIN/set", val.ToString());
// UpdatedNiagara("api_rain", ReStr, id); UpdatedNiagara("api_rain", ReStr, id);
// } }
// } }
// FolderFunction folderFunction = new FolderFunction(); FolderFunction folderFunction = new FolderFunction();
// folderFunction.DeleteFile("root/PowerfulRain.xml"); folderFunction.DeleteFile("root/PowerfulRain.xml");
// await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain");
//} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -284,71 +284,71 @@ namespace Backend.Quartz.Jobs
var json = JsonConvert.SerializeXmlNode(doc); var json = JsonConvert.SerializeXmlNode(doc);
var haveinfo = json.Split("info"); var haveinfo = json.Split("info");
//if (haveinfo.Length > 2) if (haveinfo.Length > 2)
//{ {
// var observation = TyphoonApi.Welcome.FromJson(json); var observation = TyphoonApi.Welcome.FromJson(json);
// var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault();
// var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'";
// var NeedCallApi = await backendRepository.GetOneAsync<int>(sql); var NeedCallApi = await backendRepository.GetOneAsync<int>(sql);
// Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>() Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>()
// { {
// { "@msgType", observation.Alert.MsgType}, { "@msgType", observation.Alert.MsgType},
// { "@headline", observation.Alert.Info[0].Headline}, { "@headline", observation.Alert.Info.Headline},
// { "@areaDesc", area}, { "@areaDesc", area},
// { "@urgency",observation.Alert.Info[0].Urgency}, { "@urgency",observation.Alert.Info.Urgency},
// { "@severity",observation.Alert.Info[0].Severity}, { "@severity",observation.Alert.Info.Severity},
// { "@onset", observation.Alert.Info[0].Onset}, { "@onset", observation.Alert.Info.Onset},
// { "@expires", observation.Alert.Info[0].Expires}, { "@expires", observation.Alert.Info.Expires},
// { "@created_by", "system"}, { "@created_by", "system"},
// { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
// }; };
// var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon");
// if (NeedCallApi != 0) if (NeedCallApi != 0)
// { {
// if (observation.Alert.Info[0].Urgency != null && observation.Alert.Info[0].Urgency != "Expected") if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected")
// { {
// var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info[0].Urgency); var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency);
// UpdatedNiagara("api_typhoon", ReStr, id); UpdatedNiagara("api_typhoon", ReStr, id);
// } }
// } }
// FolderFunction folderFunction = new FolderFunction(); FolderFunction folderFunction = new FolderFunction();
// folderFunction.DeleteFile("root/Typhoon.xml"); folderFunction.DeleteFile("root/Typhoon.xml");
// await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon");
//} }
//else else
//{ {
// var observation = TyphoonApi.Welcome.FromJson(json); var observation = TyphoonApi.Welcome.FromJson(json);
// //var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault(); //var area = observation.Alert.Info.Area.Where(a => a.Geocode.Value == "63").Select(a => a.AreaDesc).FirstOrDefault();
// var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'"; var sql = $"select id from api_typhoon where msgType = '{observation.Alert.MsgType}' and onset = '{observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}' and expires = '{observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}'";
// var NeedCallApi = await backendRepository.GetOneAsync<int>(sql); var NeedCallApi = await backendRepository.GetOneAsync<int>(sql);
// Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>() Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>()
// { {
// { "@msgType", observation.Alert.MsgType}, { "@msgType", observation.Alert.MsgType},
// { "@headline", observation.Alert.Info.Headline}, { "@headline", observation.Alert.Info.Headline},
// //{ "@areaDesc", area}, //{ "@areaDesc", area},
// { "@urgency",observation.Alert.Info.Urgency}, { "@urgency",observation.Alert.Info.Urgency},
// { "@severity",observation.Alert.Info.Severity}, { "@severity",observation.Alert.Info.Severity},
// { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")},
// { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")},
// { "@created_by", "system"}, { "@created_by", "system"},
// { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
// }; };
// var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon");
// if (NeedCallApi != 0) if (NeedCallApi != 0)
// { {
// if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected") if (observation.Alert.Info.Urgency != null && observation.Alert.Info.Urgency != "Expected")
// { {
// var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency); var ReStr = Fetch_PostWithJSONFormat($@"{obixApiConfig.ApiBase}obix/config/Arena/D2/CWB/L110/CAP/D2_CWB_L110_CAP_MET2/SeverityLEVL_Typhoon/set", observation.Alert.Info.Urgency);
// UpdatedNiagara("api_typhoon", ReStr, id); UpdatedNiagara("api_typhoon", ReStr, id);
// } }
// } }
// FolderFunction folderFunction = new FolderFunction(); FolderFunction folderFunction = new FolderFunction();
// folderFunction.DeleteFile("root/Typhoon.xml"); folderFunction.DeleteFile("root/Typhoon.xml");
// await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon");
//} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -55,7 +55,7 @@ namespace RainApi
public string References { get; set; } public string References { get; set; }
[JsonProperty("info")] [JsonProperty("info")]
public Info[] Info { get; set; } public Info Info { get; set; }
} }
public partial class Info public partial class Info
@ -69,9 +69,6 @@ namespace RainApi
[JsonProperty("event")] [JsonProperty("event")]
public string Event { get; set; } public string Event { get; set; }
[JsonProperty("responseType")]
public string ResponseType { get; set; }
[JsonProperty("urgency")] [JsonProperty("urgency")]
public string Urgency { get; set; } public string Urgency { get; set; }
@ -102,14 +99,17 @@ namespace RainApi
[JsonProperty("description")] [JsonProperty("description")]
public string Description { get; set; } public string Description { get; set; }
[JsonProperty("instruction")]
public string Instruction { get; set; }
[JsonProperty("web")] [JsonProperty("web")]
public Uri Web { get; set; } public Uri Web { get; set; }
[JsonProperty("parameter")] [JsonProperty("parameter")]
public EventCode[] Parameter { get; set; } public EventCode Parameter { get; set; }
[JsonProperty("area")] [JsonProperty("area")]
public Area[] Area { get; set; } public List<Area> Area { get; set; }
} }
public partial class Area public partial class Area
@ -124,7 +124,7 @@ namespace RainApi
public partial class EventCode public partial class EventCode
{ {
[JsonProperty("valueName")] [JsonProperty("valueName")]
public ValueName ValueName { get; set; } public string ValueName { get; set; }
[JsonProperty("value")] [JsonProperty("value")]
public string Value { get; set; } public string Value { get; set; }
@ -139,7 +139,7 @@ namespace RainApi
public string Encoding { get; set; } public string Encoding { get; set; }
} }
public enum ValueName { AlertColor, AlertTitle, ProfileCapTwpEvent10, SeverityLevel, TaiwanGeocode103, WebsiteColor }; public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode103 };
public partial class Welcome public partial class Welcome
{ {
@ -177,16 +177,10 @@ namespace RainApi
{ {
case "Taiwan_Geocode_103": case "Taiwan_Geocode_103":
return ValueName.TaiwanGeocode103; return ValueName.TaiwanGeocode103;
case "alert_color":
return ValueName.AlertColor;
case "alert_title": case "alert_title":
return ValueName.AlertTitle; return ValueName.AlertTitle;
case "profile:CAP-TWP:Event:1.0": case "profile:CAP-TWP:Event:1.0":
return ValueName.ProfileCapTwpEvent10; return ValueName.ProfileCapTwpEvent10;
case "severity_level":
return ValueName.SeverityLevel;
case "website_color":
return ValueName.WebsiteColor;
} }
throw new Exception("Cannot unmarshal type ValueName"); throw new Exception("Cannot unmarshal type ValueName");
} }
@ -204,21 +198,12 @@ namespace RainApi
case ValueName.TaiwanGeocode103: case ValueName.TaiwanGeocode103:
serializer.Serialize(writer, "Taiwan_Geocode_103"); serializer.Serialize(writer, "Taiwan_Geocode_103");
return; return;
case ValueName.AlertColor:
serializer.Serialize(writer, "alert_color");
return;
case ValueName.AlertTitle: case ValueName.AlertTitle:
serializer.Serialize(writer, "alert_title"); serializer.Serialize(writer, "alert_title");
return; return;
case ValueName.ProfileCapTwpEvent10: case ValueName.ProfileCapTwpEvent10:
serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0"); serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0");
return; 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"); throw new Exception("Cannot marshal type ValueName");
} }

View File

@ -69,9 +69,6 @@ namespace TyphoonApi
[JsonProperty("event")] [JsonProperty("event")]
public string Event { get; set; } public string Event { get; set; }
[JsonProperty("responseType")]
public string ResponseType { get; set; }
[JsonProperty("urgency")] [JsonProperty("urgency")]
public string Urgency { get; set; } public string Urgency { get; set; }
@ -100,16 +97,19 @@ namespace TyphoonApi
public string Headline { get; set; } public string Headline { get; set; }
[JsonProperty("description")] [JsonProperty("description")]
public Description Description { get; set; } public string Description { get; set; }
[JsonProperty("instruction")]
public string Instruction { get; set; }
[JsonProperty("web")] [JsonProperty("web")]
public Uri Web { get; set; } public Uri Web { get; set; }
[JsonProperty("parameter")] [JsonProperty("parameter")]
public EventCode[] Parameter { get; set; } public EventCode Parameter { get; set; }
[JsonProperty("area")] [JsonProperty("area")]
public Area[] Area { get; set; } public List<Area> Area { get; set; }
} }
public partial class Area public partial class Area
@ -117,96 +117,8 @@ namespace TyphoonApi
[JsonProperty("areaDesc")] [JsonProperty("areaDesc")]
public string AreaDesc { get; set; } public string AreaDesc { get; set; }
[JsonProperty("polygon")] [JsonProperty("geocode")]
public string Polygon { get; set; } public EventCode Geocode { get; set; }
}
public partial class Description
{
[JsonProperty("typhoon-info")]
public TyphoonInfo TyphoonInfo { get; set; }
[JsonProperty("section")]
public DescriptionSection[] Section { get; set; }
}
public partial class DescriptionSection
{
[JsonProperty("@title")]
public string Title { get; set; }
[JsonProperty("#text")]
public string Text { get; set; }
}
public partial class TyphoonInfo
{
[JsonProperty("section")]
public TyphoonInfoSection[] Section { get; set; }
}
public partial class TyphoonInfoSection
{
[JsonProperty("@title")]
public string Title { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; }
[JsonProperty("typhoon_name", NullValueHandling = NullValueHandling.Ignore)]
public string TyphoonName { get; set; }
[JsonProperty("cwb_typhoon_name", NullValueHandling = NullValueHandling.Ignore)]
public string CwbTyphoonName { get; set; }
[JsonProperty("analysis", NullValueHandling = NullValueHandling.Ignore)]
public Analysis Analysis { get; set; }
[JsonProperty("prediction", NullValueHandling = NullValueHandling.Ignore)]
public Analysis Prediction { get; set; }
}
public partial class Analysis
{
[JsonProperty("time")]
public DateTimeOffset Time { get; set; }
[JsonProperty("position")]
public string Position { get; set; }
[JsonProperty("max_winds")]
public Gust MaxWinds { get; set; }
[JsonProperty("gust")]
public Gust Gust { get; set; }
[JsonProperty("pressure")]
public Gust Pressure { get; set; }
[JsonProperty("radius_of_15mps")]
public Gust RadiusOf15Mps { get; set; }
[JsonProperty("scale", NullValueHandling = NullValueHandling.Ignore)]
public Scale[] Scale { get; set; }
}
public partial class Gust
{
[JsonProperty("@unit")]
public string Unit { get; set; }
[JsonProperty("#text")]
[JsonConverter(typeof(ParseStringConverter))]
public long Text { get; set; }
}
public partial class Scale
{
[JsonProperty("@lang")]
public string Lang { get; set; }
[JsonProperty("#text")]
public string Text { get; set; }
} }
public partial class EventCode public partial class EventCode
@ -227,6 +139,8 @@ namespace TyphoonApi
public string Encoding { get; set; } public string Encoding { get; set; }
} }
public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode103 };
public partial class Welcome public partial class Welcome
{ {
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, QuickType.Converter.Settings); public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, QuickType.Converter.Settings);
@ -245,25 +159,30 @@ namespace TyphoonApi
DateParseHandling = DateParseHandling.None, DateParseHandling = DateParseHandling.None,
Converters = Converters =
{ {
ValueNameConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
}, },
}; };
} }
internal class ParseStringConverter : JsonConverter internal class ValueNameConverter : JsonConverter
{ {
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?); public override bool CanConvert(Type t) => t == typeof(ValueName) || t == typeof(ValueName?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{ {
if (reader.TokenType == JsonToken.Null) return null; if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader); var value = serializer.Deserialize<string>(reader);
long l; switch (value)
if (Int64.TryParse(value, out l))
{ {
return l; case "Taiwan_Geocode_103":
return ValueName.TaiwanGeocode103;
case "alert_title":
return ValueName.AlertTitle;
case "profile:CAP-TWP:Event:1.0":
return ValueName.ProfileCapTwpEvent10;
} }
throw new Exception("Cannot unmarshal type long"); throw new Exception("Cannot unmarshal type ValueName");
} }
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
@ -273,11 +192,22 @@ namespace TyphoonApi
serializer.Serialize(writer, null); serializer.Serialize(writer, null);
return; return;
} }
var value = (long)untypedValue; var value = (ValueName)untypedValue;
serializer.Serialize(writer, value.ToString()); switch (value)
return; {
case ValueName.TaiwanGeocode103:
serializer.Serialize(writer, "Taiwan_Geocode_103");
return;
case ValueName.AlertTitle:
serializer.Serialize(writer, "alert_title");
return;
case ValueName.ProfileCapTwpEvent10:
serializer.Serialize(writer, "profile:CAP-TWP:Event:1.0");
return;
}
throw new Exception("Cannot marshal type ValueName");
} }
public static readonly ParseStringConverter Singleton = new ParseStringConverter(); public static readonly ValueNameConverter Singleton = new ValueNameConverter();
} }
} }

View File

@ -20,7 +20,7 @@
"RegularUpdateDBTableJob": "0 0 2 * * ?", "RegularUpdateDBTableJob": "0 0 2 * * ?",
"ParkingJob": "0 0 2 * * ?", "ParkingJob": "0 0 2 * * ?",
"ArchiveElectricMeterHourJob": "0 0 2 * * ?", "ArchiveElectricMeterHourJob": "0 0 2 * * ?",
"ArchiveElectricMeterDayJob": "0/5 * * * * ?", "ArchiveElectricMeterDayJob": "0 0 2 * * ?",
"WeatherAPIJob": "0/5 * * * * ?" "WeatherAPIJob": "0/5 * * * * ?"
}, },
"DBConfig": { "DBConfig": {

View File

@ -1,136 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
<identifier>CWB-Weather_extremely-rain_202306011035001</identifier>
<sender>weather@cwb.gov.tw</sender>
<sent>2023-06-01T10:43:55+08:00</sent>
<status>Actual</status>
<msgType>Update</msgType>
<scope>Public</scope>
<references>weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306010655001,2023-06-01T07:02:17+08:00 weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306010345001,2023-06-01T03:56:19+08:00</references>
<info>
<language>zh-TW</language>
<category>Met</category>
<event>降雨</event>
<responseType>Monitor</responseType>
<urgency>Future</urgency>
<severity>Moderate</severity>
<certainty>Likely</certainty>
<eventCode>
<valueName>profile:CAP-TWP:Event:1.0</valueName>
<value>rainfall</value>
</eventCode>
<effective>2023-06-01T10:35:00+08:00</effective>
<onset>2023-06-01T10:36:00+08:00</onset>
<expires>2023-06-01T23:00:00+08:00</expires>
<senderName>中央氣象局</senderName>
<headline>大雨特報</headline>
<description>
颱風外圍環流影響,今(1)日新竹以北及宜蘭山區有局部大雨發生的機率,請注意瞬間大雨,山區請慎防坍方及落石。
</description>
<web>https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html</web>
<parameter>
<valueName>alert_title</valueName>
<value>大雨特報</value>
</parameter>
<parameter>
<valueName>severity_level</valueName>
<value>大雨</value>
</parameter>
<parameter>
<valueName>alert_color</valueName>
<value>黃色</value>
</parameter>
<parameter>
<valueName>website_color</valueName>
<value>255,255,0</value>
</parameter>
<area>
<areaDesc>新竹縣橫山鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000408</value>
</geocode>
</area><area>
<areaDesc>新竹縣北埔鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000409</value>
</geocode>
</area><area>
<areaDesc>桃園市復興區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6801300</value>
</geocode>
</area><area>
<areaDesc>臺北市士林區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6301100</value>
</geocode>
</area><area>
<areaDesc>新北市三峽區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6500900</value>
</geocode>
</area><area>
<areaDesc>新北市石碇區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6501900</value>
</geocode>
</area><area>
<areaDesc>臺北市北投區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6301200</value>
</geocode>
</area><area>
<areaDesc>新竹縣五峰鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000413</value>
</geocode>
</area><area>
<areaDesc>新竹縣尖石鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000412</value>
</geocode>
</area><area>
<areaDesc>新北市烏來區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6502900</value>
</geocode>
</area><area>
<areaDesc>新北市坪林區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6502000</value>
</geocode>
</area><area>
<areaDesc>新北市平溪區</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>6502400</value>
</geocode>
</area><area>
<areaDesc>宜蘭縣南澳鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000212</value>
</geocode>
</area><area>
<areaDesc>宜蘭縣大同鄉</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>1000211</value>
</geocode>
</area>
</info>
</alert>

View File

@ -1,197 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
<identifier>CWB-Weather_typhoon-warning_202305311730001</identifier>
<sender>weather@cwb.gov.tw</sender>
<sent>2023-05-31T17:17:30+08:00</sent>
<status>Actual</status>
<msgType>Cancel</msgType>
<scope>Public</scope>
<references>weather@cwb.gov.tw,CWB-Weather_typhoon-warning_202305311430001,2023-05-31T14:22:23+08:00</references>
<info>
<language>zh-TW</language>
<category>Met</category>
<event>颱風</event>
<urgency>Past</urgency>
<severity>Minor</severity>
<certainty>Observed</certainty>
<eventCode>
<valueName>profile:CAP-TWP:Event:1.0</valueName>
<value>typhoon</value>
</eventCode>
<effective>2023-05-31T17:30:00+08:00</effective>
<onset>2023-05-31T17:30:00+08:00</onset>
<expires>2023-05-31T17:40:00+08:00</expires>
<senderName>中央氣象局</senderName>
<headline>解除颱風警報</headline>
<description>
[颱風動態]
根據最新資料顯示第2號颱風暴風半徑略為縮小中心目前在鵝鑾鼻東北東方海面向北北東轉東北移動對巴士海峽及臺灣東半部近海威脅已解除。
[注意事項]
*巴士海峽及臺灣附近各海面風浪明顯偏大;基隆北海岸、南部、東半部(含蘭嶼、綠島)、恆春半島沿海及澎湖、馬祖易有長浪發生,尤其東半部(含蘭嶼、綠島)、基隆北海岸、恆春半島沿海易有4至5米浪高請避免前往海邊活動。陸上強風特報今(31)日臺南至苗栗沿海空曠地區及澎湖、蘭嶼、綠島易有9至10級強陣風新竹以北、基隆北海岸、東半部沿海空曠地區、臺南至苗栗地區、恆春半島、金門、馬祖亦有較強陣風請特別注意。30日0時至31日17時出現較大累積雨量如下宜蘭縣翠峰湖334.5毫米臺中市南湖圈谷257.0毫米。本警報單之颱風半徑為平均半徑第2號颱風之7級風暴風半徑近似正圓平均半徑約為280公里。颱風詳細特性請參考本局颱輔助說明(https://www.cwb.gov.tw/Data/typhoon/TY_PDF.pdf)。此為第2號颱風警報最後一次報告。
</description>
<instruction></instruction>
<web>https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html</web>
<parameter>
<valueName>alert_title</valueName>
<value>颱風警報</value>
</parameter>
<area>
<areaDesc>基隆市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10017</value>
</geocode>
</area>
<area>
<areaDesc>臺北市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>63</value>
</geocode>
</area>
<area>
<areaDesc>新北市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>65</value>
</geocode>
</area>
<area>
<areaDesc>桃園市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>68</value>
</geocode>
</area>
<area>
<areaDesc>新竹市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10018</value>
</geocode>
</area>
<area>
<areaDesc>新竹縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10004</value>
</geocode>
</area>
<area>
<areaDesc>苗栗縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10005</value>
</geocode>
</area>
<area>
<areaDesc>臺中市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>66</value>
</geocode>
</area>
<area>
<areaDesc>彰化縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10007</value>
</geocode>
</area>
<area>
<areaDesc>雲林縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10009</value>
</geocode>
</area>
<area>
<areaDesc>南投縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10008</value>
</geocode>
</area>
<area>
<areaDesc>嘉義縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10010</value>
</geocode>
</area>
<area>
<areaDesc>嘉義市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10020</value>
</geocode>
</area>
<area>
<areaDesc>臺南市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>67</value>
</geocode>
</area>
<area>
<areaDesc>高雄市</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>64</value>
</geocode>
</area>
<area>
<areaDesc>屏東縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10013</value>
</geocode>
</area>
<area>
<areaDesc>宜蘭縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10002</value>
</geocode>
</area>
<area>
<areaDesc>花蓮縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10015</value>
</geocode>
</area>
<area>
<areaDesc>臺東縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10014</value>
</geocode>
</area>
<area>
<areaDesc>澎湖縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>10016</value>
</geocode>
</area>
<area>
<areaDesc>金門縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>09020</value>
</geocode>
</area>
<area>
<areaDesc>連江縣</areaDesc>
<geocode>
<valueName>Taiwan_Geocode_103</valueName>
<value>09007</value>
</geocode>
</area>
</info>
</alert>