Esempio n. 1
0
 public static ToastContent CreateAlertToast(HeWeatherModel fetchresult, CitySettingsModel currentCityModel)
 {
     var lo = new ResourceLoader();
     var action = new ToastActionsCustom();
     var button = new ToastButton(lo.GetString("Known"), "Today_Alert_Dismiss");
     button.ActivationType = ToastActivationType.Background;
     action.Buttons.Add(button);
     action.Buttons.Add(new ToastButtonDismiss(lo.GetString("Dismiss")));
     var alarm = fetchresult.Alarms[0];
     ToastContent t = new ToastContent()
     {
         Scenario = ToastScenario.Reminder,
         Launch = currentCityModel.Id,
         Actions = action,
         Visual = new ToastVisual()
         {
             TitleText = new ToastText()
             {
                 Text = alarm.Title
             },
             BodyTextLine1 = new ToastText()
             {
                 Text = alarm.Text
             }
         }
     };
     return t;
 }
Esempio n. 2
0
        public static TileContent GenerateNormalTile(HeWeatherModel model, bool isNight, string glance, string glanceFull, Uri uri, int todayIndex, CitySettingsModel currentCity, SettingsModel settings)
        {
            var ctosConverter = new ConditiontoTextConverter();
            var ctoiConverter = new ConditiontoImageConverter();
            var loader = new ResourceLoader();
            #region
            TileContent NowContent = new TileContent()
            {
                Visual = new TileVisual()
                {
                    Branding = TileBranding.Auto,
                    DisplayName = currentCity.City,
                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            PeekImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TilePeekImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                            }),
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileText(),
                                new TileText()
                                {
                                    Text = (string)ctosConverter.Convert(model.NowWeather.Now.Condition,null,null,null),
                                    Align = TileTextAlign.Center
                                },


            new TileText()
            {
                Text = model.DailyForecast[todayIndex].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                Align = TileTextAlign.Center
            },

            new TileText()
            {
                Text = model.DailyForecast[todayIndex].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                Align = TileTextAlign.Center,
                Style = TileTextStyle.CaptionSubtle
            }
                                            }
                        }
                    },

                    TileWide = new TileBinding()
                    {
                        DisplayName = glance,
                        Branding = TileBranding.NameAndLogo,
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                                       {
                                new TileGroup()
                                {
                                    Children=
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].Date.ToString("ddd"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.NowWeather.Now.Condition,null,isNight,null))
                                                },
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 2,
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Center
                                                },
                                                new TileText()
                                                {
                                                    Text = (string)ctosConverter.Convert(model.NowWeather.Now.Condition,null,null,null),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },

                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Center
                                                }
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Text = loader.GetString("ScaleText"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Text = loader.GetString("HumText"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 2,
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {

                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Left
                                                },
                                                new TileText()
                                                {
                                                    Text = model.NowWeather.Wind.Speed.Actual(settings.Preferences.SpeedParameter) +
                                                    model.NowWeather.Wind.Speed.DanWei(settings.Preferences.SpeedParameter),
                                                    Align = TileTextAlign.Left,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {

                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Left
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].Humidity.ToString() + "%",
                                                    Align = TileTextAlign.Left,
                                                    Style = TileTextStyle.Caption
                                                },
                                            }
                                        },
                                    }
                                }
                                       },
                            PeekImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TilePeekImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                            }),
                        }
                    },
                    TileLarge = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                            new TileGroup()
                                            {
                                             Children =
                                             {
                                                 new TileSubgroup()
                                        {
                                            Weight = 30,
                                            Children =
                                            {
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.NowWeather.Now.Condition,null,isNight,null))
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].Date.ToString("ddd"),
                                                    Style = TileTextStyle.Base
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString() + '~' + model.DailyForecast[todayIndex].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Align = TileTextAlign.Auto,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                     Text = glanceFull,
                                                     Align = TileTextAlign.Auto,
                                                     Style = TileTextStyle.CaptionSubtle,
                                                     Wrap = true
                                                }
                                            }
                                        },
                                            },
                                           },
                                            new TileText(),
                                            new TileGroup()
                                            {
                                             Children =
                                             {
                                                 new TileSubgroup()
                                        {
                                            Weight = 30,
                                            Children =
                                            {
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.NowWeather.Now.Condition,null,isNight,null))
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].Date.ToString("ddd"),
                                                    Style = TileTextStyle.Base
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex + 1].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString() + '~' + model.DailyForecast[todayIndex + 1].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Align = TileTextAlign.Auto,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                     Text = loader.GetString("ScaleText")+": "+model.DailyForecast[todayIndex+1].Wind.Speed.Actual(settings.Preferences.SpeedParameter) +
                                                    model.DailyForecast[todayIndex+1].Wind.Speed.DanWei(settings.Preferences.SpeedParameter),
                                                     Align = TileTextAlign.Auto,
                                                     Style = TileTextStyle.CaptionSubtle,
                                                },
                                                new TileText()
                                                {
                                                     Text = loader.GetString("HumText")+": "+model.DailyForecast[todayIndex+1].Humidity.ToString() + "%",
                                                     Align = TileTextAlign.Auto,
                                                     Style = TileTextStyle.CaptionSubtle,
                                                     Wrap = true
                                                }
                                            }
                                        },
                                                }
                                            }

                            },
                            PeekImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TilePeekImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                            }),
                        }
                    }
                }
            };
            #endregion
            return NowContent;
        }
Esempio n. 3
0
 public static string[] CalculateWeatherAlarm(HeWeatherModel model, CitySettingsModel currentCityModel, SettingsModel settings, DateTime desiredDateTimeinThatRegion)
 {
     var l = new ResourceLoader();
     var todayIndex = Array.FindIndex(model.DailyForecast, x =>
     {
         return x.Date.Date == desiredDateTimeinThatRegion.Date;
     });
     var hourIndex = Array.FindIndex(model.HourlyForecast, x =>
     {
         return (x.DateTime - desiredDateTimeinThatRegion).TotalSeconds > 0;
     });
     if (desiredDateTimeinThatRegion.Hour < 7)
     {
         todayIndex--;
     }
     if (todayIndex < 0)
     {
         todayIndex = 0;
     }
     if (hourIndex < 0)
     {
         hourIndex = 0;
     }
     List<string> str = new List<string>();
     var ctos = new ConditiontoTextConverter();
     switch (model.DailyForecast[todayIndex + 1].Condition.DayCond)
     {
         case WeatherCondition.gale:
         case WeatherCondition.strong_gale:
         case WeatherCondition.storm:
         case WeatherCondition.violent_storm:
         case WeatherCondition.hurricane:
         case WeatherCondition.tornado:
         case WeatherCondition.tropical_storm:
             str.Add(currentCityModel.City + l.GetString("ToastGale"));
             break;
         case WeatherCondition.heavy_shower_rain:
             str.Add(currentCityModel.City + l.GetString("ToastRain"));
             break;
         case WeatherCondition.thundershower:
         case WeatherCondition.heavy_thunderstorm:
             str.Add(currentCityModel.City + l.GetString("ToastThunder"));
             break;
         case WeatherCondition.hail:
             str.Add(currentCityModel.City + l.GetString("ToastHail"));
             break;
         case WeatherCondition.heavy_rain:
         case WeatherCondition.extreme_rain:
         case WeatherCondition.storm_rain:
         case WeatherCondition.heavy_storm_rain:
         case WeatherCondition.severe_storm_rain:
             str.Add(currentCityModel.City + l.GetString("ToastRain"));
             break;
         case WeatherCondition.freezing_rain:
             str.Add(currentCityModel.City + l.GetString("ToastFreeze"));
             break;
         case WeatherCondition.heavy_snow:
         case WeatherCondition.snowstorm:
             str.Add(currentCityModel.City + l.GetString("ToastSnow"));
             break;
         case WeatherCondition.volcanic_ash:
         case WeatherCondition.duststorm:
         case WeatherCondition.sandstorm:
             str.Add(currentCityModel.City + l.GetString("ToastSand"));
             break;
         default:
             break;
     }
     if (str.IsNullorEmpty())
     {
         switch (model.DailyForecast[todayIndex + 1].Condition.NightCond)
         {
             case WeatherCondition.gale:
             case WeatherCondition.strong_gale:
             case WeatherCondition.storm:
             case WeatherCondition.violent_storm:
             case WeatherCondition.hurricane:
             case WeatherCondition.tornado:
             case WeatherCondition.tropical_storm:
                 str.Add(currentCityModel.City + l.GetString("ToastGale"));
                 break;
             case WeatherCondition.heavy_shower_rain:
                 str.Add(currentCityModel.City + l.GetString("ToastRain"));
                 break;
             case WeatherCondition.thundershower:
             case WeatherCondition.heavy_thunderstorm:
                 str.Add(currentCityModel.City + l.GetString("ToastThunder"));
                 break;
             case WeatherCondition.hail:
                 str.Add(currentCityModel.City + l.GetString("ToastHail"));
                 break;
             case WeatherCondition.heavy_rain:
             case WeatherCondition.extreme_rain:
             case WeatherCondition.storm_rain:
             case WeatherCondition.heavy_storm_rain:
             case WeatherCondition.severe_storm_rain:
                 str.Add(currentCityModel.City + l.GetString("ToastRain"));
                 break;
             case WeatherCondition.freezing_rain:
                 str.Add(currentCityModel.City + l.GetString("ToastFreeze"));
                 break;
             case WeatherCondition.heavy_snow:
             case WeatherCondition.snowstorm:
                 str.Add(currentCityModel.City + l.GetString("ToastSnow"));
                 break;
             case WeatherCondition.volcanic_ash:
             case WeatherCondition.duststorm:
             case WeatherCondition.sandstorm:
                 str.Add(currentCityModel.City + l.GetString("ToastSand"));
                 break;
             default:
                 break;
         }
     }
     if (str.IsNullorEmpty())
     {
         if ((((model.DailyForecast[todayIndex + 1].LowTemp + model.DailyForecast[todayIndex + 1].HighTemp) / 2).Celsius - ((model.DailyForecast[todayIndex].LowTemp + model.DailyForecast[todayIndex].HighTemp) / 2).Celsius) > 8)
         {
             str.Add(currentCityModel.City + l.GetString("ToastHot"));
         }
         else if ((((model.DailyForecast[todayIndex + 1].LowTemp + model.DailyForecast[todayIndex + 1].HighTemp) / 2).Celsius - ((model.DailyForecast[todayIndex].LowTemp + model.DailyForecast[todayIndex].HighTemp) / 2).Celsius) < -8)
         {
             str.Add(currentCityModel.City + l.GetString("ToastCold"));
         }
     }
     if (!str.IsNullorEmpty())
     {
         str.Add(ctos.Convert(model.DailyForecast[todayIndex + 1].Condition.DayCond, null, null, null) + "  " + model.DailyForecast[todayIndex + 1].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString() + "~" + model.DailyForecast[todayIndex + 1].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString());
     }
     return str.ToArray();
 }
Esempio n. 4
0
        public static async Task<List<TileContent>> CreateAll(CitySettingsModel currentCity, HeWeatherModel model, DateTime desiredDateTimeinThatRegion)
        {
            var todayIndex = Array.FindIndex(model.DailyForecast, x =>
            {
                return x.Date.Date == desiredDateTimeinThatRegion.Date;
            });
            var hourIndex = Array.FindIndex(model.HourlyForecast, x =>
            {
                return (x.DateTime - desiredDateTimeinThatRegion).TotalSeconds > 0;
            });
            if (desiredDateTimeinThatRegion.Hour < 7)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            if (hourIndex < 0)
            {
                hourIndex = 0;
            }
            var sunRise = model.DailyForecast[todayIndex].SunRise;
            var sunSet = model.DailyForecast[todayIndex].SunSet;
            var currentTime = desiredDateTimeinThatRegion;

            var settings = SettingsModel.Current;
            var isNight = CalcIsNight(currentTime, sunRise, sunSet, new Models.Location(currentCity.Latitude, currentCity.Longitude));
            Uri uri = await settings.Immersive.GetCurrentBackgroundAsync(model.NowWeather.Now.Condition, isNight);

            var glance = Glance.GenerateShortDescription(model, isNight);
            var glanceFull = Glance.GenerateGlanceDescription(model, isNight, settings.Preferences.TemperatureParameter, desiredDateTimeinThatRegion);
            var lockdetial = Glance.GenerateLockDetailDescription(model, isNight, settings.Preferences.TemperatureParameter, desiredDateTimeinThatRegion);
            var noramlTile = GenerateNormalTile(model, isNight, glance, glanceFull, uri, todayIndex, currentCity, settings);
            var nowTile = GenerateNowTile(model, isNight, uri, glanceFull, lockdetial, todayIndex, currentCity, settings);
            var forecastTile = GenerateForecastTile(model, isNight, uri, glanceFull, lockdetial, todayIndex, currentCity, settings);
            var list = new List<TileContent>();
            list.Add(nowTile);
            list.Add(noramlTile);
            list.Add(forecastTile);
            return list;
        }
Esempio n. 5
0
        private static TileContent GenerateForecastTile(HeWeatherModel model, bool isNight, Uri uri, string glanceFull, string lockdetial, int todayIndex, CitySettingsModel currentCity, SettingsModel settings)
        {
            var ctosConverter = new ConditiontoTextConverter();
            var ctoiConverter = new ConditiontoImageConverter();
            var forecaset = new TileContent()
            {
                Visual = new TileVisual()
                {
                    DisplayName = currentCity.City,
                    Branding = TileBranding.NameAndLogo,
                    LockDetailedStatus1 = currentCity.City + "  " + model.NowWeather.Temprature.Actual(settings.Preferences.TemperatureParameter) + "\r\n" + lockdetial,
                    TileLarge = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileText(),
                                new TileGroup()
                                {
                                    Children =
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,

                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].Date.ToString("ddd") : "",
                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 1 ? new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight?model.DailyForecast[todayIndex+1].Condition.NightCond:model.DailyForecast[todayIndex+1].Condition.DayCond,null,isNight,null)) : new TileImageSource(""),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },

                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].Date.ToString("ddd") : "",
                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 2 ? new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight?model.DailyForecast[todayIndex+2].Condition.NightCond:model.DailyForecast[todayIndex+2].Condition.DayCond,null,isNight,null)) : new TileImageSource(""),
                                                },
                                            }

                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,

                                        },
                                    }
                                },
                                new TileText(),
                                new TileGroup()
                                {
                                    Children =
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,

                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].Date.ToString("ddd") : "",
                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 3 ? new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight?model.DailyForecast[todayIndex+3].Condition.NightCond:model.DailyForecast[todayIndex+3].Condition.DayCond,null,isNight,null)) : new TileImageSource(""),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },

                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 4 ? model.DailyForecast[todayIndex+4].Date.ToString("ddd") : "",

                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 4 ?  new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight ? model.DailyForecast[todayIndex+4].Condition.NightCond : model.DailyForecast[todayIndex+4].Condition.DayCond, null, isNight, null)) : new TileImageSource(""),
                                                },
                                            }

                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children=
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 4 ? model.DailyForecast[todayIndex+4].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 4 ? model.DailyForecast[todayIndex+4].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,

                                        },
                                    }
                                }
                            }
                        }
                    },
                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileText()
                                {

                                },
                                new TileText()
                                {
                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].Date.ToString("ddd") : "",
                                    Align = TileTextAlign.Center
                                },
                                 new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                            }
                        }
                    },
                    TileWide = new TileBinding()
                    {

                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileGroup()
                                {
                                    Children =
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].Date.ToString("ddd") : "",

                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 1 ?  new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight ? model.DailyForecast[todayIndex+1].Condition.NightCond : model.DailyForecast[todayIndex+1].Condition.DayCond, null, isNight, null)) : new TileImageSource(""),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 1 ? model.DailyForecast[todayIndex+1].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                       new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].Date.ToString("ddd") : "",

                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 2 ?  new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight ? model.DailyForecast[todayIndex+2].Condition.NightCond : model.DailyForecast[todayIndex+2].Condition.DayCond, null, isNight, null)) : new TileImageSource(""),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 2 ? model.DailyForecast[todayIndex+2].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].Date.ToString("ddd") : "",

                                                },
                                                new TileImage()
                                                {
                                                    Source = model.DailyForecast.Length > todayIndex + 3 ?  new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(isNight ? model.DailyForecast[todayIndex+3].Condition.NightCond : model.DailyForecast[todayIndex+3].Condition.DayCond, null, isNight, null)) : new TileImageSource(""),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            TextStacking = TileTextStacking.Bottom,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].HighTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast.Length > todayIndex + 3 ? model.DailyForecast[todayIndex+3].LowTemp.Actual(settings.Preferences.TemperatureParameter) : "",
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                    }
                                },
                            }
                        }
                    }
                }
            };
            return forecaset;
        }
Esempio n. 6
0
        public static async Task<XmlDocument> CreateToast(HeWeatherModel model, CitySettingsModel currentCity, SettingsModel settings, DateTime DueTime)
        {
            var glance = Glance.GenerateGlanceDescription(model, false, settings.Preferences.TemperatureParameter, DueTime);
            var ctos = new ConditiontoTextConverter();

            var dueIndex = Array.FindIndex(model.DailyForecast, x =>
            {
                return x.Date.Date == DueTime.Date;
            });
            var uri = await settings.Immersive.GetCurrentBackgroundAsync(model.DailyForecast[dueIndex].Condition.DayCond, false);
            var loader = new ResourceLoader();
            var toast = new ToastContent()
            {
                Scenario = ToastScenario.Default,
                ActivationType = ToastActivationType.Foreground,
                Duration = ToastDuration.Long,
                Launch = currentCity.Id,
                Visual = new ToastVisual()
                {
                    TitleText = new ToastText()
                    {
                        Text = string.Format(loader.GetString("Today_Weather"), currentCity.City)
                    },
                    BodyTextLine1 = new ToastText()
                    {
                        Text = ctos.Convert(model.DailyForecast[dueIndex].Condition.DayCond, null, null, null) + ", "
                        + ((model.DailyForecast[dueIndex].HighTemp + model.DailyForecast[dueIndex].LowTemp) / 2).Actual(settings.Preferences.TemperatureParameter)
                    },
                    BodyTextLine2 = new ToastText()
                    {
                        Text = glance
                    },
                }
            };
            var xml = toast.GetXml();
            var e = xml.CreateElement("image");
            e.SetAttribute("placement", "hero");
            e.SetAttribute("src", uri.AbsoluteUri);
            var b = xml.GetElementsByTagName("binding");
            b.Item(0).AppendChild(e);
            return xml;
        }
Esempio n. 7
0
        private static TileContent GenerateNowTile(HeWeatherModel model, bool isNight, Uri uri, string glanceFull, string lockdetial, int todayIndex, CitySettingsModel currentCity, SettingsModel settings)
        {
            var ctosConverter = new ConditiontoTextConverter();
            var ctoiConverter = new ConditiontoImageConverter();
            var loader = new ResourceLoader();
            var now = new TileContent()
            {
                Visual = new TileVisual()
                {
                    LockDetailedStatus1 = currentCity.City + "  " + model.NowWeather.Temprature.Actual(settings.Preferences.TemperatureParameter) + "\r\n" + lockdetial,
                    DisplayName = currentCity.City,
                    Branding = TileBranding.NameAndLogo,
                    TileMedium = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileText(),
                                new TileGroup()
                                {
                                    Children =
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.NowWeather.Now.Condition,null,isNight,null)),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                        }
                                    }
                                },
                                new TileText()
                                {
                                    Text = model.NowWeather.Temprature.Actual(settings.Preferences.TemperatureParameter),
                                    Style = TileTextStyle.Body,
                                    Align = TileTextAlign.Center
                                }
                            }
                        },
                    },
                    TileLarge = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                            {
                                new TileText(),
                                new TileGroup()
                                {
                                    Children =
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 3,
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 2,
                                            Children =
                                            {
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.NowWeather.Now.Condition,null,isNight,null)),
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 3,
                                        }
                                    }
                                },
                                new TileText()
                                {
                                    Text = model.NowWeather.Temprature.Actual(settings.Preferences.TemperatureParameter),
                                    Style = TileTextStyle.Subheader,
                                    Align = TileTextAlign.Center
                                },
                                new TileText()
                                {
                                    Text = glanceFull,
                                    Align = TileTextAlign.Center,
                                    Style = TileTextStyle.CaptionSubtle,
                                    Wrap = true
                                }
                            }
                        }
                    },
                    TileSmall = new TileBinding()
                    {
                        Content = new TileBindingContentAdaptive()
                        {
                            TextStacking = TileTextStacking.Center,
                            Children =
                            {
                                new TileText()
                                {
                                    Text = model.NowWeather.Temprature.Actual(settings.Preferences.TemperatureParameter),
                                    Align = TileTextAlign.Center,
                                    Style = TileTextStyle.Body
                                }
                            }
                        }
                    },
                    TileWide = new TileBinding()
                    {
                        DisplayName = currentCity.City,
                        Branding = TileBranding.NameAndLogo,
                        Content = new TileBindingContentAdaptive()
                        {
                            BackgroundImage = uri == null ? null : (settings.Preferences.TransparentTile ? null : new TileBackgroundImage()
                            {
                                Source = new TileImageSource(uri.ToString()),
                                Overlay = 70
                            }),
                            Children =
                                       {
                                new TileGroup()
                                {
                                    Children=
                                    {
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].Date.ToString("ddd"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileImage()
                                                {
                                                    Source = new TileImageSource("Assets/Tile/" + (string)ctoiConverter.Convert(model.DailyForecast[todayIndex+1].Condition.DayCond,null,isNight,null))
                                                },
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 2,
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Center
                                                },
                                                new TileText()
                                                {
                                                    Text = (string)ctosConverter.Convert(model.DailyForecast[todayIndex+1].Condition.DayCond,null,null,null),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },

                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].HighTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].LowTemp.Actual(settings.Preferences.TemperatureParameter).ToString(),
                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Center
                                                }
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 1,
                                            Children =
                                            {
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Text = loader.GetString("ScaleText"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                                new TileText()
                                                {
                                                    Text = loader.GetString("HumText"),
                                                    Align = TileTextAlign.Center,
                                                    Style = TileTextStyle.CaptionSubtle
                                                },
                                            }
                                        },
                                        new TileSubgroup()
                                        {
                                            Weight = 2,
                                            TextStacking = TileTextStacking.Center,
                                            Children =
                                            {
                                                new TileText()
                                                {

                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Left
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].Wind.Speed.Actual(settings.Preferences.SpeedParameter) +
                                                    model.NowWeather.Wind.Speed.DanWei(settings.Preferences.SpeedParameter),
                                                    Align = TileTextAlign.Left,
                                                    Style = TileTextStyle.Caption
                                                },
                                                new TileText()
                                                {

                                                    Style = TileTextStyle.CaptionSubtle,
                                                    Align = TileTextAlign.Left
                                                },
                                                new TileText()
                                                {
                                                    Text = model.DailyForecast[todayIndex+1].Humidity.ToString() + "%",
                                                    Align = TileTextAlign.Left,
                                                    Style = TileTextStyle.Caption
                                                },
                                            }
                                        },
                                    }
                                }
                                       },
                        }
                    },
                }
            };
            return now;
        }
        private async Task FetchDataAsync()
        {
            await SearchExistingDataAsync();
            string resstr;
            if (currentCityModel.Id != null)
            {
                try
                {
                    if (!storedDatas.IsNullorEmpty())
                    {
                        resstr = storedDatas;
                        fetchresult = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                        return;
                    }
                    resstr = await Core.Models.Request.GetRequestAsync(settings, currentCityModel);
                    if (resstr.IsNullorEmpty())
                    {
                        await Task.Delay(1000);
                        this.OnFetchDataFailed(this, new FetchDataFailedEventArgs("Network_Error"));
                        return;
                    }
                    fetchresult = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                    if (fetchresult.Status != HeWeatherStatus.ok)
                    {
                        await Task.Delay(1000);
                        this.OnFetchDataFailed(this, new FetchDataFailedEventArgs("Service_Unavailable"));
                        return;
                    }
                    var task = ThreadPool.RunAsync(async (work) =>
                    {
                        await settings.Cities.SaveDataAsync(currentCityModel.Id, resstr, settings.Preferences.DataSource);
                        currentCityModel.Update();
                        if (settings.Cities.CurrentIndex != -1)
                        {
                            settings.Cities.SavedCities[settings.Cities.CurrentIndex] = currentCityModel;
                        }
                        else
                        {
                            settings.Cities.LocatedCity = currentCityModel;
                        }
                        settings.Cities.Save();
                    });
                    return;
                }
                catch (Exception)
                {
                    await Task.Delay(1000);
                    this.OnFetchDataFailed(this, new FetchDataFailedEventArgs("Service_Unavailable"));
                    return;
                }

            }
            else throw new NullReferenceException();
        }
Esempio n. 9
0
 internal static string GenerateLockDetailDescription(HeWeatherModel model, bool isNight, TemperatureParameter parameter, DateTime desiredDate)
 {
     var todayIndex = Array.FindIndex(model.DailyForecast, x =>
     {
         return x.Date.Date == desiredDate.Date;
     });
     if (isNight && desiredDate.Hour < 12)
     {
         todayIndex--;
     }
     if (todayIndex < 0)
     {
         todayIndex = 0;
     }
     var 主语 = model.NowWeather.Now.Condition;
     string zhuyu = loader.GetString("xianzai");
     if (Tools.Random.Next(200) >= 100)
     {
         if (isNight)
         {
             主语 = model.DailyForecast[todayIndex].Condition.NightCond;
             zhuyu = loader.GetString("wanjian");
         }
         else
         {
             主语 = model.DailyForecast[todayIndex].Condition.DayCond;
             zhuyu = loader.GetString("jintian");
         }
     }
     string binyu;
     StringBuilder decoration = new StringBuilder();
     if (Tools.Random.Next(200) >= 100)
     {
         if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius < 0)
         {
             decoration.Append(wendudi.SelectRandomString() + ", ");
         }
         else if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius > 25)
         {
             decoration.Append(wendugao.SelectRandomString() + ", ");
         }
         if (Tools.Random.Next(200) >= 100 && model.DailyForecast[todayIndex].Humidity > 80)
         {
             decoration.Append(shiduda[0] + ", ");
         }
         if (model.NowWeather.Visibility != null)
             if (Tools.Random.Next(200) >= 100 && model.NowWeather.Visibility.KM < 0.5)
             {
                 decoration.Append(nengjiandudi[0] + ", ");
             }
         if (Tools.Random.Next(200) >= 100)
             switch (主语)
             {
                 case WeatherCondition.unknown:
                     return loader.GetString("unknown_weather");
                 case WeatherCondition.sunny:
                 case WeatherCondition.few_clouds:
                 case WeatherCondition.partly_cloudy:
                 case WeatherCondition.calm:
                 case WeatherCondition.light_breeze:
                 case WeatherCondition.moderate:
                 case WeatherCondition.fresh_breeze:
                     decoration.Append(haotianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.overcast:
                 case WeatherCondition.cloudy:
                 case WeatherCondition.windy:
                     break;
                 case WeatherCondition.strong_breeze:
                 case WeatherCondition.high_wind:
                     break;
                 case WeatherCondition.gale:
                 case WeatherCondition.strong_gale:
                 case WeatherCondition.storm:
                 case WeatherCondition.violent_storm:
                 case WeatherCondition.hurricane:
                 case WeatherCondition.tornado:
                 case WeatherCondition.tropical_storm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.shower_rain:
                     break;
                 case WeatherCondition.heavy_shower_rain:
                 case WeatherCondition.thundershower:
                 case WeatherCondition.heavy_thunderstorm:
                 case WeatherCondition.hail:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.light_rain:
                 case WeatherCondition.moderate_rain:
                     break;
                 case WeatherCondition.heavy_rain:
                 case WeatherCondition.extreme_rain:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.drizzle_rain:
                     break;
                 case WeatherCondition.storm_rain:
                 case WeatherCondition.heavy_storm_rain:
                 case WeatherCondition.severe_storm_rain:
                 case WeatherCondition.freezing_rain:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.light_snow:
                     break;
                 case WeatherCondition.moderate_snow:
                 case WeatherCondition.heavy_snow:
                 case WeatherCondition.snowstorm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.sleet:
                 case WeatherCondition.rain_snow:
                 case WeatherCondition.shower_snow:
                 case WeatherCondition.snow_flurry:
                     break;
                 case WeatherCondition.mist:
                     break;
                 case WeatherCondition.foggy:
                 case WeatherCondition.haze:
                 case WeatherCondition.sand:
                 case WeatherCondition.dust:
                 case WeatherCondition.volcanic_ash:
                 case WeatherCondition.duststorm:
                 case WeatherCondition.sandstorm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.hot:
                 case WeatherCondition.cold:
                     break;
                 default:
                     break;
             }
     }
     switch (主语)
     {
         case WeatherCondition.unknown:
             return loader.GetString("unknown_weather");
         case WeatherCondition.sunny:
             binyu = sunny.SelectRandomString();
             break;
         case WeatherCondition.cloudy:
             binyu = cloudy.SelectRandomString();
             break;
         case WeatherCondition.few_clouds:
             binyu = few_clouds.SelectRandomString();
             break;
         case WeatherCondition.partly_cloudy:
             binyu = partly_cloudy.SelectRandomString();
             break;
         case WeatherCondition.overcast:
             binyu = overcast.SelectRandomString();
             break;
         case WeatherCondition.windy:
             binyu = windy.SelectRandomString();
             break;
         case WeatherCondition.calm:
         case WeatherCondition.light_breeze:
         case WeatherCondition.moderate:
         case WeatherCondition.fresh_breeze:
             binyu = breeze.SelectRandomString();
             break;
         case WeatherCondition.strong_breeze:
         case WeatherCondition.high_wind:
         case WeatherCondition.gale:
         case WeatherCondition.strong_gale:
             binyu = gale.SelectRandomString();
             break;
         case WeatherCondition.storm:
         case WeatherCondition.violent_storm:
         case WeatherCondition.hurricane:
         case WeatherCondition.tornado:
         case WeatherCondition.tropical_storm:
             binyu = storm.SelectRandomString();
             break;
         case WeatherCondition.shower_rain:
         case WeatherCondition.heavy_shower_rain:
             binyu = shower.SelectRandomString();
             break;
         case WeatherCondition.thundershower:
         case WeatherCondition.heavy_thunderstorm:
             binyu = thundershower.SelectRandomString();
             break;
         case WeatherCondition.hail:
             binyu = hail.SelectRandomString();
             break;
         case WeatherCondition.drizzle_rain:
         case WeatherCondition.light_rain:
         case WeatherCondition.moderate_rain:
             binyu = moderate_rain.SelectRandomString();
             break;
         case WeatherCondition.heavy_rain:
         case WeatherCondition.extreme_rain:
             binyu = heavy_rain.SelectRandomString();
             break;
         case WeatherCondition.storm_rain:
         case WeatherCondition.heavy_storm_rain:
         case WeatherCondition.severe_storm_rain:
             binyu = storm.SelectRandomString();
             break;
         case WeatherCondition.freezing_rain:
             binyu = freezing_rain.SelectRandomString();
             break;
         case WeatherCondition.light_snow:
         case WeatherCondition.moderate_snow:
             binyu = moderate_snow.SelectRandomString();
             break;
         case WeatherCondition.heavy_snow:
             binyu = heavy_snow.SelectRandomString();
             break;
         case WeatherCondition.snowstorm:
             binyu = snowstorm.SelectRandomString();
             break;
         case WeatherCondition.sleet:
         case WeatherCondition.rain_snow:
             binyu = sleet.SelectRandomString();
             break;
         case WeatherCondition.shower_snow:
         case WeatherCondition.snow_flurry:
             binyu = shower_snow.SelectRandomString();
             break;
         case WeatherCondition.mist:
             binyu = mist.SelectRandomString();
             break;
         case WeatherCondition.foggy:
             binyu = foggy.SelectRandomString();
             break;
         case WeatherCondition.haze:
             binyu = haze.SelectRandomString();
             break;
         case WeatherCondition.sand:
         case WeatherCondition.dust:
             binyu = dust.SelectRandomString();
             break;
         case WeatherCondition.volcanic_ash:
         case WeatherCondition.duststorm:
         case WeatherCondition.sandstorm:
             binyu = duststorm.SelectRandomString();
             break;
         case WeatherCondition.hot:
             binyu = loader.GetString("bianre");
             break;
         case WeatherCondition.cold:
             binyu = loader.GetString("bianleng");
             break;
         default: return loader.GetString("unknown_weather");
     }
     string nowtemp;
     string tomorrowtemp;
     switch (parameter)
     {
         case TemperatureParameter.Celsius:
             nowtemp = model.DailyForecast[todayIndex].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex].HighTemp.Celsius + '°';
             tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + '°';
             break;
         case TemperatureParameter.Fahrenheit:
             nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Fahrenheit + '°';
             tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Fahrenheit + '°';
             break;
         case TemperatureParameter.Kelvin:
             nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 0].HighTemp.Kelvin + "K";
             tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 1].HighTemp.Kelvin + "K";
             break;
         default:
             nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Celsius + "°";
             tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + "°";
             break;
     }
     string tomorrowcondition;
     var converter = new ConditiontoTextConverter();
     tomorrowcondition = (string)converter.Convert(model.DailyForecast[todayIndex + 1].Condition.DayCond, null, null, null);
     return string.Format(loader.GetString("LockDetail"), zhuyu, binyu, decoration, nowtemp, tomorrowcondition, tomorrowtemp);
 }
Esempio n. 10
0
 public static string GenerateShortDescription(HeWeatherModel model, bool isNight)
 {
     var utcOffset = model.Location.UpdateTime - model.Location.UtcTime;
     var current = DateTimeHelper.ReviseLoc(utcOffset);
     var todayIndex = Array.FindIndex(model.DailyForecast, x =>
     {
         return x.Date.Date == current.Date;
     });
     if (isNight && current.Hour < 12)
     {
         todayIndex--;
     }
     if (todayIndex < 0)
     {
         todayIndex = 0;
     }
     var 主语 = model.NowWeather.Now.Condition;
     string zhuyu = loader.GetString("xianzai");
     if (Tools.Random.Next(200) >= 100)
     {
         if (isNight)
         {
             主语 = model.DailyForecast[todayIndex].Condition.NightCond;
             zhuyu = loader.GetString("wanjian");
         }
         else
         {
             主语 = model.DailyForecast[todayIndex].Condition.DayCond;
             zhuyu = loader.GetString("jintian");
         }
     }
     string binyu;
     StringBuilder decoration = new StringBuilder();
     if (Tools.Random.Next(200) >= 100)
     {
         if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius < 0)
         {
             decoration.Append(wendudi.SelectRandomString() + ", ");
         }
         else if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius > 25)
         {
             decoration.Append(wendugao.SelectRandomString() + ", ");
         }
         if (Tools.Random.Next(200) >= 100 && model.DailyForecast[todayIndex].Humidity > 80)
         {
             decoration.Append(shiduda[0] + ", ");
         }
         if (model.NowWeather.Visibility != null)
             if (Tools.Random.Next(200) >= 100 && model.NowWeather.Visibility.KM < 0.5)
             {
                 decoration.Append(nengjiandudi[0] + ", ");
             }
         if (Tools.Random.Next(200) >= 100)
             switch (主语)
             {
                 case WeatherCondition.unknown:
                     return loader.GetString("unknown_weather");
                 case WeatherCondition.sunny:
                 case WeatherCondition.few_clouds:
                 case WeatherCondition.partly_cloudy:
                 case WeatherCondition.calm:
                 case WeatherCondition.light_breeze:
                 case WeatherCondition.moderate:
                 case WeatherCondition.fresh_breeze:
                     decoration.Append(haotianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.overcast:
                 case WeatherCondition.cloudy:
                 case WeatherCondition.windy:
                     break;
                 case WeatherCondition.strong_breeze:
                 case WeatherCondition.high_wind:
                     break;
                 case WeatherCondition.gale:
                 case WeatherCondition.strong_gale:
                 case WeatherCondition.storm:
                 case WeatherCondition.violent_storm:
                 case WeatherCondition.hurricane:
                 case WeatherCondition.tornado:
                 case WeatherCondition.tropical_storm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.shower_rain:
                     break;
                 case WeatherCondition.heavy_shower_rain:
                 case WeatherCondition.thundershower:
                 case WeatherCondition.heavy_thunderstorm:
                 case WeatherCondition.hail:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.light_rain:
                 case WeatherCondition.moderate_rain:
                     break;
                 case WeatherCondition.heavy_rain:
                 case WeatherCondition.extreme_rain:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.drizzle_rain:
                     break;
                 case WeatherCondition.storm_rain:
                 case WeatherCondition.heavy_storm_rain:
                 case WeatherCondition.severe_storm_rain:
                 case WeatherCondition.freezing_rain:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.light_snow:
                     break;
                 case WeatherCondition.moderate_snow:
                 case WeatherCondition.heavy_snow:
                 case WeatherCondition.snowstorm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.sleet:
                 case WeatherCondition.rain_snow:
                 case WeatherCondition.shower_snow:
                 case WeatherCondition.snow_flurry:
                     break;
                 case WeatherCondition.mist:
                     break;
                 case WeatherCondition.foggy:
                 case WeatherCondition.haze:
                 case WeatherCondition.sand:
                 case WeatherCondition.dust:
                 case WeatherCondition.volcanic_ash:
                 case WeatherCondition.duststorm:
                 case WeatherCondition.sandstorm:
                     decoration.Append(huaitianqi.SelectRandomString() + ", ");
                     break;
                 case WeatherCondition.hot:
                 case WeatherCondition.cold:
                     break;
                 default:
                     break;
             }
         if (decoration.ToString().EndsWith(", "))
         {
             decoration.Remove(decoration.Length - 2, 2);
         }
     }
     switch (主语)
     {
         case WeatherCondition.unknown:
             return loader.GetString("unknown_weather");
         case WeatherCondition.sunny:
             binyu = sunny.SelectRandomString();
             break;
         case WeatherCondition.cloudy:
             binyu = cloudy.SelectRandomString();
             break;
         case WeatherCondition.few_clouds:
             binyu = few_clouds.SelectRandomString();
             break;
         case WeatherCondition.partly_cloudy:
             binyu = partly_cloudy.SelectRandomString();
             break;
         case WeatherCondition.overcast:
             binyu = overcast.SelectRandomString();
             break;
         case WeatherCondition.windy:
             binyu = windy.SelectRandomString();
             break;
         case WeatherCondition.calm:
         case WeatherCondition.light_breeze:
         case WeatherCondition.moderate:
         case WeatherCondition.fresh_breeze:
             binyu = breeze.SelectRandomString();
             break;
         case WeatherCondition.strong_breeze:
         case WeatherCondition.high_wind:
         case WeatherCondition.gale:
         case WeatherCondition.strong_gale:
             binyu = gale.SelectRandomString();
             break;
         case WeatherCondition.storm:
         case WeatherCondition.violent_storm:
         case WeatherCondition.hurricane:
         case WeatherCondition.tornado:
         case WeatherCondition.tropical_storm:
             binyu = storm.SelectRandomString();
             break;
         case WeatherCondition.shower_rain:
         case WeatherCondition.heavy_shower_rain:
             binyu = shower.SelectRandomString();
             break;
         case WeatherCondition.thundershower:
         case WeatherCondition.heavy_thunderstorm:
             binyu = thundershower.SelectRandomString();
             break;
         case WeatherCondition.hail:
             binyu = hail.SelectRandomString();
             break;
         case WeatherCondition.drizzle_rain:
         case WeatherCondition.light_rain:
         case WeatherCondition.moderate_rain:
             binyu = moderate_rain.SelectRandomString();
             break;
         case WeatherCondition.heavy_rain:
         case WeatherCondition.extreme_rain:
             binyu = heavy_rain.SelectRandomString();
             break;
         case WeatherCondition.storm_rain:
         case WeatherCondition.heavy_storm_rain:
         case WeatherCondition.severe_storm_rain:
             binyu = storm.SelectRandomString();
             break;
         case WeatherCondition.freezing_rain:
             binyu = freezing_rain.SelectRandomString();
             break;
         case WeatherCondition.light_snow:
         case WeatherCondition.moderate_snow:
             binyu = moderate_snow.SelectRandomString();
             break;
         case WeatherCondition.heavy_snow:
             binyu = heavy_snow.SelectRandomString();
             break;
         case WeatherCondition.snowstorm:
             binyu = snowstorm.SelectRandomString();
             break;
         case WeatherCondition.sleet:
         case WeatherCondition.rain_snow:
             binyu = sleet.SelectRandomString();
             break;
         case WeatherCondition.shower_snow:
         case WeatherCondition.snow_flurry:
             binyu = shower_snow.SelectRandomString();
             break;
         case WeatherCondition.mist:
             binyu = mist.SelectRandomString();
             break;
         case WeatherCondition.foggy:
             binyu = foggy.SelectRandomString();
             break;
         case WeatherCondition.haze:
             binyu = haze.SelectRandomString();
             break;
         case WeatherCondition.sand:
         case WeatherCondition.dust:
             binyu = dust.SelectRandomString();
             break;
         case WeatherCondition.volcanic_ash:
         case WeatherCondition.duststorm:
         case WeatherCondition.sandstorm:
             binyu = duststorm.SelectRandomString();
             break;
         case WeatherCondition.hot:
             binyu = loader.GetString("bianre");
             break;
         case WeatherCondition.cold:
             binyu = loader.GetString("bianleng");
             break;
         default: return loader.GetString("unknown_weather");
     }
     return string.Format(loader.GetString("Glance"), zhuyu, binyu, decoration);
 }