[後端] 修改後台拍成程序

This commit is contained in:
dev02 2023-11-16 17:00:10 +08:00
parent 8417a9ed62
commit 0c27f39fcb
9 changed files with 173 additions and 1357 deletions

View File

@ -128,12 +128,12 @@ namespace BackendWorkerService
); );
#endregion #endregion
#region ( ) //#region 電錶歸檔(設定每 小時 執行一次)
services.AddSingleton<ArchiveElectricMeterHourJob>(); //services.AddSingleton<ArchiveElectricMeterHourJob>();
services.AddSingleton( //services.AddSingleton(
new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ArchiveElectricMeterHourJob")) //new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue<string>("BackgroundServiceCron:ArchiveElectricMeterHourJob"))
); //);
#endregion //#endregion
#region ( ) #region ( )
services.AddSingleton<ArchiveElectricMeterDayJob>(); services.AddSingleton<ArchiveElectricMeterDayJob>();

View File

@ -118,13 +118,13 @@ namespace BackendWorkerService.Quartz
/// <param name="task"></param> /// <param name="task"></param>
/// <param name="task_item"></param> /// <param name="task_item"></param>
/// <returns></returns> /// <returns></returns>
public async Task InsertWorkTime(string task, string task_item ,string LoggerWord = null) public async Task InsertWorkTime(string task, string task_item ,string LoggerWord = null, DateTime? dateTime = null)
{ {
try try
{ {
Dictionary<string, object> worktime = new Dictionary<string, object>() Dictionary<string, object> worktime = new Dictionary<string, object>()
{ {
{ "@lastwork_time", DateTime.Now}, { "@lastwork_time", dateTime ?? DateTime.Now},
{ "@success", 2}, { "@success", 2},
{ "@updated_at", DateTime.Now}, { "@updated_at", DateTime.Now},
}; };

View File

@ -17,6 +17,8 @@ using System.Xml.Serialization;
using System.Linq; using System.Linq;
using NCrontab; using NCrontab;
using BackendWorkerService.Services.Implement; using BackendWorkerService.Services.Implement;
using RainApi;
using System.Globalization;
namespace BackendWorkerService.Quartz.Jobs namespace BackendWorkerService.Quartz.Jobs
{ {
@ -200,71 +202,71 @@ namespace BackendWorkerService.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 = JsonConvert.DeserializeObject<RainApi.Welcome>(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 = JsonConvert.DeserializeObject<RainApi.Welcome>(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)
{ {
@ -276,79 +278,80 @@ namespace BackendWorkerService.Quartz.Jobs
{ {
try try
{ {
await task_Detail.InsertWorkTime("WeatherAPI", "api_typhoon"); await task_Detail.InsertWorkTime("WeatherAPI", "api_typhoon", null , new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day, 0, 25, 0));
WebClient mywebClient = new WebClient(); WebClient mywebClient = new WebClient();
mywebClient.DownloadFile("https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/W-C0034-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&downloadType=WEB&format=CAP", @"root/Typhoon.xml"); mywebClient.DownloadFile("https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/W-C0034-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&downloadType=WEB&format=CAP", @"root/Typhoon.xml");
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
doc.Load("root/Typhoon.xml"); doc.Load("root/Typhoon.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 = TyphoonApi.Welcome.FromJson(json); var observation = JsonConvert.DeserializeObject<TyphoonApi.Welcome>(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.ToString("yyyy-MM-dd HH:mm:ss")},
// { "@expires", observation.Alert.Info[0].Expires}, { "@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[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 = JsonConvert.DeserializeObject<TyphoonApi.Welcome>(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)
@ -356,16 +359,18 @@ namespace BackendWorkerService.Quartz.Jobs
await task_Detail.WorkFail("WeatherAPI", "api_typhoon", ex.Message.ToString()); await task_Detail.WorkFail("WeatherAPI", "api_typhoon", ex.Message.ToString());
} }
} }
if (await task_Detail.GetNeedWorkTask("WeatherAPI", "api_earthquake")) if (await task_Detail.GetNeedWorkTask("WeatherAPI", "api_earthquake"))
{ {
try try
{ {
await task_Detail.InsertWorkTime("WeatherAPI", "api_earthquake"); await task_Detail.InsertWorkTime("WeatherAPI", "api_earthquake", null, new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day, 0, 25, 0));
var client = new HttpClient(); var client = new HttpClient();
var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/E-A0015-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&format=JSON&areaName=%E8%87%BA%E5%8C%97%E5%B8%82"; var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/E-A0015-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&format=JSON&areaName=%E8%87%BA%E5%8C%97%E5%B8%82";
HttpResponseMessage response = client.GetAsync(UVUri).Result; HttpResponseMessage response = client.GetAsync(UVUri).Result;
String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
var observation = QuickType.Welcome.FromJson(jsonUVs); var j = JsonConvert.DeserializeObject(jsonUVs);
var observation = JsonConvert.DeserializeObject<QuickType.Welcome>(jsonUVs);
if (!observation.Success) if (!observation.Success)
{ {
logger.LogInformation("【WeatherAPIJob】【取得地震觀測資料不正確】"); logger.LogInformation("【WeatherAPIJob】【取得地震觀測資料不正確】");
@ -395,7 +400,7 @@ namespace BackendWorkerService.Quartz.Jobs
} }
else else
{ {
if (a.Intensity.ShakingArea.Length > 0) if (a.Intensity.ShakingArea.Count > 0)
{ {
Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>() Dictionary<string, object> EarthquakeAPIdb = new Dictionary<string, object>()
{ {
@ -460,6 +465,7 @@ namespace BackendWorkerService.Quartz.Jobs
await task_Detail.WorkFail("WeatherAPI", "api_earthquake", ex.Message.ToString()); await task_Detail.WorkFail("WeatherAPI", "api_earthquake", ex.Message.ToString());
} }
} }
if (await task_Detail.GetNeedWorkTask("WeatherAPI", "set_weather")) if (await task_Detail.GetNeedWorkTask("WeatherAPI", "set_weather"))
{ {
try try

View File

@ -21,191 +21,100 @@ namespace QuickType
public partial class Welcome public partial class Welcome
{ {
[JsonProperty("success")]
[JsonConverter(typeof(ParseStringConverter))]
public bool Success { get; set; } public bool Success { get; set; }
[JsonProperty("result")]
public Result Result { get; set; } public Result Result { get; set; }
[JsonProperty("records")]
public Records Records { get; set; } public Records Records { get; set; }
} }
public partial class Records public partial class Records
{ {
[JsonProperty("datasetDescription")]
public DatasetDescription DatasetDescription { get; set; } public DatasetDescription DatasetDescription { get; set; }
public List<Earthquake> Earthquake { get; set; }
[JsonProperty("Earthquake")]
public Earthquake[] Earthquake { get; set; }
} }
public partial class Earthquake public partial class Earthquake
{ {
[JsonProperty("EarthquakeNo")]
public long EarthquakeNo { get; set; } public long EarthquakeNo { get; set; }
[JsonProperty("ReportType")]
public DatasetDescription ReportType { get; set; } public DatasetDescription ReportType { get; set; }
[JsonProperty("ReportColor")]
public ReportColor ReportColor { get; set; } public ReportColor ReportColor { get; set; }
[JsonProperty("ReportContent")]
public string ReportContent { get; set; } public string ReportContent { get; set; }
[JsonProperty("ReportImageURI")]
public Uri ReportImageUri { get; set; } public Uri ReportImageUri { get; set; }
public string ReportRemark { get; set; }
[JsonProperty("ReportRemark")]
public ReportRemark ReportRemark { get; set; }
[JsonProperty("Web")]
public Uri Web { get; set; } public Uri Web { get; set; }
[JsonProperty("ShakemapImageURI")]
public Uri ShakemapImageUri { get; set; } public Uri ShakemapImageUri { get; set; }
[JsonProperty("EarthquakeInfo")]
public EarthquakeInfo EarthquakeInfo { get; set; } public EarthquakeInfo EarthquakeInfo { get; set; }
[JsonProperty("Intensity")]
public Intensity Intensity { get; set; } public Intensity Intensity { get; set; }
} }
public partial class EarthquakeInfo public partial class EarthquakeInfo
{ {
[JsonProperty("OriginTime")]
public DateTimeOffset OriginTime { get; set; } public DateTimeOffset OriginTime { get; set; }
[JsonProperty("Source")]
public Source Source { get; set; } public Source Source { get; set; }
[JsonProperty("FocalDepth")]
public double FocalDepth { get; set; } public double FocalDepth { get; set; }
[JsonProperty("Epicenter")]
public Epicenter Epicenter { get; set; } public Epicenter Epicenter { get; set; }
[JsonProperty("EarthquakeMagnitude")]
public EarthquakeMagnitude EarthquakeMagnitude { get; set; } public EarthquakeMagnitude EarthquakeMagnitude { get; set; }
} }
public partial class EarthquakeMagnitude public partial class EarthquakeMagnitude
{ {
[JsonProperty("MagnitudeType")]
public MagnitudeType MagnitudeType { get; set; } public MagnitudeType MagnitudeType { get; set; }
[JsonProperty("MagnitudeValue")]
public double MagnitudeValue { get; set; } public double MagnitudeValue { get; set; }
} }
public partial class Epicenter public partial class Epicenter
{ {
[JsonProperty("Location")]
public string Location { get; set; } public string Location { get; set; }
[JsonProperty("EpicenterLatitude")]
public double EpicenterLatitude { get; set; } public double EpicenterLatitude { get; set; }
[JsonProperty("EpicenterLongitude")]
public double EpicenterLongitude { get; set; } public double EpicenterLongitude { get; set; }
} }
public partial class Intensity public partial class Intensity
{ {
[JsonProperty("ShakingArea")] public List<ShakingArea> ShakingArea { get; set; }
public ShakingArea[] ShakingArea { get; set; }
} }
public partial class ShakingArea public partial class ShakingArea
{ {
[JsonProperty("AreaDesc")]
public string AreaDesc { get; set; } public string AreaDesc { get; set; }
[JsonProperty("CountyName")]
public string CountyName { get; set; } public string CountyName { get; set; }
[JsonProperty("InfoStatus", NullValueHandling = NullValueHandling.Ignore)]
public InfoStatus? InfoStatus { get; set; } public InfoStatus? InfoStatus { get; set; }
public string AreaIntensity { get; set; }
[JsonProperty("AreaIntensity")] public List<EqStation> EqStation { get; set; }
public AreaIntensityEnum AreaIntensity { get; set; }
[JsonProperty("EqStation")]
public EqStation[] EqStation { get; set; }
} }
public partial class EqStation public partial class EqStation
{ {
[JsonProperty("pga", NullValueHandling = NullValueHandling.Ignore)]
public Pga Pga { get; set; } public Pga Pga { get; set; }
[JsonProperty("pgv", NullValueHandling = NullValueHandling.Ignore)]
public Pga Pgv { get; set; } public Pga Pgv { get; set; }
[JsonProperty("StationName")]
public string StationName { get; set; } public string StationName { get; set; }
[JsonProperty("StationID")]
public string StationId { get; set; } public string StationId { get; set; }
[JsonProperty("InfoStatus", NullValueHandling = NullValueHandling.Ignore)]
public InfoStatus? InfoStatus { get; set; } public InfoStatus? InfoStatus { get; set; }
[JsonProperty("BackAzimuth")]
public double BackAzimuth { get; set; } public double BackAzimuth { get; set; }
[JsonProperty("EpicenterDistance")]
public double EpicenterDistance { get; set; } public double EpicenterDistance { get; set; }
public string SeismicIntensity { get; set; }
[JsonProperty("SeismicIntensity")]
public AreaIntensityEnum SeismicIntensity { get; set; }
[JsonProperty("StationLatitude")]
public double StationLatitude { get; set; } public double StationLatitude { get; set; }
[JsonProperty("StationLongitude")]
public double StationLongitude { get; set; } public double StationLongitude { get; set; }
[JsonProperty("WaveImageURI", NullValueHandling = NullValueHandling.Ignore)]
public Uri WaveImageUri { get; set; } public Uri WaveImageUri { get; set; }
} }
public partial class Pga public partial class Pga
{ {
[JsonProperty("unit")]
public Unit Unit { get; set; } public Unit Unit { get; set; }
[JsonProperty("EWComponent")]
public double EwComponent { get; set; } public double EwComponent { get; set; }
[JsonProperty("NSComponent")]
public double NsComponent { get; set; } public double NsComponent { get; set; }
[JsonProperty("VComponent")]
public double VComponent { get; set; } public double VComponent { get; set; }
[JsonProperty("IntScaleValue")]
public double IntScaleValue { get; set; } public double IntScaleValue { get; set; }
} }
public partial class Result public partial class Result
{ {
[JsonProperty("resource_id")]
public string ResourceId { get; set; } public string ResourceId { get; set; }
public List<Field> Fields { get; set; }
[JsonProperty("fields")]
public Field[] Fields { get; set; }
} }
public partial class Field public partial class Field
{ {
[JsonProperty("id")]
public string Id { get; set; } public string Id { get; set; }
[JsonProperty("type")]
public TypeEnum Type { get; set; } public TypeEnum Type { get; set; }
} }
@ -213,428 +122,18 @@ namespace QuickType
public enum MagnitudeType { }; public enum MagnitudeType { };
public enum Source { }; public enum Source { , };
public enum AreaIntensityEnum { The1級, The2級, The3級, The4級 }; public enum AreaIntensityEnum { The1級, The2級, The3級, The4級, The5弱 };
public enum InfoStatus { Observe }; public enum InfoStatus { Observe };
public enum Unit { Gal, Kine }; public enum Unit { Gal, Kine };
public enum ReportColor { }; public enum ReportColor { , };
public enum ReportRemark { }; public enum ReportRemark { , };
public enum TypeEnum { Float, Integer, String, Timestamp }; public enum TypeEnum { Float, Integer, String, Timestamp };
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 =
{
MagnitudeTypeConverter.Singleton,
SourceConverter.Singleton,
AreaIntensityEnumConverter.Singleton,
InfoStatusConverter.Singleton,
UnitConverter.Singleton,
ReportColorConverter.Singleton,
ReportRemarkConverter.Singleton,
DatasetDescriptionConverter.Singleton,
TypeEnumConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class MagnitudeTypeConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(MagnitudeType) || t == typeof(MagnitudeType?);
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);
if (value == "芮氏規模")
{
return MagnitudeType.;
}
throw new Exception("Cannot unmarshal type MagnitudeType");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (MagnitudeType)untypedValue;
if (value == MagnitudeType.)
{
serializer.Serialize(writer, "芮氏規模");
return;
}
throw new Exception("Cannot marshal type MagnitudeType");
}
public static readonly MagnitudeTypeConverter Singleton = new MagnitudeTypeConverter();
}
internal class SourceConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(Source) || t == typeof(Source?);
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);
if (value == "中央氣象局")
{
return Source.;
}
throw new Exception("Cannot unmarshal type Source");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (Source)untypedValue;
if (value == Source.)
{
serializer.Serialize(writer, "中央氣象局");
return;
}
throw new Exception("Cannot marshal type Source");
}
public static readonly SourceConverter Singleton = new SourceConverter();
}
internal class AreaIntensityEnumConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(AreaIntensityEnum) || t == typeof(AreaIntensityEnum?);
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 "1級":
return AreaIntensityEnum.The1級;
case "2級":
return AreaIntensityEnum.The2級;
case "3級":
return AreaIntensityEnum.The3級;
case "4級":
return AreaIntensityEnum.The4級;
}
throw new Exception("Cannot unmarshal type AreaIntensityEnum");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (AreaIntensityEnum)untypedValue;
switch (value)
{
case AreaIntensityEnum.The1級:
serializer.Serialize(writer, "1級");
return;
case AreaIntensityEnum.The2級:
serializer.Serialize(writer, "2級");
return;
case AreaIntensityEnum.The3級:
serializer.Serialize(writer, "3級");
return;
case AreaIntensityEnum.The4級:
serializer.Serialize(writer, "4級");
return;
}
throw new Exception("Cannot marshal type AreaIntensityEnum");
}
public static readonly AreaIntensityEnumConverter Singleton = new AreaIntensityEnumConverter();
}
internal class InfoStatusConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(InfoStatus) || t == typeof(InfoStatus?);
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);
if (value == "observe")
{
return InfoStatus.Observe;
}
throw new Exception("Cannot unmarshal type InfoStatus");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (InfoStatus)untypedValue;
if (value == InfoStatus.Observe)
{
serializer.Serialize(writer, "observe");
return;
}
throw new Exception("Cannot marshal type InfoStatus");
}
public static readonly InfoStatusConverter Singleton = new InfoStatusConverter();
}
internal class UnitConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(Unit) || t == typeof(Unit?);
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 "gal":
return Unit.Gal;
case "kine":
return Unit.Kine;
}
throw new Exception("Cannot unmarshal type Unit");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (Unit)untypedValue;
switch (value)
{
case Unit.Gal:
serializer.Serialize(writer, "gal");
return;
case Unit.Kine:
serializer.Serialize(writer, "kine");
return;
}
throw new Exception("Cannot marshal type Unit");
}
public static readonly UnitConverter Singleton = new UnitConverter();
}
internal class ReportColorConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(ReportColor) || t == typeof(ReportColor?);
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);
if (value == "綠色")
{
return ReportColor.;
}
throw new Exception("Cannot unmarshal type ReportColor");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (ReportColor)untypedValue;
if (value == ReportColor.)
{
serializer.Serialize(writer, "綠色");
return;
}
throw new Exception("Cannot marshal type ReportColor");
}
public static readonly ReportColorConverter Singleton = new ReportColorConverter();
}
internal class ReportRemarkConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(ReportRemark) || t == typeof(ReportRemark?);
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);
if (value == "本報告係中央氣象局地震觀測網即時地震資料地震速報之結果。")
{
return ReportRemark.;
}
throw new Exception("Cannot unmarshal type ReportRemark");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (ReportRemark)untypedValue;
if (value == ReportRemark.)
{
serializer.Serialize(writer, "本報告係中央氣象局地震觀測網即時地震資料地震速報之結果。");
return;
}
throw new Exception("Cannot marshal type ReportRemark");
}
public static readonly ReportRemarkConverter Singleton = new ReportRemarkConverter();
}
internal class DatasetDescriptionConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(DatasetDescription) || t == typeof(DatasetDescription?);
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);
if (value == "地震報告")
{
return DatasetDescription.;
}
throw new Exception("Cannot unmarshal type DatasetDescription");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (DatasetDescription)untypedValue;
if (value == DatasetDescription.)
{
serializer.Serialize(writer, "地震報告");
return;
}
throw new Exception("Cannot marshal type DatasetDescription");
}
public static readonly DatasetDescriptionConverter Singleton = new DatasetDescriptionConverter();
}
internal class TypeEnumConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(TypeEnum) || t == typeof(TypeEnum?);
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 "Float":
return TypeEnum.Float;
case "Integer":
return TypeEnum.Integer;
case "String":
return TypeEnum.String;
case "Timestamp":
return TypeEnum.Timestamp;
}
throw new Exception("Cannot unmarshal type TypeEnum");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (TypeEnum)untypedValue;
switch (value)
{
case TypeEnum.Float:
serializer.Serialize(writer, "Float");
return;
case TypeEnum.Integer:
serializer.Serialize(writer, "Integer");
return;
case TypeEnum.String:
serializer.Serialize(writer, "String");
return;
case TypeEnum.Timestamp:
serializer.Serialize(writer, "Timestamp");
return;
}
throw new Exception("Cannot marshal type TypeEnum");
}
public static readonly TypeEnumConverter Singleton = new TypeEnumConverter();
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(bool) || t == typeof(bool?);
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);
bool b;
if (Boolean.TryParse(value, out b))
{
return b;
}
throw new Exception("Cannot unmarshal type bool");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (bool)untypedValue;
var boolString = value ? "true" : "false";
serializer.Serialize(writer, boolString);
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
} }

View File

@ -21,208 +21,61 @@ namespace RainApi
public partial class Welcome public partial class Welcome
{ {
[JsonProperty("?xml")]
public Xml Xml { get; set; } public Xml Xml { get; set; }
[JsonProperty("alert")]
public Alert Alert { get; set; } public Alert Alert { get; set; }
} }
public partial class Alert public partial class Alert
{ {
[JsonProperty("@xmlns")]
public string Xmlns { get; set; } public string Xmlns { get; set; }
[JsonProperty("identifier")]
public string Identifier { get; set; } public string Identifier { get; set; }
[JsonProperty("sender")]
public string Sender { get; set; } public string Sender { get; set; }
[JsonProperty("sent")]
public DateTimeOffset Sent { get; set; } public DateTimeOffset Sent { get; set; }
[JsonProperty("status")]
public string Status { get; set; } public string Status { get; set; }
[JsonProperty("msgType")]
public string MsgType { get; set; } public string MsgType { get; set; }
[JsonProperty("scope")]
public string Scope { get; set; } public string Scope { get; set; }
[JsonProperty("references")]
public string References { get; set; } public string References { get; set; }
public Info Info { get; set; }
[JsonProperty("info")]
public Info[] Info { get; set; }
} }
public partial class Info public partial class Info
{ {
[JsonProperty("language")]
public string Language { get; set; } public string Language { get; set; }
[JsonProperty("category")]
public string Category { get; set; } public string Category { get; set; }
[JsonProperty("event")]
public string Event { get; set; } public string Event { get; set; }
[JsonProperty("responseType")]
public string ResponseType { get; set; }
[JsonProperty("urgency")]
public string Urgency { get; set; } public string Urgency { get; set; }
[JsonProperty("severity")]
public string Severity { get; set; } public string Severity { get; set; }
[JsonProperty("certainty")]
public string Certainty { get; set; } public string Certainty { get; set; }
[JsonProperty("eventCode")]
public EventCode EventCode { get; set; } public EventCode EventCode { get; set; }
[JsonProperty("effective")]
public DateTimeOffset Effective { get; set; } public DateTimeOffset Effective { get; set; }
[JsonProperty("onset")]
public DateTimeOffset Onset { get; set; } public DateTimeOffset Onset { get; set; }
[JsonProperty("expires")]
public DateTimeOffset Expires { get; set; } public DateTimeOffset Expires { get; set; }
[JsonProperty("senderName")]
public string SenderName { get; set; } public string SenderName { get; set; }
[JsonProperty("headline")]
public string Headline { get; set; } public string Headline { get; set; }
[JsonProperty("description")]
public string Description { get; set; } public string Description { get; set; }
public string Instruction { get; set; }
[JsonProperty("web")]
public Uri Web { get; set; } public Uri Web { get; set; }
public EventCode Parameter { get; set; }
[JsonProperty("parameter")] public List<Area> Area { get; set; }
public EventCode[] Parameter { get; set; }
[JsonProperty("area")]
public Area[] Area { get; set; }
} }
public partial class Area public partial class Area
{ {
[JsonProperty("areaDesc")]
public string AreaDesc { get; set; } public string AreaDesc { get; set; }
[JsonProperty("geocode")]
public EventCode Geocode { get; set; } public EventCode Geocode { get; set; }
} }
public partial class EventCode public partial class EventCode
{ {
[JsonProperty("valueName")] public string ValueName { get; set; }
public ValueName ValueName { get; set; }
[JsonProperty("value")]
public string Value { get; set; } public string Value { get; set; }
} }
public partial class Xml public partial class Xml
{ {
[JsonProperty("@version")]
public string Version { get; set; } public string Version { get; set; }
[JsonProperty("@encoding")]
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 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();
}
} }

View File

@ -21,263 +21,110 @@ namespace TyphoonApi
public partial class Welcome public partial class Welcome
{ {
[JsonProperty("?xml")]
public Xml Xml { get; set; } public Xml Xml { get; set; }
[JsonProperty("alert")]
public Alert Alert { get; set; } public Alert Alert { get; set; }
} }
public partial class Alert public partial class Alert
{ {
[JsonProperty("@xmlns")]
public string Xmlns { get; set; } public string Xmlns { get; set; }
[JsonProperty("identifier")]
public string Identifier { get; set; } public string Identifier { get; set; }
[JsonProperty("sender")]
public string Sender { get; set; } public string Sender { get; set; }
[JsonProperty("sent")]
public DateTimeOffset Sent { get; set; } public DateTimeOffset Sent { get; set; }
[JsonProperty("status")]
public string Status { get; set; } public string Status { get; set; }
[JsonProperty("msgType")]
public string MsgType { get; set; } public string MsgType { get; set; }
[JsonProperty("scope")]
public string Scope { get; set; } public string Scope { get; set; }
[JsonProperty("references")]
public string References { get; set; } public string References { get; set; }
[JsonProperty("info")]
public Info Info { get; set; } public Info Info { get; set; }
} }
public partial class Info public partial class Info
{ {
[JsonProperty("language")]
public string Language { get; set; } public string Language { get; set; }
[JsonProperty("category")]
public string Category { get; set; } public string Category { get; set; }
[JsonProperty("event")]
public string Event { get; set; } public string Event { get; set; }
[JsonProperty("responseType")]
public string ResponseType { get; set; }
[JsonProperty("urgency")]
public string Urgency { get; set; } public string Urgency { get; set; }
[JsonProperty("severity")]
public string Severity { get; set; } public string Severity { get; set; }
[JsonProperty("certainty")]
public string Certainty { get; set; } public string Certainty { get; set; }
[JsonProperty("eventCode")]
public EventCode EventCode { get; set; } public EventCode EventCode { get; set; }
[JsonProperty("effective")]
public DateTimeOffset Effective { get; set; } public DateTimeOffset Effective { get; set; }
[JsonProperty("onset")]
public DateTimeOffset Onset { get; set; } public DateTimeOffset Onset { get; set; }
[JsonProperty("expires")]
public DateTimeOffset Expires { get; set; } public DateTimeOffset Expires { get; set; }
[JsonProperty("senderName")]
public string SenderName { get; set; } public string SenderName { get; set; }
[JsonProperty("headline")]
public string Headline { get; set; } public string Headline { get; set; }
[JsonProperty("description")]
public Description Description { get; set; } public Description Description { get; set; }
public object Instruction { get; set; }
[JsonProperty("web")]
public Uri Web { get; set; } public Uri Web { get; set; }
public EventCode Parameter { get; set; }
[JsonProperty("parameter")] public List<Area> Area { get; set; }
public EventCode[] Parameter { get; set; }
[JsonProperty("area")]
public Area[] Area { get; set; }
} }
public partial class Area public partial class Area
{ {
[JsonProperty("areaDesc")]
public string AreaDesc { get; set; } public string AreaDesc { get; set; }
public EventCode Geocode { get; set; }
}
[JsonProperty("polygon")] public partial class EventCode
public string Polygon { get; set; } {
public string ValueName { get; set; }
public string Value { get; set; }
} }
public partial class Description public partial class Description
{ {
[JsonProperty("typhoon-info")]
public TyphoonInfo TyphoonInfo { get; set; } public TyphoonInfo TyphoonInfo { get; set; }
public List<DescriptionSection> Section { get; set; }
[JsonProperty("section")]
public DescriptionSection[] Section { get; set; }
} }
public partial class DescriptionSection public partial class DescriptionSection
{ {
[JsonProperty("@title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("#text")]
public string Text { get; set; } public string Text { get; set; }
} }
public partial class TyphoonInfo public partial class TyphoonInfo
{ {
[JsonProperty("section")] public List<TyphoonInfoSection> Section { get; set; }
public TyphoonInfoSection[] Section { get; set; }
} }
public partial class TyphoonInfoSection public partial class TyphoonInfoSection
{ {
[JsonProperty("@title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)]
public string Text { get; set; } public string Text { get; set; }
[JsonProperty("typhoon_name", NullValueHandling = NullValueHandling.Ignore)]
public string TyphoonName { get; set; } public string TyphoonName { get; set; }
public string CwaTyphoonName { get; set; }
[JsonProperty("cwb_typhoon_name", NullValueHandling = NullValueHandling.Ignore)]
public string CwbTyphoonName { get; set; }
[JsonProperty("analysis", NullValueHandling = NullValueHandling.Ignore)]
public Analysis Analysis { get; set; } public Analysis Analysis { get; set; }
[JsonProperty("prediction", NullValueHandling = NullValueHandling.Ignore)]
public Analysis Prediction { get; set; } public Analysis Prediction { get; set; }
} }
public partial class Analysis public partial class Analysis
{ {
[JsonProperty("time")]
public DateTimeOffset Time { get; set; } public DateTimeOffset Time { get; set; }
[JsonProperty("position")]
public string Position { get; set; } public string Position { get; set; }
[JsonProperty("max_winds")]
public Gust MaxWinds { get; set; } public Gust MaxWinds { get; set; }
[JsonProperty("gust")]
public Gust Gust { get; set; } public Gust Gust { get; set; }
[JsonProperty("pressure")]
public Gust Pressure { get; set; } public Gust Pressure { get; set; }
[JsonProperty("radius_of_15mps")]
public Gust RadiusOf15Mps { get; set; } public Gust RadiusOf15Mps { get; set; }
public List<Scale> Scale { get; set; }
[JsonProperty("scale", NullValueHandling = NullValueHandling.Ignore)]
public Scale[] Scale { get; set; }
} }
public partial class Gust public partial class Gust
{ {
[JsonProperty("@unit")]
public string Unit { get; set; } public string Unit { get; set; }
[JsonProperty("#text")]
[JsonConverter(typeof(ParseStringConverter))]
public long Text { get; set; } public long Text { get; set; }
} }
public partial class Scale public partial class Scale
{ {
[JsonProperty("@lang")]
public string Lang { get; set; } public string Lang { get; set; }
[JsonProperty("#text")]
public string Text { get; set; } public string Text { get; set; }
} }
public partial class EventCode
{
[JsonProperty("valueName")]
public string ValueName { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
public partial class Xml public partial class Xml
{ {
[JsonProperty("@version")]
public string Version { get; set; } public string Version { get; set; }
[JsonProperty("@encoding")]
public string Encoding { get; set; }
} }
public partial class Welcome public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode112 };
{
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 =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
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);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
} }

View File

@ -15,11 +15,11 @@
"ParkingJob": "0/5 * * * * ?", "ParkingJob": "0/5 * * * * ?",
"ArchiveElectricMeterHourJob": "0 0 2 * * ?", "ArchiveElectricMeterHourJob": "0 0 2 * * ?",
"ArchiveElectricMeterDayJob": "0/5 * * * * ?", "ArchiveElectricMeterDayJob": "0/5 * * * * ?",
"WeatherAPIJob": "0 0 2 * * ?" "WeatherAPIJob": "0/5 * * * * ?"
}, },
"DBConfig": { "DBConfig": {
"MySqlDBConfig": { "MySqlDBConfig": {
"Server": "jbgI3Q4uFL4Kd9bbvToklA==", //0.202 "Server": "CYGthbCeGtAXT4s1NOSJHQ==", //0.202
"Port": "mkF51jVbg40V5K5eTh2Ckw==", //3306 "Port": "mkF51jVbg40V5K5eTh2Ckw==", //3306
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp

View File

@ -1,192 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
<identifier>CWB-Weather_extremely-rain_202306060340001</identifier>
<sender>weather@cwb.gov.tw</sender>
<sent>2023-06-06T03:45:20+08:00</sent>
<status>Actual</status>
<msgType>Cancel</msgType>
<scope>Public</scope>
<references>weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306060045001,2023-06-06T00:50:36+08:00 weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306052245001,2023-06-05T22:54:54+08:00 weather@cwb.gov.tw,CWB-Weather_extremely-rain_202306052220001,2023-06-05T22:25:45+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>rainfall</value>
</eventCode>
<effective>2023-06-06T03:40:00+08:00</effective>
<onset>2023-06-06T03:40:00+08:00</onset>
<expires>2023-06-06T03:55:20+08:00</expires>
<senderName>中央氣象局</senderName>
<headline>解除豪雨特報</headline>
<description>
由於降雨趨於緩和,發生大雨或豪雨的機率降低,故解除豪雨特報。
</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>

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>