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 DateTimeNow = DateTime.Now;
|
||||||
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
|
||||||
|
|
||||||
|
Root2 observation = null;
|
||||||
|
|
||||||
if (this.environment.IsDevelopment())
|
if (this.environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
dateTime = "2021-08-09 10";
|
dateTime = "2021-08-16 09";
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
|
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
|
||||||
@ -64,13 +66,23 @@ namespace SolarPower.Quartz.Jobs
|
|||||||
List<WeatherObservation> weatherObservations = new List<WeatherObservation>();
|
List<WeatherObservation> weatherObservations = new List<WeatherObservation>();
|
||||||
|
|
||||||
#region 氣象觀測(取資料)
|
#region 氣象觀測(取資料)
|
||||||
logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】");
|
try
|
||||||
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";
|
logger.LogInformation("【CalcPowerStationJob】【開始取得氣象觀測】");
|
||||||
HttpResponseMessage response = client.GetAsync(UVUri).Result;
|
var client = new HttpClient();
|
||||||
String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
|
var UVUri = "https://opendata.cwb.gov.tw/api/v1/rest/datastore/O-A0003-001?Authorization=CWB-EA24220B-DDCC-4188-84E5-AD37A0E03F80&elementName=TIME,TEMP";
|
||||||
Root2 observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
|
HttpResponseMessage response = client.GetAsync(UVUri).Result;
|
||||||
logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】");
|
String jsonUVs = response.Content.ReadAsStringAsync().Result.ToString();
|
||||||
|
observation = JsonConvert.DeserializeObject<Root2>(jsonUVs);
|
||||||
|
logger.LogInformation("【CalcPowerStationJob】【取得成功氣象觀測】");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError("【CalcPowerStationJob】【取得失敗氣象觀測】");
|
||||||
|
logger.LogError("【{0}】{1}", "CalcPowerStationJob", ex.Message);
|
||||||
|
observation = null;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
#region step2. 從電站的DB及電站編號找出該電站的控制器
|
||||||
@ -353,7 +365,7 @@ namespace SolarPower.Quartz.Jobs
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
WeatherObservation weatherObservation = new WeatherObservation();
|
WeatherObservation weatherObservation = new WeatherObservation();
|
||||||
if (powerStation.WeathersStationId != null)
|
if (powerStation.WeathersStationId != null && observation != null)
|
||||||
{
|
{
|
||||||
foreach (var Location in observation.Records.Location)
|
foreach (var Location in observation.Records.Location)
|
||||||
{
|
{
|
||||||
@ -363,7 +375,7 @@ namespace SolarPower.Quartz.Jobs
|
|||||||
calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
|
calcPowerStation.TodayWeatherTemp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
|
||||||
weatherObservation.PowerStationId = powerStation.Id;
|
weatherObservation.PowerStationId = powerStation.Id;
|
||||||
weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
|
weatherObservation.Temp = Convert.ToDouble(Location.WeatherElement[0].ElementValue);
|
||||||
weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime)? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
weatherObservation.ObsTime = !string.IsNullOrEmpty(Location.Time.ObsTime) ? Convert.ToInt32(Location.Time.ObsTime.Substring(0, 4)) >= 1971 ? Location.Time.ObsTime : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
calcPowerStation.WeathersStationId = powerStation.WeathersStationId;
|
calcPowerStation.WeathersStationId = powerStation.WeathersStationId;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user