Пример #1
0
        public async static Task ExecuteWeatherRecipes()
        {
            try
            {
                await WeatherHelper.ReadWeather();

                if (!WeatherHelper.WeatherRead)
                {
                    return;
                }

                var dropRecipe = Repository.Instance.GetRecipe("Temperature Drop");
                if (dropRecipe != null && dropRecipe.IsAvailable && dropRecipe.IsEnabled)
                {
                    if (WeatherHelper.CurrentWeather != null && WeatherHelper.CurrentWeather.Temperature <= Constants.TEMPERATURE_ALERT_THRESHOLD)
                    {
                        var arguments = new Dictionary <string, object>()
                        {
                            { "HeaderText", "Weather Alert!" },
                            { "AlertText", "Temperature has dropped below " + Constants.TEMPERATURE_ALERT_THRESHOLD + " degree Celsius." },
                            { "Persistent", false },
                            { "Delay", 500 }
                        };
                        SendNotification(dropRecipe, arguments);
                    }
                }

                var rainRecipe = Repository.Instance.GetRecipe("Rain");
                if (rainRecipe != null && rainRecipe.IsAvailable && rainRecipe.IsEnabled)
                {
                    if (WeatherHelper.CurrentWeather != null && WeatherHelper.CurrentWeather.Forecast.ToLower().Contains("rain"))
                    {
                        var arguments = new Dictionary <string, object>()
                        {
                            { "HeaderText", "Love soaking in rain?" },
                            { "AlertText", "If NO, pack your umbrella now. There is a rain forecast." },
                            { "Persistent", true },
                            { "Delay", 500 }
                        };
                        SendNotification(rainRecipe, arguments);
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }