CheckerResult CheckCurrentWeatherInfo() { FeitionPoster poster = new FeitionPoster(this.ReceiverMan.FeitionAccount); OWMCurWeather record = null; try { OWMWebRequest <OWMCurWeather> req = new OWMWebRequest <OWMCurWeather>( OWMPublic.OWMRequest(OWMRequestKind.CurrentWeather), this.ReceiverMan.Location.OWM.CityID, this.ReceiverMan.Location.OWM.CityName); req.Coordinary = this.ReceiverMan.Location.OWM.Coordinary; req.Language = "zh_cn"; record = req.GetResponse(); } catch (Exception ex) { CheckerLogWrite(string.Format("CheckCurrentWeatherInfo: {0}", ex.ToString())); } if (record == null) { CheckerLogWrite("OWMWebRequest<OWMCurWeather>:GetResponse returns null."); return(CheckerResult.NetworkIssue); } if (HRWNRiskDefinition.Instance.IsRiskWeather(record)) { // Maybe the fog weather is fake if there is. CheckerResult cResult = CheckChineseSpecialFogWeather(record); switch (cResult) { case CheckerResult.Sent: case CheckerResult.Existing: case CheckerResult.IsNotRisk: { CheckerLogWrite("Current Weather: This is a chinese fake fog, report AQI successfully instead."); // and we just regard it as a good check process is done. return(CheckerResult.Sent); } case CheckerResult.NetworkIssue: case CheckerResult.DataIssue: { CheckerLogWrite("Current Weather: Not sure whether this is a chinese fake fog as it failed to get AQI data."); // and we just regard it as a good check process is done. return(CheckerResult.Sent); } } string str = record.GetReadableText(this.ReceiverMan.Location.OWM.CityNickName); poster.AppendMessage(str); bool fExist = curWeatherHistoryList.Exists(record); if (fExist) { //ConsoleMe.WriteLine("Existing current weather: {0}.", record.ToString()); CheckerLogWrite("Existing current weather."); return(CheckerResult.Existing); } bool status = poster.Send(); if (!fExist && status) { curWeatherHistoryList.Add(record); } poster.ResetMessage(); return(CheckerResult.Sent); } else { CheckerLogWrite("OWMCurWeather: isn't a risk."); return(CheckerResult.IsNotRisk); } }
CheckerResult CheckNextHourForecastInfo() { FeitionPoster poster = new FeitionPoster(this.ReceiverMan.FeitionAccount); OWMForecast record = null; try { OWMWebRequest <OWMForecast> req = new OWMWebRequest <OWMForecast>( OWMPublic.OWMRequest(OWMRequestKind.HourlyForecast), this.ReceiverMan.Location.OWM.CityID, this.ReceiverMan.Location.OWM.CityName); req.Coordinary = this.ReceiverMan.Location.OWM.Coordinary; req.Language = "zh_cn"; record = req.GetResponse(); } catch (Exception ex) { CheckerLogWrite(string.Format("CheckNextHourForecastInfo: {0}", ex.ToString())); return(CheckerResult.NetworkIssue); } if (record == null) { CheckerLogWrite("OWMWebRequest<OWMForecast>:GetResponse returns null."); return(CheckerResult.NetworkIssue); } if (record.Forecasts.TimeArray.Count() > 0) { var res = (from c in record.Forecasts.TimeArray orderby c.FromDate select c).ToList(); if (res != null && res.Count > 0) { OWMForecastItem forecastItem = res[0]; if (HRWNRiskDefinition.Instance.IsRiskWeather(forecastItem)) { if (IsChineseFog(forecastItem)) { CheckerLogWrite("Forecast: Maybe this is a chinese fake fog, let's omit it for foreast."); return(CheckerResult.DataIssue); } poster.AppendMessage(forecastItem.ToString()); bool fExist = forecastHistoryList.Exists(forecastItem); if (fExist) { //ConsoleMe.WriteLine("Existing forecast: {0}.", forecastItem.ToString()); CheckerLogWrite("Existing forecast."); return(CheckerResult.Existing); } bool status = poster.Send(); if (!fExist && status) { forecastHistoryList.Add(forecastItem); } poster.ResetMessage(); return(CheckerResult.Sent); } else { CheckerLogWrite("OWMForecastItem: isn't a risk."); return(CheckerResult.IsNotRisk); } } else { return(CheckerResult.DataIssue); } } else { CheckerLogWrite("No data returned for OWMForecastItem."); return(CheckerResult.DataIssue); } }
CheckerResult CheckSpecialStationAQI(int averageValue = int.MaxValue) { FeitionPoster poster = new FeitionPoster(this.ReceiverMan.FeitionAccount); List <AQIRecord> res = null; try { PM25WebRequest <AQIRecord> req = new PM25WebRequest <AQIRecord>(this.RequestKind, this.ReceiverMan.Location.PM25.CityName); res = req.GetResponse <AQIRecord>(); } catch (Exception ex) { CheckerLogWrite(string.Format("CheckNextHourForecastInfo: {0}", ex.ToString())); } if (res == null) { CheckerLogWrite("PM25WebRequest:GetResponse returns null."); return(CheckerResult.NetworkIssue); } var result = (from c in res where c.Position_Name == this.ReceiverMan.Location.PM25.StationName select c).ToList(); AQIRecord aqiRecord; if (result != null && result.Count() > 0) { aqiRecord = result[0]; if (this.ReceiverMan.Location.PM25.IsEnabled == 0) { CheckerLogWrite("Disabled the AQI switcher."); // Assume that the record is existing here. return(CheckerResult.Existing); } bool forceSend = false; if (averageValue != int.MaxValue) { // Temporarily diabled. Should we really define another threshold value for AQI AGAIN? //forceSend = Convert.ToInt32(aqiRecord.AQI) > averageValue; } if (forceSend || HRWNRiskDefinition.Instance.IsRiskAQI(aqiRecord)) { string str = aqiRecord.GetReadableText(); poster.AppendMessage(str); bool fExist = aqiRecordHistoryList.Exists(aqiRecord); if (fExist) { //ConsoleMe.WriteLine("Existing aqi: {0}.", aqiRecord.ToString()); CheckerLogWrite("Existing aqi."); return(CheckerResult.Existing); } bool status = poster.Send(); if (status) { aqiRecordHistoryList.Add(aqiRecord); } poster.ResetMessage(); return(CheckerResult.Sent); } else { CheckerLogWrite("AQIRecord: isn't a risk."); return(CheckerResult.IsNotRisk); } } else { return(CheckerResult.DataIssue); } }