Example #1
0
 public static async Task<string> GetRequestAsync(SettingsModel settings, CitySettingsModel city)
 {
     try
     {
         return await GetRequestAsync(settings, city.Id, city.Longitude, city.Latitude, city.ZMW);
     }
     catch (Exception)
     {
         return null;
     }
 }
 public static SettingsModel Get()
 {
     var s = new SettingsModel();
     s.Cities = Cities.Get();
     s.Immersive = Immersive.Get();
     s.Preferences = Preferences.Get();
     var init = LocalSettingsHelper.ReadSettingsValue("Inited");
     if (init == null)
     {
         s.Inited = false;
     }
     else
     {
         s.Inited = true;
     }
     return s;
 }
Example #3
0
        public static async Task UpdateSubTiles(SettingsModel settings)
        {
            var tiles = await SecondaryTile.FindAllForPackageAsync();
            var list = tiles.ToList();
            foreach (var item in settings.Cities.SavedCities)
            {
                try
                {
                    var tile = list.Find(x =>
                    {
                        return x.TileId == item.Id;
                    });
                    if (tile != null)
                    {
                        string resstr = await Request.GetRequestAsync(settings, item);
                        if (!resstr.IsNullorEmpty())
                        {
                            var fetchresult = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                            if (fetchresult == null || fetchresult.DailyForecast == null || fetchresult.HourlyForecast == null)
                            {
                                return;
                            }
                            var utcOffset = fetchresult.Location.UpdateTime - fetchresult.Location.UtcTime;
                            var current = DateTimeHelper.ReviseLoc(utcOffset);
                            try
                            {
                                Sender.CreateSubTileNotification(await Generator.CreateAll(item, fetchresult, current), item.Id);
                            }
                            catch (Exception)
                            { }
                        }
                    }
                }
                catch (Exception)
                {

                }

            }

        }
Example #4
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();
 }
Example #5
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;
        }
Example #6
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;
        }
Example #7
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;
        }
Example #8
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 void InitialConverterParameter(SettingsModel settings)
 {
     TemperatureDecoratorConverter.ChangeParameter(settings.Preferences.TemperatureParameter);
     DateTimeConverter.ChangeParameter(settings.Preferences.GetForecastFormat());
     var p = settings.Preferences.GetHourlyFormat();
     HourMinuteConverter.ChangeParameter(p);
     UpdateTimeConverter.ChangeParameter(p);
     RefreshCompleteConverter.ChangeParameter(p);
     WindSpeedConverter.ChangeParameter(settings.Preferences.WindParameter, settings.Preferences.SpeedParameter);
     PressureConverter.ChangeParameter(settings.Preferences.PressureParameter);
     VisibilityConverter.ChangeParameter(settings.Preferences.LengthParameter);
     ImmersiveHourConverter.ChangeParameter(settings.Preferences.GetImmersiveHourFormat());
     ImmersiveMinConverter.ChangeParameter(settings.Preferences.GetImmersiveMinFormat());
 }
 private void ReadSettings()
 {
     settings = SettingsModel.Current;
     currentCityModel = settings.Cities.GetCurrentCity();
     InitialConverterParameter(settings);
 }
        private async Task Init(SettingsModel settings, CitySettingsModel currentCity)
        {
            string resstr = await Request.GetRequestAsync(settings, currentCity);
            if (!resstr.IsNullorEmpty())
            {
                var fetchresult = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                if (fetchresult == null || fetchresult.DailyForecast == null || fetchresult.HourlyForecast == null)
                {
                    return;
                }
                var utcOffset = fetchresult.Location.UpdateTime - fetchresult.Location.UtcTime;
                var current = DateTimeHelper.ReviseLoc(utcOffset);
                try
                {
                    Sender.CreateMainTileQueue(await Generator.CreateAll(currentCity, fetchresult, current));
                }
                catch (Exception)
                {

                }

                try
                {
                    if (UserProfilePersonalizationSettings.IsSupported() && settings.Preferences.SetWallPaper)
                    {
                        var todayIndex = Array.FindIndex(fetchresult.DailyForecast, x =>
                        {
                            return x.Date.Date == current.Date;
                        });
                        if (current.Hour <= 7)
                        {
                            todayIndex--;
                        }
                        if (todayIndex < 0)
                        {
                            todayIndex = 0;
                        }
                        TimeSpan sunRise, sunSet;
                        if (fetchresult.DailyForecast[todayIndex].SunRise == default(TimeSpan) || fetchresult.DailyForecast[todayIndex].SunSet == default(TimeSpan))
                        {
                            sunRise = Core.LunarCalendar.SunRiseSet.GetRise(new Models.Location(currentCity.Latitude, currentCity.Longitude), current);
                            sunSet = Core.LunarCalendar.SunRiseSet.GetSet(new Models.Location(currentCity.Latitude, currentCity.Longitude), current);
                        }
                        else
                        {
                            sunRise = fetchresult.DailyForecast[todayIndex].SunRise;
                            sunSet = fetchresult.DailyForecast[todayIndex].SunSet;
                        }
                        var file = await FileIOHelper.GetFilebyUriAsync(await settings.Immersive.GetCurrentBackgroundAsync(fetchresult.NowWeather.Now.Condition, WeatherModel.CalculateIsNight(current, sunRise, sunSet)));
                        var lFile = await FileIOHelper.CreateWallPaperFileAsync(Guid.NewGuid().ToString() + ".png");
                        var d = PointerDevice.GetPointerDevices();
                        var m = d.ToArray();
                        var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                        var size = new Size(m[0].PhysicalDeviceRect.Width, m[0].PhysicalDeviceRect.Height);
                        var ratio = size.Height / size.Width;
                        var cropSize = new Size();
                        double scale;
                        var startPoint = new Point();
                        using (var stream = await file.OpenReadAsync())
                        {
                            var bitmap = new BitmapImage();
                            await bitmap.SetSourceAsync(stream);
                            var width = bitmap.PixelWidth;
                            var height = bitmap.PixelHeight;
                            var center = new Point(width / 2, height / 2);
                            if (width * ratio >= height)
                            {
                                cropSize.Width = height / ratio;
                                cropSize.Height = height;
                                scale = size.Height / height;
                            }
                            else
                            {
                                cropSize.Width = width;
                                cropSize.Height = width * ratio;
                                scale = size.Width / width;
                            }

                            startPoint.X = center.X - cropSize.Width / 2;
                            startPoint.Y = center.Y - cropSize.Height / 2;
                        }
                        await ImagingHelper.CropandScaleAsync(file, lFile, startPoint, cropSize, scale);
                        var uc = await ImagingHelper.SetWallpaperAsync(lFile);
                    }
                }
                catch (Exception)
                {
                }

                if (settings.Preferences.EnableMorning)
                {
                    var shu1 = settings.Preferences.MorningNoteTime.TotalHours;

                    var tomorrow8 = DateTime.Now.Hour > shu1 ? (DateTime.Today.AddDays(1)).AddHours(shu1) : (DateTime.Today.AddHours(shu1));

                    try
                    {
                        Sender.CreateScheduledToastNotification(await (Generator.CreateToast(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(tomorrow8, utcOffset))), tomorrow8, "MorningToast");
                    }
                    catch (Exception)
                    {

                    }
                }
                if (settings.Preferences.EnableEvening)
                {
                    var shu2 = settings.Preferences.EveningNoteTime.TotalHours;
                    var tomorrow20 = DateTime.Now.Hour > shu2 ? (DateTime.Today.AddDays(1)).AddHours(shu2) : (DateTime.Today.AddHours(shu2));
                    try
                    {
                        Sender.CreateScheduledToastNotification(await (Generator.CreateToast(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(tomorrow20, utcOffset))), tomorrow20, "EveningToast");
                    }
                    catch (Exception)
                    {

                    }
                }
                if (settings.Preferences.EnableAlarm)
                {
                    if (!fetchresult.Alarms.IsNullorEmpty() && (DateTime.Now - settings.Preferences.LastAlertTime).TotalDays > 1)
                    {
                        Sender.CreateBadge(Generator.GenerateAlertBadge());
                        Sender.CreateToast(Generator.CreateAlertToast(fetchresult, currentCity).GetXml());
                    }
                    else
                    {
                        Sender.ClearBadge();
                    }
                    var str = Generator.CalculateWeatherAlarm(fetchresult, currentCity, settings, DateTimeHelper.ReviseLoc(DateTime.Now, utcOffset));
                    if (!str.IsNullorEmpty() && str.Length > 1 && (DateTime.Now - settings.Preferences.LastAlarmTime).TotalDays > 1)
                    {
                        Sender.CreateToast(Generator.CreateAlarmToast(str, currentCity).GetXml());
                    }
                }
                await settings.Cities.SaveDataAsync(currentCity.Id, resstr, settings.Preferences.DataSource);
                currentCity.Update();
                if (settings.Cities.CurrentIndex != -1)
                {
                    settings.Cities.SavedCities[settings.Cities.CurrentIndex] = currentCity;
                }
                else
                {
                    settings.Cities.LocatedCity = currentCity;
                }
                settings.Cities.Save();
            }
        }
        private async Task CalcPosition(Geoposition pos, List<CityInfo> citys, SettingsModel settings)
        {
            try
            {
                var final = await Models.Location.ReverseGeoCode((float)pos.Coordinate.Point.Position.Latitude, (float)pos.Coordinate.Point.Position.Longitude, SettingsModel.Current.Cities.Routes, citys);
                if (settings.Cities.LocatedCity != null && settings.Cities.LocatedCity.Id == final.Id)
                {
                    if (settings.Cities.LocatedCity.Latitude == 0)
                    {
                        settings.Cities.LocatedCity.Latitude = (float)pos.Coordinate.Point.Position.Latitude;
                        settings.Cities.LocatedCity.Longitude = (float)pos.Coordinate.Point.Position.Longitude;
                    }
                }
                else
                {
                    var p = final;
                    p.Location = new Models.Location((float)pos.Coordinate.Point.Position.Latitude, (float)pos.Coordinate.Point.Position.Longitude);
                    settings.Cities.LocatedCity = new Models.Settings.CitySettingsModel(p);
                }
            }
            catch (Exception)
            {
                FailtoPos();
            }
            finally
            {
                citys.Clear();
                citys = null;
                settings.Cities.Save();
            }

        }
 private void GetCityListandCompelte(SettingsModel settings)
 {
     var cs = new List<string>();
     if (settings.Cities.LocatedCity != null && !settings.Cities.LocatedCity.City.IsNullorEmpty())
     {
         cs.Add(settings.Cities.LocatedCity.City);
     }
     if (!settings.Cities.SavedCities.IsNullorEmpty())
         cs.AddRange(settings.Cities.SavedCities.Select((a, b) =>
         {
             return a.City;
         }));
     SplashComplete(cs);
 }
Example #14
0
        public static async Task<string> GetRequestAsync(SettingsModel settings, string id, float lon, float lat, string zmw)
        {
            try
            {
                if (WebHelper.IsInternet())
                {
                    var keys = Key.key.Split(new string[] { ":|:" }, StringSplitOptions.RemoveEmptyEntries);
                    var param = new string[] { "cityid=" + id };
                    string resstr;
                    switch (settings.Preferences.DataSource)
                    {
                        case DataSource.HeWeather:
                            resstr = await BaiduRequestHelper.RequestWithKeyAsync("http://apis.baidu.com/heweather/pro/weather", param, keys[0]);
                            break;
                        case DataSource.Caiyun:
                            resstr = await CaiyunRequestHelper.RequestNowWithKeyAsync(lon, lat, keys[1]);
                            resstr += ":|:";
                            resstr += await CaiyunRequestHelper.RequestForecastWithKeyAsync(lon, lat, keys[1]);
                            break;
                        case DataSource.Wunderground:

                            if (!zmw.IsNullorEmpty())
                            {
                                resstr = await WundergroundRequestHelper.GetResult(keys[2], zmw);
                            }
                            else
                            {
                                resstr = await GeoLookup(lat, lon);
                                if (resstr.Length < 40)
                                {
                                    if (settings.Cities.LocatedCity != null && settings.Cities.LocatedCity.Id == id)
                                    {
                                        settings.Cities.LocatedCity.RequestZMW(resstr);
                                        zmw = settings.Cities.LocatedCity.ZMW;
                                    }
                                    else if (!settings.Cities.SavedCities.IsNullorEmpty())
                                    {
                                        foreach (var item in settings.Cities.SavedCities)
                                        {
                                            if (item.Id == id)
                                            {
                                                item.RequestZMW(resstr);
                                                zmw = item.ZMW;
                                            }
                                        }
                                    }
                                    settings.Cities.Save();
                                    resstr = await WundergroundRequestHelper.GetResult(keys[2], zmw);
                                }
                            }
                            break;
                        default:
                            resstr = null;
                            break;
                    }
                    return resstr;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
 private void InitialConverterParameter(SettingsModel settings)
 {
     TemperatureDecoratorConverter.ChangeParameter(settings.Preferences.TemperatureParameter);
     DateTimeConverter.ChangeParameter(settings.Preferences.GetForecastFormat());
     var p = settings.Preferences.GetHourlyFormat();
     HourMinuteConverter.ChangeParameter(p);
     UpdateTimeConverter.ChangeParameter(p);
     RefreshCompleteConverter.ChangeParameter(p);
     WindSpeedConverter.ChangeParameter(settings.Preferences.WindParameter, settings.Preferences.SpeedParameter);
     PressureConverter.ChangeParameter(settings.Preferences.PressureParameter);
     VisibilityConverter.ChangeParameter(settings.Preferences.LengthParameter);
     ImmersiveHourConverter.ChangeParameter(settings.Preferences.GetImmersiveHourFormat());
     ImmersiveMinConverter.ChangeParameter(settings.Preferences.GetImmersiveMinFormat());
     ScrollViewerConverter.WeatherCanvasHeight = settings.Preferences.NowPanelHeight * 2;
     FontSizeConverter.FIXED_TITLE_FONTSIZE = (ScrollViewerConverter.WeatherCanvasHeight - 192) / 648 * 60 + 48;
 }