1. 天氣 加入try catch
This commit is contained in:
parent
855fa4024d
commit
ab0aa1ee1d
@ -40,9 +40,11 @@ namespace SolarPower.Quartz.Jobs
|
||||
var DateTimeNow = DateTime.Now;
|
||||
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
||||
|
||||
Root2 observation = null;
|
||||
|
||||
if (this.environment.IsDevelopment())
|
||||
{
|
||||
dateTime = "2021-08-09 10";
|
||||
dateTime = "2021-08-16 09";
|
||||
}
|
||||
|
||||
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
|
||||
@ -64,13 +66,23 @@ namespace SolarPower.Quartz.Jobs
|
||||
List<WeatherObservation> weatherObservations = new List<WeatherObservation>();
|
||||
|
||||
#region 氣象觀測(取資料)
|
||||
try
|
||||
{
|
||||
logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】");
|
||||
var client = new HttpClient();
|
||||
var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP";
|
||||
HttpResponseMessage response = client.GetAsync(UVUri).Result;
|
||||
String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
|
||||
Root2 observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
|
||||
observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
|
||||
logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("【CalcPowerStationJob】【取得失敗氣象觀測】");
|
||||
logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message);
|
||||
observation = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||
@ -353,7 +365,7 @@ namespace SolarPower.Quartz.Jobs
|
||||
#endregion
|
||||
|
||||
WeatherObservation weatherObservation = new WeatherObservation();
|
||||
if (powerStation.WeathersStationId != null)
|
||||
if (powerStation.WeathersStationId != null && observation != null)
|
||||
{
|
||||
foreach (var Location in observation.Records.Location)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user