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 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); } }