diff --git a/BackendWorkerService/Program.cs b/BackendWorkerService/Program.cs index f87a035..6fdac3c 100644 --- a/BackendWorkerService/Program.cs +++ b/BackendWorkerService/Program.cs @@ -128,12 +128,12 @@ namespace BackendWorkerService ); #endregion - #region 電錶歸檔(設定每 小時 執行一次) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ArchiveElectricMeterHourJob")) - ); - #endregion + //#region 電錶歸檔(設定每 小時 執行一次) + //services.AddSingleton(); + //services.AddSingleton( + //new JobSchedule(jobType: typeof(ArchiveElectricMeterHourJob), cronExpression: configuration.GetValue("BackgroundServiceCron:ArchiveElectricMeterHourJob")) + //); + //#endregion #region 電錶歸檔(設定每 天 執行一次) services.AddSingleton(); diff --git a/BackendWorkerService/Quartz/JobSchedule.cs b/BackendWorkerService/Quartz/JobSchedule.cs index ae2344d..249a920 100644 --- a/BackendWorkerService/Quartz/JobSchedule.cs +++ b/BackendWorkerService/Quartz/JobSchedule.cs @@ -118,13 +118,13 @@ namespace BackendWorkerService.Quartz /// /// /// - 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 { Dictionary worktime = new Dictionary() { - { "@lastwork_time", DateTime.Now}, + { "@lastwork_time", dateTime ?? DateTime.Now}, { "@success", 2}, { "@updated_at", DateTime.Now}, }; diff --git a/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs b/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs index b375d16..781a044 100644 --- a/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs +++ b/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs @@ -17,6 +17,8 @@ using System.Xml.Serialization; using System.Linq; using NCrontab; using BackendWorkerService.Services.Implement; +using RainApi; +using System.Globalization; namespace BackendWorkerService.Quartz.Jobs { @@ -200,71 +202,71 @@ namespace BackendWorkerService.Quartz.Jobs doc.Load("root/PowerfulRain.xml"); var json = JsonConvert.SerializeXmlNode(doc); var haveinfo = json.Split("info"); - //if (haveinfo.Length > 2) - //{ - // 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 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 NeedCallApi = await backendRepository.GetOneAsync(sql); + if (haveinfo.Length > 2) + { + var observation = JsonConvert.DeserializeObject(json); + 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.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(sql); - // Dictionary RainAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@onset", observation.Alert.Info[0].Onset}, - // { "@expires", observation.Alert.Info[0].Expires}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); - // if (NeedCallApi != 0) - // { - // var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); - // 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()); - // UpdatedNiagara("api_rain", ReStr, id); - // } - // } + Dictionary RainAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@onset", observation.Alert.Info.Onset}, + { "@expires", observation.Alert.Info.Expires}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); + if (NeedCallApi != 0) + { + var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline); + 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()); + UpdatedNiagara("api_rain", ReStr, id); + } + } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/PowerfulRain.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); - //} - //else - //{ - // 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 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 NeedCallApi = await backendRepository.GetOneAsync(sql); + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/PowerfulRain.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); + } + else + { + var observation = JsonConvert.DeserializeObject(json); + 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.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(sql); - // Dictionary RainAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@onset", observation.Alert.Info[0].Onset.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@expires", observation.Alert.Info[0].Expires.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); - // if (NeedCallApi != 0) - // { - // var val = RainValue(observation.Alert.MsgType, observation.Alert.Info[0].Headline); - // 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()); - // UpdatedNiagara("api_rain", ReStr, id); - // } - // } + Dictionary RainAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(RainAPIdb, "api_rain"); + if (NeedCallApi != 0) + { + var val = RainValue(observation.Alert.MsgType, observation.Alert.Info.Headline); + 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()); + UpdatedNiagara("api_rain", ReStr, id); + } + } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/PowerfulRain.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/PowerfulRain.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_rain"); - //} + } } catch (Exception ex) { @@ -276,79 +278,80 @@ namespace BackendWorkerService.Quartz.Jobs { 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(); 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(); doc.Load("root/Typhoon.xml"); var json = JsonConvert.SerializeXmlNode(doc); + var haveinfo = json.Split("info"); - //if (haveinfo.Length > 2) - //{ - // var observation = TyphoonApi.Welcome.FromJson(json); - // 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 NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary EarthquakeAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info[0].Headline}, - // { "@areaDesc", area}, - // { "@urgency",observation.Alert.Info[0].Urgency}, - // { "@severity",observation.Alert.Info[0].Severity}, - // { "@onset", observation.Alert.Info[0].Onset}, - // { "@expires", observation.Alert.Info[0].Expires}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); - // if (NeedCallApi != 0) - // { - // if (observation.Alert.Info[0].Urgency != null && observation.Alert.Info[0].Urgency != "Expected") - // { + if (haveinfo.Length > 2) + { + var observation = JsonConvert.DeserializeObject(json); + 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 NeedCallApi = await backendRepository.GetOneAsync(sql); + Dictionary EarthquakeAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@urgency",observation.Alert.Info.Urgency}, + { "@severity",observation.Alert.Info.Severity}, + { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); + if (NeedCallApi != 0) + { + 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); - // UpdatedNiagara("api_typhoon", ReStr, id); - // } - // } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/Typhoon.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); - //} - //else - //{ - // var observation = TyphoonApi.Welcome.FromJson(json); - // //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 NeedCallApi = await backendRepository.GetOneAsync(sql); - // Dictionary EarthquakeAPIdb = new Dictionary() - // { - // { "@msgType", observation.Alert.MsgType}, - // { "@headline", observation.Alert.Info.Headline}, - // //{ "@areaDesc", area}, - // { "@urgency",observation.Alert.Info.Urgency}, - // { "@severity",observation.Alert.Info.Severity}, - // { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, - // { "@created_by", "system"}, - // { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - // }; - // var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); - // if (NeedCallApi != 0) - // { - // 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); + UpdatedNiagara("api_typhoon", ReStr, id); + } + } + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/Typhoon.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); + } + else + { + var observation = JsonConvert.DeserializeObject(json); + 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 NeedCallApi = await backendRepository.GetOneAsync(sql); + Dictionary EarthquakeAPIdb = new Dictionary() + { + { "@msgType", observation.Alert.MsgType}, + { "@headline", observation.Alert.Info.Headline}, + { "@areaDesc", area}, + { "@urgency",observation.Alert.Info.Urgency}, + { "@severity",observation.Alert.Info.Severity}, + { "@onset", observation.Alert.Info.Onset.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@expires", observation.Alert.Info.Expires.ToString("yyyy-MM-dd HH:mm:ss")}, + { "@created_by", "system"}, + { "@created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + }; + var id = await backendRepository.AddOneByCustomTableReturnId(EarthquakeAPIdb, "api_typhoon"); + if (NeedCallApi != 0) + { + 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); - // UpdatedNiagara("api_typhoon", ReStr, id); - // } - // } - // FolderFunction folderFunction = new FolderFunction(); - // folderFunction.DeleteFile("root/Typhoon.xml"); - // await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); + 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); + } + } + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile("root/Typhoon.xml"); + await task_Detail.InsertWorkTime_End("WeatherAPI", "api_typhoon"); - //} + } } catch (Exception ex) @@ -356,16 +359,18 @@ namespace BackendWorkerService.Quartz.Jobs await task_Detail.WorkFail("WeatherAPI", "api_typhoon", ex.Message.ToString()); } } + if (await task_Detail.GetNeedWorkTask("WeatherAPI", "api_earthquake")) { 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 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; String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString(); - var observation = QuickType.Welcome.FromJson(jsonUVs); + var j = JsonConvert.DeserializeObject(jsonUVs); + var observation = JsonConvert.DeserializeObject(jsonUVs); if (!observation.Success) { logger.LogInformation("WeatherAPIJob敺圈閫皜祈銝甇蝣箝"); @@ -395,7 +400,7 @@ namespace BackendWorkerService.Quartz.Jobs } else { - if (a.Intensity.ShakingArea.Length > 0) + if (a.Intensity.ShakingArea.Count > 0) { Dictionary EarthquakeAPIdb = new Dictionary() { @@ -460,6 +465,7 @@ namespace BackendWorkerService.Quartz.Jobs await task_Detail.WorkFail("WeatherAPI", "api_earthquake", ex.Message.ToString()); } } + if (await task_Detail.GetNeedWorkTask("WeatherAPI", "set_weather")) { try diff --git a/BackendWorkerService/Services/Implement/Quicktype.cs b/BackendWorkerService/Services/Implement/Quicktype.cs index 35dab94..f14a43f 100644 --- a/BackendWorkerService/Services/Implement/Quicktype.cs +++ b/BackendWorkerService/Services/Implement/Quicktype.cs @@ -21,191 +21,100 @@ namespace QuickType public partial class Welcome { - [JsonProperty("success")] - [JsonConverter(typeof(ParseStringConverter))] public bool Success { get; set; } - - [JsonProperty("result")] public Result Result { get; set; } - - [JsonProperty("records")] public Records Records { get; set; } } public partial class Records { - [JsonProperty("datasetDescription")] public DatasetDescription DatasetDescription { get; set; } - - [JsonProperty("Earthquake")] - public Earthquake[] Earthquake { get; set; } + public List Earthquake { get; set; } } public partial class Earthquake { - [JsonProperty("EarthquakeNo")] public long EarthquakeNo { get; set; } - - [JsonProperty("ReportType")] public DatasetDescription ReportType { get; set; } - - [JsonProperty("ReportColor")] public ReportColor ReportColor { get; set; } - - [JsonProperty("ReportContent")] public string ReportContent { get; set; } - - [JsonProperty("ReportImageURI")] public Uri ReportImageUri { get; set; } - - [JsonProperty("ReportRemark")] - public ReportRemark ReportRemark { get; set; } - - [JsonProperty("Web")] + public string ReportRemark { get; set; } public Uri Web { get; set; } - - [JsonProperty("ShakemapImageURI")] public Uri ShakemapImageUri { get; set; } - - [JsonProperty("EarthquakeInfo")] public EarthquakeInfo EarthquakeInfo { get; set; } - - [JsonProperty("Intensity")] public Intensity Intensity { get; set; } } public partial class EarthquakeInfo { - [JsonProperty("OriginTime")] public DateTimeOffset OriginTime { get; set; } - - [JsonProperty("Source")] public Source Source { get; set; } - - [JsonProperty("FocalDepth")] public double FocalDepth { get; set; } - - [JsonProperty("Epicenter")] public Epicenter Epicenter { get; set; } - - [JsonProperty("EarthquakeMagnitude")] public EarthquakeMagnitude EarthquakeMagnitude { get; set; } } public partial class EarthquakeMagnitude { - [JsonProperty("MagnitudeType")] public MagnitudeType MagnitudeType { get; set; } - - [JsonProperty("MagnitudeValue")] public double MagnitudeValue { get; set; } } public partial class Epicenter { - [JsonProperty("Location")] public string Location { get; set; } - - [JsonProperty("EpicenterLatitude")] public double EpicenterLatitude { get; set; } - - [JsonProperty("EpicenterLongitude")] public double EpicenterLongitude { get; set; } } public partial class Intensity { - [JsonProperty("ShakingArea")] - public ShakingArea[] ShakingArea { get; set; } + public List ShakingArea { get; set; } } public partial class ShakingArea { - [JsonProperty("AreaDesc")] public string AreaDesc { get; set; } - - [JsonProperty("CountyName")] public string CountyName { get; set; } - - [JsonProperty("InfoStatus", NullValueHandling = NullValueHandling.Ignore)] public InfoStatus? InfoStatus { get; set; } - - [JsonProperty("AreaIntensity")] - public AreaIntensityEnum AreaIntensity { get; set; } - - [JsonProperty("EqStation")] - public EqStation[] EqStation { get; set; } + public string AreaIntensity { get; set; } + public List EqStation { get; set; } } public partial class EqStation { - [JsonProperty("pga", NullValueHandling = NullValueHandling.Ignore)] public Pga Pga { get; set; } - - [JsonProperty("pgv", NullValueHandling = NullValueHandling.Ignore)] public Pga Pgv { get; set; } - - [JsonProperty("StationName")] public string StationName { get; set; } - - [JsonProperty("StationID")] public string StationId { get; set; } - - [JsonProperty("InfoStatus", NullValueHandling = NullValueHandling.Ignore)] public InfoStatus? InfoStatus { get; set; } - - [JsonProperty("BackAzimuth")] public double BackAzimuth { get; set; } - - [JsonProperty("EpicenterDistance")] public double EpicenterDistance { get; set; } - - [JsonProperty("SeismicIntensity")] - public AreaIntensityEnum SeismicIntensity { get; set; } - - [JsonProperty("StationLatitude")] + public string SeismicIntensity { get; set; } public double StationLatitude { get; set; } - - [JsonProperty("StationLongitude")] public double StationLongitude { get; set; } - - [JsonProperty("WaveImageURI", NullValueHandling = NullValueHandling.Ignore)] public Uri WaveImageUri { get; set; } } public partial class Pga { - [JsonProperty("unit")] public Unit Unit { get; set; } - - [JsonProperty("EWComponent")] public double EwComponent { get; set; } - - [JsonProperty("NSComponent")] public double NsComponent { get; set; } - - [JsonProperty("VComponent")] public double VComponent { get; set; } - - [JsonProperty("IntScaleValue")] public double IntScaleValue { get; set; } } public partial class Result { - [JsonProperty("resource_id")] public string ResourceId { get; set; } - - [JsonProperty("fields")] - public Field[] Fields { get; set; } + public List Fields { get; set; } } public partial class Field { - [JsonProperty("id")] public string Id { get; set; } - - [JsonProperty("type")] public TypeEnum Type { get; set; } } @@ -213,428 +122,18 @@ namespace QuickType 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 Unit { Gal, Kine }; - public enum ReportColor { 蝬 }; + public enum ReportColor { 蝬, 暺 }; - public enum ReportRemark { 砍勗靽銝剖亢瘞鞊∪圈閫皜祉雯單圈鞈圈曹蝯 }; + public enum ReportRemark { 砍勗靽銝剖亢瘞鞊∪圈閫皜祉雯單圈鞈圈曹蝯, 砍勗靽銝剖亢瘞鞊∠蔡圈閫皜祉雯單圈鞈圈曹蝯 }; public enum TypeEnum { Float, Integer, String, Timestamp }; - public partial class Welcome - { - public static Welcome FromJson(string json) => JsonConvert.DeserializeObject(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(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(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(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(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(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(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(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(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(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(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(); - } } diff --git a/BackendWorkerService/Services/Implement/RainApi.cs b/BackendWorkerService/Services/Implement/RainApi.cs index ec870f9..a161026 100644 --- a/BackendWorkerService/Services/Implement/RainApi.cs +++ b/BackendWorkerService/Services/Implement/RainApi.cs @@ -21,208 +21,61 @@ namespace RainApi public partial class Welcome { - [JsonProperty("?xml")] public Xml Xml { get; set; } - - [JsonProperty("alert")] public Alert Alert { get; set; } } public partial class Alert { - [JsonProperty("@xmlns")] public string Xmlns { get; set; } - - [JsonProperty("identifier")] public string Identifier { get; set; } - - [JsonProperty("sender")] public string Sender { get; set; } - - [JsonProperty("sent")] public DateTimeOffset Sent { get; set; } - - [JsonProperty("status")] public string Status { get; set; } - - [JsonProperty("msgType")] public string MsgType { get; set; } - - [JsonProperty("scope")] public string Scope { get; set; } - - [JsonProperty("references")] public string References { get; set; } - - [JsonProperty("info")] - public Info[] Info { get; set; } + public Info Info { get; set; } } public partial class Info { - [JsonProperty("language")] public string Language { get; set; } - - [JsonProperty("category")] public string Category { get; set; } - - [JsonProperty("event")] public string Event { get; set; } - - [JsonProperty("responseType")] - public string ResponseType { get; set; } - - [JsonProperty("urgency")] public string Urgency { get; set; } - - [JsonProperty("severity")] public string Severity { get; set; } - - [JsonProperty("certainty")] public string Certainty { get; set; } - - [JsonProperty("eventCode")] public EventCode EventCode { get; set; } - - [JsonProperty("effective")] public DateTimeOffset Effective { get; set; } - - [JsonProperty("onset")] public DateTimeOffset Onset { get; set; } - - [JsonProperty("expires")] public DateTimeOffset Expires { get; set; } - - [JsonProperty("senderName")] public string SenderName { get; set; } - - [JsonProperty("headline")] public string Headline { get; set; } - - [JsonProperty("description")] public string Description { get; set; } - - [JsonProperty("web")] + public string Instruction { get; set; } public Uri Web { get; set; } - - [JsonProperty("parameter")] - public EventCode[] Parameter { get; set; } - - [JsonProperty("area")] - public Area[] Area { get; set; } + public EventCode Parameter { get; set; } + public List Area { get; set; } } public partial class Area { - [JsonProperty("areaDesc")] public string AreaDesc { get; set; } - - [JsonProperty("geocode")] public EventCode Geocode { get; set; } } public partial class EventCode { - [JsonProperty("valueName")] - public ValueName ValueName { get; set; } - - [JsonProperty("value")] + public string ValueName { get; set; } public string Value { get; set; } } public partial class Xml { - [JsonProperty("@version")] public string Version { get; set; } - - [JsonProperty("@encoding")] public string Encoding { get; set; } } - public enum ValueName { AlertColor, AlertTitle, ProfileCapTwpEvent10, SeverityLevel, TaiwanGeocode103, WebsiteColor }; - - public partial class Welcome - { - public static Welcome FromJson(string json) => JsonConvert.DeserializeObject(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(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(); - } + public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode103 }; } diff --git a/BackendWorkerService/Services/Implement/TyphoonApi.cs b/BackendWorkerService/Services/Implement/TyphoonApi.cs index 07c8546..4ff2f3a 100644 --- a/BackendWorkerService/Services/Implement/TyphoonApi.cs +++ b/BackendWorkerService/Services/Implement/TyphoonApi.cs @@ -21,263 +21,110 @@ namespace TyphoonApi public partial class Welcome { - [JsonProperty("?xml")] public Xml Xml { get; set; } - - [JsonProperty("alert")] public Alert Alert { get; set; } } public partial class Alert { - [JsonProperty("@xmlns")] public string Xmlns { get; set; } - - [JsonProperty("identifier")] public string Identifier { get; set; } - - [JsonProperty("sender")] public string Sender { get; set; } - - [JsonProperty("sent")] public DateTimeOffset Sent { get; set; } - - [JsonProperty("status")] public string Status { get; set; } - - [JsonProperty("msgType")] public string MsgType { get; set; } - - [JsonProperty("scope")] public string Scope { get; set; } - - [JsonProperty("references")] public string References { get; set; } - - [JsonProperty("info")] public Info Info { get; set; } } public partial class Info { - [JsonProperty("language")] public string Language { get; set; } - - [JsonProperty("category")] public string Category { get; set; } - - [JsonProperty("event")] public string Event { get; set; } - - [JsonProperty("responseType")] - public string ResponseType { get; set; } - - [JsonProperty("urgency")] public string Urgency { get; set; } - - [JsonProperty("severity")] public string Severity { get; set; } - - [JsonProperty("certainty")] public string Certainty { get; set; } - - [JsonProperty("eventCode")] public EventCode EventCode { get; set; } - - [JsonProperty("effective")] public DateTimeOffset Effective { get; set; } - - [JsonProperty("onset")] public DateTimeOffset Onset { get; set; } - - [JsonProperty("expires")] public DateTimeOffset Expires { get; set; } - - [JsonProperty("senderName")] public string SenderName { get; set; } - - [JsonProperty("headline")] public string Headline { get; set; } - - [JsonProperty("description")] public Description Description { get; set; } - - [JsonProperty("web")] + public object Instruction { get; set; } public Uri Web { get; set; } - - [JsonProperty("parameter")] - public EventCode[] Parameter { get; set; } - - [JsonProperty("area")] - public Area[] Area { get; set; } + public EventCode Parameter { get; set; } + public List Area { get; set; } } public partial class Area { - [JsonProperty("areaDesc")] public string AreaDesc { get; set; } + public EventCode Geocode { get; set; } + } - [JsonProperty("polygon")] - public string Polygon { get; set; } + public partial class EventCode + { + public string ValueName { get; set; } + public string Value { get; set; } } public partial class Description { - [JsonProperty("typhoon-info")] public TyphoonInfo TyphoonInfo { get; set; } - - [JsonProperty("section")] - public DescriptionSection[] Section { get; set; } + public List 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 List 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 string CwaTyphoonName { get; set; } 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 List 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 - { - [JsonProperty("valueName")] - public string ValueName { get; set; } - - [JsonProperty("value")] - public string Value { get; set; } - } - public partial class Xml { - [JsonProperty("@version")] public string Version { get; set; } - - [JsonProperty("@encoding")] - public string Encoding { get; set; } } - public partial class Welcome - { - public static Welcome FromJson(string json) => JsonConvert.DeserializeObject(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(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(); - } + public enum ValueName { AlertTitle, ProfileCapTwpEvent10, TaiwanGeocode112 }; } diff --git a/BackendWorkerService/appsettings.Development.json b/BackendWorkerService/appsettings.Development.json index 8c89eee..1a5d4fd 100644 --- a/BackendWorkerService/appsettings.Development.json +++ b/BackendWorkerService/appsettings.Development.json @@ -15,11 +15,11 @@ "ParkingJob": "0/5 * * * * ?", "ArchiveElectricMeterHourJob": "0 0 2 * * ?", "ArchiveElectricMeterDayJob": "0/5 * * * * ?", - "WeatherAPIJob": "0 0 2 * * ?" + "WeatherAPIJob": "0/5 * * * * ?" }, "DBConfig": { "MySqlDBConfig": { - "Server": "jbgI3Q4uFL4Kd9bbvToklA==", //0.202 + "Server": "CYGthbCeGtAXT4s1NOSJHQ==", //0.202 "Port": "mkF51jVbg40V5K5eTh2Ckw==", //3306 //"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30 //"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp diff --git a/BackendWorkerService/root/PowerfulRain.xml b/BackendWorkerService/root/PowerfulRain.xml deleted file mode 100644 index fbb92b3..0000000 --- a/BackendWorkerService/root/PowerfulRain.xml +++ /dev/null @@ -1,192 +0,0 @@ - - - - CWB-Weather_extremely-rain_202306060340001 - weather@cwb.gov.tw - 2023-06-06T03:45:20+08:00 - Actual - Cancel - Public - 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 - - zh-TW - Met - - Past - Minor - Observed - - profile:CAP-TWP:Event:1.0 - rainfall - - 2023-06-06T03:40:00+08:00 - 2023-06-06T03:40:00+08:00 - 2023-06-06T03:55:20+08:00 - 銝剖亢瘞鞊∪ - 閫方悸函孵 - -望潮刻隅潛楨嚗潛憭折冽鞊芷函璈雿嚗閫方悸函孵晞 - - - https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html - - alert_title - 鞊芷函孵 - - - - 粹撣 - - Taiwan_Geocode_103 - 10017 - - - - 箏撣 - - Taiwan_Geocode_103 - 63 - - - - 啣撣 - - Taiwan_Geocode_103 - 65 - - - - 獢撣 - - Taiwan_Geocode_103 - 68 - - - - 啁姘撣 - - Taiwan_Geocode_103 - 10018 - - - - 啁姘蝮 - - Taiwan_Geocode_103 - 10004 - - - - - - Taiwan_Geocode_103 - 10005 - - - - 箔葉撣 - - Taiwan_Geocode_103 - 66 - - - - 敶啣蝮 - - Taiwan_Geocode_103 - 10007 - - - - 脫蝮 - - Taiwan_Geocode_103 - 10009 - - - - - - Taiwan_Geocode_103 - 10008 - - - - 蝢拍腦 - - Taiwan_Geocode_103 - 10010 - - - - 蝢拙 - - Taiwan_Geocode_103 - 10020 - - - - 箏撣 - - Taiwan_Geocode_103 - 67 - - - - 擃撣 - - Taiwan_Geocode_103 - 64 - - - - 撅梁腦 - - Taiwan_Geocode_103 - 10013 - - - - 摰剔腦 - - Taiwan_Geocode_103 - 10002 - - - - 梯桃腦 - - Taiwan_Geocode_103 - 10015 - - - - 箸梁腦 - - Taiwan_Geocode_103 - 10014 - - - - 瞉皝蝮 - - Taiwan_Geocode_103 - 10016 - - - - - - Taiwan_Geocode_103 - 09020 - - - - 瘙蝮 - - Taiwan_Geocode_103 - 09007 - - - - \ No newline at end of file diff --git a/BackendWorkerService/root/Typhoon.xml b/BackendWorkerService/root/Typhoon.xml deleted file mode 100644 index 9dd9749..0000000 --- a/BackendWorkerService/root/Typhoon.xml +++ /dev/null @@ -1,197 +0,0 @@ - - - - CWB-Weather_typhoon-warning_202305311730001 - weather@cwb.gov.tw - 2023-05-31T17:17:30+08:00 - Actual - Cancel - Public - weather@cwb.gov.tw,CWB-Weather_typhoon-warning_202305311430001,2023-05-31T14:22:23+08:00 - - zh-TW - Met - 憸梢◢ - Past - Minor - Observed - - profile:CAP-TWP:Event:1.0 - typhoon - - 2023-05-31T17:30:00+08:00 - 2023-05-31T17:30:00+08:00 - 2023-05-31T17:40:00+08:00 - 銝剖亢瘞鞊∪ - 閫日2憸刻郎 - -[憸梢◢] -寞啗憿舐內嚗蝚2憸梢◢湧◢敺亦箇葬撠嚗銝剖桀券暸撒勗望寞絲g梯勗蝘餃嚗撠撌游ㄚ瘚瑕魚箇勗刻瘚瑕撌脰圾扎 - -[瘜冽鈭] -嚗撌游ㄚ瘚瑕魚箇餈瘚琿a◢瘚芣憿臬憭改粹瘚瑕硫具勗(怨剖飲蝬撜)亙撜嗆窒瘚瑕瞉皝擐祉瑟答潛嚗撠文嗆勗(怨剖飲蝬撜)粹瘚瑕硫亙撜嗆窒瘚瑟45蝐單答擃嚗隢踹敺瘚琿瘣餃嚗訾撘琿◢孵梧隞(31)亥箏唾瘝踵絲蝛箸啣瞉皝剖飲蝬撜嗆910蝝撘琿憸剁啁姘隞亙粹瘚瑕硫勗冽窒瘚瑞征啣箏唾啣亙撜嗚擐祉鈭行頛撘琿憸剁隢孵交釣嚗3003117箇曇憭抒敞蝛券憒銝嚗摰剔腦蝧撜唳334.5瘥怎掖嚗箔葉撣皝靚257.0瘥怎掖嚗祈郎勗桐憸梢◢敺箏像敺嚗蝚2憸梢◢銋7蝝憸冽湧◢敺餈隡潭迤嚗撟喳敺蝝280祇憸梢◢閰喟敦寞扯砍憸梯抵牧(https://www.cwb.gov.tw/Data/typhoon/TY_PDF.pdf)嚗甇斤箇洵2憸梢◢霅血望敺銝甈∪勗 - - - - https://www.cwb.gov.tw/V8/C/P/Warning/FIFOWS.html - - alert_title - 憸梢◢霅血 - - - - 粹撣 - - Taiwan_Geocode_103 - 10017 - - - - 箏撣 - - Taiwan_Geocode_103 - 63 - - - - 啣撣 - - Taiwan_Geocode_103 - 65 - - - - 獢撣 - - Taiwan_Geocode_103 - 68 - - - - 啁姘撣 - - Taiwan_Geocode_103 - 10018 - - - - 啁姘蝮 - - Taiwan_Geocode_103 - 10004 - - - - - - Taiwan_Geocode_103 - 10005 - - - - 箔葉撣 - - Taiwan_Geocode_103 - 66 - - - - 敶啣蝮 - - Taiwan_Geocode_103 - 10007 - - - - 脫蝮 - - Taiwan_Geocode_103 - 10009 - - - - - - Taiwan_Geocode_103 - 10008 - - - - 蝢拍腦 - - Taiwan_Geocode_103 - 10010 - - - - 蝢拙 - - Taiwan_Geocode_103 - 10020 - - - - 箏撣 - - Taiwan_Geocode_103 - 67 - - - - 擃撣 - - Taiwan_Geocode_103 - 64 - - - - 撅梁腦 - - Taiwan_Geocode_103 - 10013 - - - - 摰剔腦 - - Taiwan_Geocode_103 - 10002 - - - - 梯桃腦 - - Taiwan_Geocode_103 - 10015 - - - - 箸梁腦 - - Taiwan_Geocode_103 - 10014 - - - - 瞉皝蝮 - - Taiwan_Geocode_103 - 10016 - - - - - - Taiwan_Geocode_103 - 09020 - - - - 瘙蝮 - - Taiwan_Geocode_103 - 09007 - - - - \ No newline at end of file