private WeatherConditions GetResult(string json, Location location)
        {
            var weatherDto = JsonConvert.DeserializeObject <WeatherDto>(json);

            if (weatherDto == null)
            {
                return(null);
            }

            var weatherConditions = new WeatherConditions()
            {
                Title          = weatherDto.Title,
                Description    = weatherDto.Description,
                TemperatureC   = (int)Math.Ceiling(TemperatureConverter.KelvinToCelsius(weatherDto.Main.Temperature)),
                TemperatureF   = (int)Math.Ceiling(TemperatureConverter.KelvinToFahrenheit(weatherDto.Main.Temperature)),
                Icon           = Icons.GetCssClass(weatherDto.IconCode),
                Location       = location.City,
                CountryCode    = location.CountryCode,
                UsesFahrenheit = location.UsesFahrenheit,
                Service        = "OpenWeatherMap",
                ServiceUrl     = "http://openweathermap.org/"
            };

            return(weatherConditions);
        }
Esempio n. 2
0
 //Constructor
 internal ClimatesOfFerngillApi(SDVMoon moon, WeatherConditions cond, StaminaDrain manager, WeatherConfig config)
 {
     Termina           = moon;
     CurrentConditions = cond;
     StaminaManager    = manager;
     ModConfig         = config;
 }
Esempio n. 3
0
        protected static Bitmap GetWeatherBitmap(WeatherConditions conditionsIn)
        {
            switch (conditionsIn)
            {
            case WeatherConditions.Clear:
                return(new Bitmap(Properties.Resources.weather_clear));

            case WeatherConditions.Overcast:
                return(new Bitmap(Properties.Resources.weather_overcast));

            case WeatherConditions.PartlyCloudy:
                return(new Bitmap(Properties.Resources.weather_few_clouds));

            case WeatherConditions.Rain:
                return(new Bitmap(Properties.Resources.weather_showers));

            case WeatherConditions.Storm:
                return(new Bitmap(Properties.Resources.weather_storm));

            case WeatherConditions.Snow:
                return(new Bitmap(Properties.Resources.weather_snow));

            default:
                return(new Bitmap(Properties.Resources.weather_severe_alert));
            }
        }
Esempio n. 4
0
        public void SetDefaults()
        {
            version         = 1;
            type            = "basic";
            timeScale       = 1;
            beatsPerMinute  = 120;
            pulsesPerBeat   = 4;
            durationPerBeat = 4;
            swing           = 1;

            sequenceQueue = new List <Sequence>();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<location id=\"defaultLocation\" lat=\"0\" lon=\"0\">Default Location</location>");
            currentLocation = new Location(doc.DocumentElement, this);

            currentTemperature      = 24f;
            currentTemperatureUnits = TemperatureUnits.CELSIUS;

            currentWeather = WeatherConditions.CLEAR;

            currentDate = DateTime.Now;

            backColor = Color.white;
            midColor  = Color.gray;
            foreColor = Color.black;
        }
Esempio n. 5
0
        public void GetWeather(string city)
        {
            WeatherConditions weatherConditions = new WeatherConditions();

            var client = new OpenWeatherAPI.OpenWeatherAPI("d9a69d574ef7c5bdccdc52b2b0b13458");

            var results = client.Query(city);

            if (client != null)
            {
                weatherConditions.CurentTemperature        = results.Main.Temperature.CelsiusCurrent;
                weatherConditions.Direction                = results.Wind.Direction;
                weatherConditions.MaxTemperature           = results.Main.Temperature.CelsiusMaximum;
                weatherConditions.MinTemperature           = results.Main.Temperature.CelsiusMaximum;
                weatherConditions.SeaLevel                 = results.Main.SeaLevelAtm;
                weatherConditions.WindSpeedMetersPerSecond = results.Wind.SpeedMetersPerSecond;
                //weatherConditions.RainLevel = results.Rain.H3;
                weatherConditions.Degri = results.Wind.Degree;
                weatherConditionsOld    = weatherConditions;
                weatherConditions.Cyti  = city;
                countGet += 1;
                weatherConditions.CountCondition = countGet;
                EventNewWeatherConditions(weatherConditions);
            }
        }
Esempio n. 6
0
        public WeatherConditions GetWeatherForCityAndCountry(string cityName, string countryCode)
        {
            var cityCountry = $"{cityName},{countryCode}";
            var weather     = _weatherCacheProvider.WeatherCacheDictionary.ContainsKey(cityCountry) ? _weatherCacheProvider.WeatherCacheDictionary[cityCountry] : null;

            if (weather == null)
            {
                try
                {
                    var url = $"http://api.openweathermap.org/data/2.5/weather?q={cityCountry}&units=metric&APPID={_apiKey}";

                    var client   = new HttpClient();
                    var response = client.GetAsync(url).Result;
                    var result   = response.Content.ReadAsStringAsync().Result;
                    weather = ParseWeather(result);
                    AddToDictionary(cityCountry, weather);
                }
                catch (Exception)
                {
                    weather = WeatherConditions.Random(cityName, countryCode);
                }
                return(weather);
            }
            return(weather);
        }
Esempio n. 7
0
 public void AddToCacheDictionary(string key, WeatherConditions conditions)
 {
     _cacheDictionary.Add(key, conditions);
     System.IO.File.WriteAllLines(_cacheFile,
                                  _cacheDictionary
                                  .Select(p => $"{p.Key}|{JsonConvert.SerializeObject(p.Value)}"));
 }
Esempio n. 8
0
        public void GetVisibilityTest()
        {
            WeatherConditions test = new WeatherConditions(1, WindDirection.EAST, 1, 0);

            test.PrecipitationType = PrecipitationType.CLEAR;
            Assert.AreEqual(test.GetVisibility(), 100);

            WeatherConditions test1 = new WeatherConditions(1, WindDirection.EAST, 1, 15);

            test1.PrecipitationType = PrecipitationType.RAIN;
            Assert.AreEqual(test1.GetVisibility(), 80);

            WeatherConditions test2 = new WeatherConditions(1, WindDirection.EAST, 1, 30);

            test2.PrecipitationType = PrecipitationType.RAIN;
            Assert.AreEqual(test2.GetVisibility(), 50);

            WeatherConditions test3 = new WeatherConditions(1, WindDirection.EAST, 1, 80);

            test3.PrecipitationType = PrecipitationType.RAIN;
            Assert.AreEqual(test3.GetVisibility(), 10);

            WeatherConditions test4 = new WeatherConditions(1, WindDirection.EAST, 1, 100);

            test4.PrecipitationType = PrecipitationType.RAIN;
            Assert.AreEqual(test4.GetVisibility(), 0);
        }
Esempio n. 9
0
    static string FormatWind(WeatherConditions cond)
    {
        string wind;

        if (string.IsNullOrEmpty(cond.WindDirection))
        {
            wind = "[Wind] ";
        }
        else
        {
            wind = string.Format("[Wind {0}] ", cond.WindDirection);
        }

        // Only print wind gust speeds if we got some and if they're
        // sensible, ie greater than regular wind speeds.
        string windspeeds;

        if (cond.WindGustInKph > cond.WindSpeedInKph)
        {
            windspeeds = string.Format(
                "{0:0.#}->{1:0.#} km/h ({2:0.#}->{3:0.#} mph)",
                cond.WindSpeedInKph, cond.WindGustInKph,
                cond.WindSpeedInMph, cond.WindGustInMph
                );
        }
        else
        {
            windspeeds = string.Format(
                "{0:0.#} km/h ({1:0.#} mph)",
                cond.WindSpeedInKph, cond.WindSpeedInMph
                );
        }

        return(wind + windspeeds);
    }
 /// <summary>
 /// Sets the conditions so only the appropriate GameObject/particle system is active.
 /// </summary>
 /// <param name="conditions">Conditions.</param>
 protected void SetConditions(WeatherConditions conditions)
 {
     for (int i = 0; i < conditionsGameObjects.Length; i++)
     {
         bool matches = conditionsGameObjects [i].conditions == conditions;
         conditionsGameObjects [i].gameObject.SetActive(matches);
     }
 }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            WeatherConditions weatherConditions = await _db.WeatherConditions.FindAsync(id);

            _db.WeatherConditions.Remove(weatherConditions);
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 12
0
        public void WeatherConditionsTest()
        {
            WeatherConditions test = new WeatherConditions(1, WindDirection.EAST, 1, 1);

            Assert.AreEqual(test.WindSpeed, 1);
            Assert.AreEqual(test.WindDirection, WindDirection.EAST);
            Assert.AreEqual(test.TemperatureC, 1);
            Assert.AreEqual(test.PrecipitationIntensity, 1);
        }
Esempio n. 13
0
        public async Task GetCurrentWeatherByCityName_Test()
        {
            // prepare SI
            WeatherConditions output = null;

            using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_currentweather_SI.json"), 8192)) {
                var mockHttp = new MockHttpMessageHandler();
                mockHttp
                .When(OpenWeatherService.EndPointRoot + "*")
                .Respond("application/json", stream);
                IOpenWeatherService client = new OpenWeatherService("12345", mockHttp);

                output = await client.GetCurrentWeather(BolognaLatitude, BolognaLongitude, OWUnit.Metric, Language.Italian);

                stream.Close();
            }
            // assert
            output.ShouldNotBeNull();
            output.City.ShouldNotBeNull();
            output.City.Coordinates.Latitude.ShouldBe(44.4667);
            output.City.Coordinates.Longitude.ShouldBe(11.4333);
            output.WeatherInfo[0].Summary.ShouldBe("Clouds");
            output.WeatherInfo[0].Description.ShouldBe("nubi sparse");
            output.WeatherInfo[0].Icon.ShouldBe("03d");
            output.City.Name.ShouldNotBeNullOrWhiteSpace();
            output.City.Name.ShouldBe(BolognaCityName, StringCompareShould.IgnoreCase);
            output.City.CountryCode.ShouldBe("IT");
            output.City.SunriseTime.ToUnixTimeSeconds().ShouldBe(1610174975);

            // prepare imperial
            WeatherConditions outputImperial = null;

            using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_currentweather_Imperial.json"), 8192)) {
                var mockHttp = new MockHttpMessageHandler();
                mockHttp
                .When(OpenWeatherService.EndPointRoot + "*")
                .Respond("application/json", stream);
                IOpenWeatherService client = new OpenWeatherService("12345", mockHttp);

                outputImperial = await client.GetCurrentWeather(BolognaCityName, OWUnit.Imperial, Language.English);

                stream.Close();
            }
            // assert
            output.ShouldNotBeNull();
            output.City.ShouldNotBeNull();
            outputImperial.City.Name.ShouldBe(output.City.Name);
            outputImperial.City.CountryCode.ShouldBe(output.City.CountryCode);
            outputImperial.City.Coordinates.Latitude.ShouldBe(output.City.Coordinates.Latitude);
            outputImperial.City.Coordinates.Longitude.ShouldBe(output.City.Coordinates.Longitude);
            outputImperial.Wind.Speed.ShouldNotBe(output.Wind.Speed);
            outputImperial.Temperature.Daily.ShouldNotBeNull();
            outputImperial.Temperature.Daily.Value.ShouldBeGreaterThan(output.Temperature.Daily.Value);
            outputImperial.ApparentTemperature.Daily.ShouldNotBeNull();
            outputImperial.ApparentTemperature.Daily.Value.ShouldBeGreaterThan(output.ApparentTemperature.Daily.Value);
        }
Esempio n. 14
0
        public void CheckForRain_Fails_Test(WeatherConditions testCondition)
        {
            var checker = CreateInstance();

            _weatherMock.Setup(w => w.GetWeather()).Returns(testCondition);

            var result = checker.Check(WeatherConditions.RAINY);

            Assert.IsFalse(result);
        }
        public async Task <ActionResult> Edit([Bind(Include = "WeatherConditionId,ExternalId,Description")] WeatherConditions weatherConditions)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(weatherConditions).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(weatherConditions));
        }
        public async Task <ActionResult> Create([Bind(Include = "WeatherConditionId,ExternalId,Description")] WeatherConditions weatherConditions)
        {
            if (ModelState.IsValid)
            {
                _db.WeatherConditions.Add(weatherConditions);
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(weatherConditions));
        }
Esempio n. 17
0
        public static void SendSlackNotification([ActivityTrigger] WeatherConditions conditions, ILogger log)
        {
            log.LogInformation($"[ENTER] Sending Slack Notification for city: {conditions.name}");
            var slackWebHookUrl = $"https://hooks.slack.com/services/{SlackWebHookUrl}";
            var httpClient      = new HttpClient();
            var slackData       = new SlackData
            {
                text = $"Weather in {conditions.name} is {conditions.weather.First().main} and {String.Format("{0:0.00}", conditions.main.temp-273)}"
            };
            var content = JsonConvert.SerializeObject(slackData);

            httpClient.PostAsync(slackWebHookUrl, new StringContent(content));
            log.LogInformation($"[END] Sending Slack Notification for city: {conditions.name}");
        }
        // GET: WeatherConditions/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WeatherConditions weatherConditions = await _db.WeatherConditions.FindAsync(id);

            if (weatherConditions == null)
            {
                return(HttpNotFound());
            }
            return(View(weatherConditions));
        }
Esempio n. 19
0
    // Wraps locking and null-checking.
    bool TryGetConditions(WeatherLocation location, out WeatherConditions cond)
    {
        cond = null;

        lock (_locker)
        {
            if (weather != null)
            {
                cond = weather.GetConditions(location);
                return(true);
            }
        }

        return(false);
    }
Esempio n. 20
0
        public void ParseCommand()
        {
            switch (command)
            {
            case "speak":
            case "sing":
                if (data.Attributes.GetNamedItem("tone") != null)
                {
                    tone = (SpeechTone)System.Enum.Parse(typeof(SpeechTone), data.Attributes.GetNamedItem("tone").InnerXml.ToUpper());
                }
                else
                {
                    tone = SpeechTone.NORMAL;
                }
                break;

            case "settemperature":
                if (data.Attributes.GetNamedItem("units") != null)
                {
                    units = (TemperatureUnits)System.Enum.Parse(typeof(TemperatureUnits), data.Attributes.GetNamedItem("units").InnerXml.ToUpper());
                }
                else
                {
                    units = TemperatureUnits.CELSIUS;
                }
                break;

            case "setweather":
                weather = content != null ? (WeatherConditions)System.Enum.Parse(typeof(WeatherConditions), content.ToUpper()) : WeatherConditions.CLEAR;
                break;

            case "setdate":
            case "settime":
                date = DateTime.Parse(content);
                break;

            case "setsequence":
                if (data.Attributes.GetNamedItem("atDate") != null)
                {
                    atDate = DateTime.Parse(data.Attributes.GetNamedItem("atDate").InnerXml);
                }
                if (data.Attributes.GetNamedItem("autoStart") != null)
                {
                    autoStart = data.Attributes.GetNamedItem("autoStart").InnerXml == "true" ? true : false;
                }
                break;
            }
        }
Esempio n. 21
0
        public static async Task <WeatherConditions> GetWeatherConditionsAsync(string cityKey)
        {
            WeatherConditions weatherConditions = new WeatherConditions();

            string url = BaseURL + string.Format(CurrentconditionsEndpoint, cityKey, APIKey);

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(url);

                string json = await response.Content.ReadAsStringAsync();

                weatherConditions = JsonConvert.DeserializeObject <List <WeatherConditions> >(json).FirstOrDefault();
            }

            return(weatherConditions);
        }
        ////////////////////////////////////////
        //
        // Weather Model To View Conversion

        //Converts model object to view object
        protected WeatherViewData Convert(WeatherData weatherData)
        {
            //conditions string to enum
            WeatherConditions conditions = WeatherConditions.Clear;

            if (Enum.IsDefined(typeof(WeatherConditions), weatherData.weatherMainCategory))
            {
                conditions = (WeatherConditions)Enum.Parse(typeof(WeatherConditions), weatherData.weatherMainCategory);
            }

            //kelvin to farenheit
            float temperatureFarenheit = weatherData.temperature * (9f / 5f) - 459.67f;

            //create the view data for the view scripts to use.
            WeatherViewData weatherViewData = new WeatherViewData(conditions, temperatureFarenheit);

            return(weatherViewData);
        }
Esempio n. 23
0
        public void GetPrecipitationTypeTest()
        {
            WeatherConditions test = new WeatherConditions(1, WindDirection.EAST, 1, 21);

            Assert.AreEqual(test.GetPrecipitationType(), PrecipitationType.RAIN);

            WeatherConditions test1 = new WeatherConditions(1, WindDirection.EAST, -1, 40);

            Assert.AreEqual(test1.GetPrecipitationType(), PrecipitationType.SNOW);

            WeatherConditions test2 = new WeatherConditions(1, WindDirection.EAST, -1, 41);

            Assert.AreEqual(test2.GetPrecipitationType(), PrecipitationType.HAIL);

            WeatherConditions test3 = new WeatherConditions(1, WindDirection.EAST, 1, 0);

            Assert.AreEqual(test3.GetPrecipitationType(), PrecipitationType.CLEAR);
        }
        private WeatherConditions GetResult(string json, Location location)
        {
            var weatherDto = JsonConvert.DeserializeObject <WeatherDto>(json);

            if (weatherDto?.query?.results?.channel?.item?.condition == null)
            {
                return(null);
            }

            var condition = weatherDto.query.results.channel.item.condition;

            // Icon.Code = 3200: not available
            if (condition.code == "3200")
            {
                return(null);
            }

            var url = weatherDto.query.results.channel.item.link;

            if (string.IsNullOrEmpty(url))
            {
                url = "https://www.yahoo.com/?ilc=401";
            }

            double temperatureF;

            double.TryParse(condition.temp, out temperatureF);

            var weatherConditions = new WeatherConditions()
            {
                Title          = condition.text,
                Description    = condition.text,
                TemperatureC   = (int)Math.Ceiling(TemperatureConverter.FahrenheitToCelsius(temperatureF)),
                TemperatureF   = (int)temperatureF,
                Icon           = Icons.GetCssClass(condition.code),
                Location       = location.City,
                CountryCode    = location.CountryCode,
                UsesFahrenheit = location.UsesFahrenheit,
                Service        = "Yahoo",
                ServiceUrl     = url
            };

            return(weatherConditions);
        }
Esempio n. 25
0
        private WeatherConditions GetResult(string json, Location location)
        {
            var weatherDto = JsonConvert.DeserializeObject<WeatherDto>(json);
            if (weatherDto == null) return null;

            var weatherConditions = new WeatherConditions()
            {
                Title = weatherDto.currently.summary,
                Description = weatherDto.currently.summary,
                TemperatureC = (int)Math.Ceiling(TemperatureConverter.FahrenheitToCelsius(weatherDto.currently.temperature)),
                TemperatureF = (int)Math.Ceiling(weatherDto.currently.temperature),
                Icon = Icons.GetCssClass(weatherDto.currently.icon),
                Location = location.City,
                CountryCode = location.CountryCode,
                UsesFahrenheit = location.UsesFahrenheit,
                Service = "Forecast.io",
                ServiceUrl = "http://forecast.io/"
            };
            return weatherConditions;
        }
Esempio n. 26
0
        public void ControllerShouldReturnCorrectWeatherInViewModel()
        {
            var userId         = 1;
            var userRepo       = Substitute.For <IUserRepository>();
            var weatherService = Substitute.For <IWeatherService>();
            var ffProvider     = Substitute.For <IFeatureFlagProvider>();

            var expectedUser = new User
            {
                Id          = userId,
                CityName    = "MyCity",
                CountryCode = "AU"
            };
            var expectedWeather = new WeatherConditions
            {
                CountryCode = "AU",
                CityName    = "MyCity",
                Temperature = 20.36f
            };
            var expectedViewModel = new PersonalWeatherViewModel
            {
                CityName    = expectedUser.CityName,
                CountryCode = expectedWeather.CountryCode,
                Temperature = Math.Round(expectedWeather.Temperature, 1)
            };

            ffProvider.Toggle(Arg.Any <string>(), userId, Arg.Any <string>())
            .Returns(false);
            userRepo.GetUserProfile(1)
            .Returns(expectedUser);
            weatherService.GetWeatherForCityAndCountry(expectedUser.CityName, expectedUser.CountryCode)
            .Returns(expectedWeather);

            var controller = new HomeController(userRepo, weatherService, ffProvider);

            var result    = controller.Index(userId) as ViewResult;
            var viewModel = result.Model as PersonalWeatherViewModel;


            viewModel.Temperature.ShouldBeEquivalentTo(expectedViewModel.Temperature);
        }
Esempio n. 27
0
    public static string IrcFormat(WeatherConditions cond)
    {
        // Only print percipitation if we've got some.
        string precip = string.Empty;

        if (cond.PrecipitationInMillimeters > 0)
        {
            precip = string.Format(
                "Precipitation {0:0.#} mm ({1:0.##} in) :: ",
                cond.PrecipitationInMillimeters, cond.PrecipitationInInches
                );
        }

        return(string.Format(
                   "[ {0} ] {1} :: {2:0.#}°C ({3:0.#}°F) :: " +
                   "Humidity {4}% :: {5}{6}",
                   cond.WeatherLocation, cond.Description,
                   cond.TemperatureInC, cond.TemperatureInF,
                   cond.RelativeHumidity, precip,
                   FormatWind(cond)
                   ));
    }
Esempio n. 28
0
        public async Task <IEnumerable <WeatherConditions> > GetFor(
            IEnumerable <string> cities,
            CancellationToken ct = default)
        {
            var tasks     = cities.Select(city => GetWeatherConditions(city, ct));
            var responses = await Task.WhenAll(tasks);

            var conditions = responses.Select(r =>
            {
                var obj = new WeatherConditions(
                    Guid.NewGuid(),
                    r.City,
                    DateTime.UtcNow,
                    r.Temperature,
                    r.Precipitation,
                    r.Weather);

                return(obj);
            });

            return(conditions);
        }
Esempio n. 29
0
        public async void GetCurrentWeatherByCoordinates_Test()
        {
            // prepare
            WeatherConditions output = null;

            using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_currentweather_SI.json"), 8192)) {
                var mockHttp = new MockHttpMessageHandler();
                mockHttp
                .When(OpenWeatherService.EndPointRoot + "*")
                .Respond("application/json", stream);
                IOpenWeatherService client = new OpenWeatherService("a_valid_key", mockHttp);

                output = await client.GetCurrentWeather(BolognaLatitude, BolognaLongitude, OWUnit.Metric, Language.Italian);

                stream.Close();
            }

            // assert
            output.ShouldNotBeNull();
            output.City.Name.ShouldNotBeNullOrWhiteSpace();
            output.City.Name.ShouldBe(BolognaCityName, StringCompareShould.IgnoreCase);
        }
Esempio n. 30
0
        public static WeatherConditionsViewModel AsViewModel(this WeatherConditions weather, bool isMetricUnits)
        {
            if (weather == null)
            {
                return(null);
            }

            return(new WeatherConditionsViewModel
            {
                Condition = weather.Condition,
                Temperature = isMetricUnits ? weather.Temperature : ((weather.Temperature * 1.8) + 32),
                WindDirection = weather.WindDegrees,
                WindSpeed = isMetricUnits
                            ? weather.WindSpeed * Constants.KMH_TO_METRES_PER_SECOND
                            : weather.WindSpeed * Constants.KMH_TO_METRES_PER_SECOND / Constants.MILES_TO_KILOMETRES,
                PreviousHourPrecipitation = isMetricUnits
                                                ? weather.PreviousHourPrecipitation
                                                : weather.PreviousHourPrecipitation / Constants.MILLIMETRES_TO_INCHES,
                TotalDayPrecipitation = isMetricUnits
                                        ? weather.TotalDayPrecipitation
                                        : weather.TotalDayPrecipitation / Constants.MILLIMETRES_TO_INCHES
            });
        }
Esempio n. 31
0
        public void SetDefaults()
        {
            version = 1;
            type = "basic";

            sequenceQueue = new List<Sequence>();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml( "<location id=\"defaultLocation\" lat=\"0\" lon=\"0\">Default Location</location>" );
            currentLocation = new Location( doc.DocumentElement, this );

            currentTemperature = 24f;
            currentTemperatureUnits = TemperatureUnits.CELSIUS;

            currentWeather = WeatherConditions.CLEAR;

            currentDate = DateTime.Now;
        }
Esempio n. 32
0
 /**
  * Given weather conditions, makes them the current weather conditions.
  *
  * @param weather		The weather conditions to make current.
  */
 public void SetWeather( WeatherConditions weather )
 {
     currentWeather = weather;
 }
Esempio n. 33
0
        public void ParseCommand()
        {
            switch ( command ) {

            case "speak":
                if ( data.Attributes.GetNamedItem( "tone" ) != null ) {
                    tone = (SpeechTone) System.Enum.Parse ( typeof(SpeechTone), data.Attributes.GetNamedItem( "tone" ).InnerXml.ToUpper() );
                }
                break;

            case "settemperature":
                if ( data.Attributes.GetNamedItem( "units" ) != null ) {
                    units = (TemperatureUnits) System.Enum.Parse ( typeof(TemperatureUnits), data.Attributes.GetNamedItem( "units" ).InnerXml.ToUpper() );
                } else {
                    units = TemperatureUnits.CELSIUS;
                }
                break;

            case "setweather":
                weather = content != null ? (WeatherConditions) System.Enum.Parse ( typeof(WeatherConditions), content.ToUpper() ) : WeatherConditions.CLEAR;
                break;

            case "setdate":
            case "settime":
                date = DateTime.Parse( content );
                break;

            case "setsequence":
                if ( data.Attributes.GetNamedItem( "atDate" ) != null ) {
                    atDate = DateTime.Parse( data.Attributes.GetNamedItem( "atDate" ).InnerXml );
                }
                if ( data.Attributes.GetNamedItem( "autoStart" ) != null ) {
                    autoStart = data.Attributes.GetNamedItem( "autoStart" ).InnerXml == "true" ? true : false;
                }
                break;

            }
        }