Пример #1
0
        public bool IsRiskWeather(OWMForecastItem forecast)
        {
            SwitcherDisableLog();
#if RiskRangeEnabled
            return(this.IsRiskWeather(forecast.Symbol.Var) || this.IsRiskTemperature(forecast.Temperature.Value));
#else
            return(true);
#endif
        }
        public override bool Equals(object obj)
        {
            OWMForecastItem newObj = obj as OWMForecastItem;

            if (newObj != null)
            {
                return(newObj.FromDate == this.FromDate &&
                       newObj.ToDate == this.ToDate &&
                       newObj.Symbol.ToString() == this.Symbol.ToString() &&
                       newObj.Temperature.RoughlyEqual(this.Temperature));
            }
            return(base.Equals(obj));
        }
Пример #3
0
 bool IsChineseFog(OWMForecastItem obj)
 {
     return(obj.Symbol.Var.Contains("雾"));
 }
Пример #4
0
        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);
            }
        }