public bool SetAirWidget(XDocument xdocument)
    {
        try
        {
            var windItems = (from i in xdocument.Descendants("speed")
                             select new
            {
                Description = (string)i.Attribute("name"),
                Speed = (string)i.Attribute("value")
            }).Single();

            var direction = (from i in xdocument.Descendants("direction")
                             select new
            {
                Direction = (string)i.Attribute("code")
            }).Single();

            var pressureItems = (from i in xdocument.Descendants("pressure")
                                 select new
            {
                Value = (string)i.Attribute("value"),
                Unit = (string)i.Attribute("unit")
            }).Single();

            lblWindDescription.Text = windItems.Description;
            lblWindAmount.Text      = WeatherDisplay.BuildWind(windItems.Speed, direction.Direction);
            lblPressure.Text        = WeatherDisplay.BuildPressure(pressureItems.Value, pressureItems.Unit);
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
            return(false);
        }
        return(true);
    }
    public bool SetTitle(XDocument xdocument)
    {
        try
        {
            var cityName = (from i in xdocument.Descendants("city")
                            select new
            {
                CityName = (string)i.Attribute("name"),
            }).Single();

            var weatherIcon = (from i in xdocument.Descendants("weather")
                               select new
            {
                IconName = (string)i.Attribute("icon")
            }).Single();

            var cityCountry = xdocument.Descendants().Where(n => n.Name == "country").First();

            lblTitle.Text    = cityName.CityName + ", " + cityCountry.Value;
            imgIcon.ImageUrl = WeatherDisplay.BuildWeatherIconUrl(weatherIcon.IconName);
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
            return(false);
        }

        return(true);
    }
    public bool SetCloudWidget(XDocument xdocument)
    {
        try
        {
            var cloudItems = (from i in xdocument.Descendants("clouds")
                              select new
            {
                Value = (int)i.Attribute("value"),
                Name = (string)i.Attribute("name")
            }).Single();

            var humidity = (from i in xdocument.Descendants("humidity")
                            select new
            {
                Humidity = (string)i.Attribute("value")
            }).Single();

            lblCloudAmount.Text      = WeatherDisplay.BuildCloudAmount(cloudItems.Value);
            lblCloudDescription.Text = WeatherDisplay.BuildCloudDescription(cloudItems.Name);
            lblHumidity.Text         = WeatherDisplay.BuildHumidity(humidity.Humidity);
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
            return(false);
        }
        return(true);
    }
Exemple #4
0
        // GET: Details
        public ActionResult Details(string Id, WeatherDisplay displayType = 0)
        {
            using (_context = new ApplicationDbContext())
            {
                //Find the weather device in the database
                WeatherDevice weatherDevice = _context.WeatherDevices.First(wd => wd.Id == Id);

                //If the device has not been found
                if (weatherDevice == null)
                {
                    weatherDevice = new WeatherDevice();
                }

                List <WeatherUpdate> weatherUpdates = null;
                DateTime             displayTime    = DateTime.Now;

                //Get the weather updates that correlates with the current Date and Time the user selects
                switch (displayType)
                {
                case WeatherDisplay.OneHour:
                    displayTime    = DateTime.Now.AddHours(-1);
                    weatherUpdates = _context.WeatherUpdates.Where(wu => wu.TimeUpdateSent >= displayTime && wu.ParentDeviceID == Id).ToList();
                    break;

                case WeatherDisplay.SixHours:
                    displayTime    = DateTime.Now.AddHours(-6);
                    weatherUpdates = _context.WeatherUpdates.Where(wu => wu.TimeUpdateSent >= displayTime && wu.ParentDeviceID == Id).ToList();
                    break;

                case WeatherDisplay.TwentyFourHours:
                    displayTime    = DateTime.Now.AddDays(-1);
                    weatherUpdates = _context.WeatherUpdates.Where(wu => wu.TimeUpdateSent >= displayTime && wu.ParentDeviceID == Id).ToList();
                    break;

                case WeatherDisplay.PastSevenDays:
                    displayTime    = DateTime.Now.AddDays(-7);
                    weatherUpdates = _context.WeatherUpdates.Where(wu => wu.TimeUpdateSent >= displayTime && wu.ParentDeviceID == Id).ToList();
                    break;

                case WeatherDisplay.PastThirtyDays:
                    displayTime    = DateTime.Now.AddDays(-30);
                    weatherUpdates = _context.WeatherUpdates.Where(wu => wu.TimeUpdateSent >= displayTime && wu.ParentDeviceID == Id).ToList();
                    break;

                default:
                    break;
                }

                weatherUpdates = weatherUpdates.OrderBy(time => time.TimeUpdateSent.TimeOfDay).ToList();

                DetailsWeatherDevice currentView = new DetailsWeatherDevice
                {
                    CurrentDevice  = weatherDevice,
                    WeatherUpdates = weatherUpdates
                };

                return(View(currentView));
            }
        }
    public bool SetWeatherWidget(XDocument xdocument)
    {
        try
        {
            var temperatureItems = (from i in xdocument.Descendants("temperature")
                                    select new
            {
                CurrentTemp = (string)i.Attribute("value"),
                MinTemp = (string)i.Attribute("min"),
                MaxTemp = (string)i.Attribute("max")
            }).Single();

            lblCurrentTemp.Text = WeatherDisplay.BuildCurrentTemperature(temperatureItems.CurrentTemp);
            lblMinTemp.Text     = WeatherDisplay.BuildMinTemperature(temperatureItems.MinTemp);
            lblMaxTemp.Text     = WeatherDisplay.BuildMaxTemperature(temperatureItems.MaxTemp);
        }
        catch (Exception e)
        {
            Console.Out.WriteLine(e.Message);
            return(false);
        }

        return(true);
    }