public void OnGet()
 {
     FPAdd = new ForecastPeriod()
     {
         VerifiedForecasts = new List <VerifiedForecast>()
     };
 }
        public override Dictionary <string, object> Parse(string remainingTaf, bool withCavok = false)
        {
            string newRemainingTaf;
            var    found  = Consume(remainingTaf, out newRemainingTaf);
            var    result = new Dictionary <string, object>();

            // handle the case where nothing has been found
            if (found.Count <= 1)
            {
                throw new TafChunkDecoderException(remainingTaf, newRemainingTaf, TafChunkDecoderException.Messages.InvalidForecastPeriodInformation, this);
            }
            else
            {
                // retrieve found params and check them
                var forecastPeriod = new ForecastPeriod()
                {
                    FromDay  = Convert.ToInt32(found[1].Value),
                    FromHour = Convert.ToInt32(found[2].Value),
                    ToDay    = Convert.ToInt32(found[3].Value),
                    ToHour   = Convert.ToInt32(found[4].Value),
                };
                if (!forecastPeriod.IsValid)
                {
                    throw new TafChunkDecoderException(remainingTaf, newRemainingTaf, TafChunkDecoderException.Messages.InvalidValuesForTheForecastPeriod, this);
                }

                result.Add(ForecastPeriodParameterName, forecastPeriod);
            }

            return(GetResults(newRemainingTaf, result));
        }
Beispiel #3
0
        public async Task <IActionResult> OnGetAsync(int?FPid)
        {
            if (FPid == null)
            {
                return(NotFound());
            }
            else
            {
                FPEdit = await _context.ForecastPeriods.FindAsync(FPid);

                if (FPEdit == null)
                {
                    return(NotFound());
                }
            }
            return(Page());
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostAsync(int?FPRemove)
        {
            if (FPRemove == null)
            {
                return(NotFound());
            }
            else
            {
                ForecastPeriod fpRemove = await _context.ForecastPeriods.FindAsync(FPRemove);

                if (fpRemove != null)
                {
                    _context.ForecastPeriods.Remove(fpRemove);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToPage("Scheduling"));
            }
        }
Beispiel #5
0
 public void AddForecast(int period, ForecastPeriod data)
 {
     if (period < 0 || data == null)
     {
         throw new ArgumentException();
     }
     if (_list.ContainsKey(period))
     {
         _list.Remove(period);
     }
     _list.Add(period, data);
     if (period == 0)
     {
         Output.Sellwish.Class.AnzahlArtikel1 = _list[0].Product1;
         Output.Sellwish.Class.AnzahlArtikel2 = _list[0].Product2;
         Output.Sellwish.Class.AnzahlArtikel3 = _list[0].Product3;
     }
 }
        private Grid GetGridForForecastPeriod(ForecastPeriod period)
        {
            var newGrid = new Grid();

            newGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(80)
            });
            newGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(50)
            });
            newGrid.ColumnDefinitions.Add(new ColumnDefinition());
            newGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(80)
            });

            var timeLabel = new Label();

            timeLabel.Content = period.startTime.ToString("MM/dd htt");
            Grid.SetColumn(timeLabel, 0);
            newGrid.Children.Add(timeLabel);

            var temperatureLabel = new Label();

            temperatureLabel.Content = period.temperature + "°" + period.temperatureUnit;
            Grid.SetColumn(temperatureLabel, 1);
            newGrid.Children.Add(temperatureLabel);

            var descriptionLabel = new Label();

            descriptionLabel.Content = period.shortForecast;
            Grid.SetColumn(descriptionLabel, 2);
            newGrid.Children.Add(descriptionLabel);

            var windLabel = new Label();

            windLabel.Content = $"{period.windDirection} {period.windSpeed}";
            Grid.SetColumn(windLabel, 3);
            newGrid.Children.Add(windLabel);

            return(newGrid);
        }
        public async Task <IActionResult> OnGetAsync(int?VFid)
        {
            if (VFid == null)
            {
                return(NotFound());
            }
            else
            {
                VFEdit = await _context.VerifiedForecasts.FindAsync(VFid);

                if (VFEdit == null)
                {
                    return(NotFound());
                }
                else
                {
                    VF_ForePeriod = await _context.ForecastPeriods.FindAsync(VFEdit.ForecastPeriodID);
                }
            }
            return(Page());
        }
Beispiel #8
0
        public async Task <IActionResult> OnGetAsync(int?ForID)
        {
            if (ForID == null)
            {
                return(NotFound());
            }
            else
            {
                CurrentForecast = await _context.Forecasts.FindAsync(ForID);

                if (CurrentForecast == null)
                {
                    return(NotFound());
                }
                else
                {
                    CurrentFP = await _context.ForecastPeriods.FindAsync(CurrentForecast.ForecastPeriodID);
                }
            }

            return(Page());
        }
Beispiel #9
0
        /// <summary>
        /// Handle the information returned from the async request
        /// </summary>
        /// <param name="asyncResult"></param>
        private void HandleForecastResponse(IAsyncResult asyncResult)
        {
            // get the state information
            ForecastUpdateState forecastState = (ForecastUpdateState)asyncResult.AsyncState;
            HttpWebRequest forecastRequest = (HttpWebRequest)forecastState.AsyncRequest;

            // end the async request
            forecastState.AsyncResponse = (HttpWebResponse)forecastRequest.EndGetResponse(asyncResult);

            Stream streamResult;

            string newCredit = "";
            string newCityName = "";
            int newHeight = 0;

            // create a temp collection for the new forecast information for each
            // time period
            ObservableCollection<ForecastPeriod> newForecastList =
                new ObservableCollection<ForecastPeriod>();

            try
            {
                // get the stream containing the response from the async call
                streamResult = forecastState.AsyncResponse.GetResponseStream();

                // load the XML
                XElement xmlWeather = XElement.Load(streamResult);

                // start parsing the XML.  You can see what the XML looks like by
                // browsing to:
                // http://forecast.weather.gov/MapClick.php?lat=44.52160&lon=-87.98980&FcstType=dwml

                // find the source element and retrieve the credit information
                XElement xmlCurrent = xmlWeather.Descendants("source").First();
                newCredit = (string)(xmlCurrent.Element("credit"));

                // find the source element and retrieve the city and elevation information
                xmlCurrent = xmlWeather.Descendants("location").First();
                newCityName = (string)(xmlCurrent.Element("city"));
                newHeight = (int)(xmlCurrent.Element("height"));

                // find the first time layout element
                xmlCurrent = xmlWeather.Descendants("time-layout").First();

                int timeIndex = 1;

                // search through the time layout elements until you find a node
                // contains at least 12 time periods of information. Other nodes can be ignored
                while (xmlCurrent.Elements("start-valid-time").Count() < 12)
                {
                    xmlCurrent = xmlWeather.Descendants("time-layout").ElementAt(timeIndex);
                    timeIndex++;
                }

                ForecastPeriod newPeriod;

                // For each time period element, create a new forecast object and store
                // the time period name.
                // Time periods vary depending on the time of day the data is fetched.
                // You may get "Today", "Tonight", "Monday", "Monday Night", etc
                // or you may get "Tonight", "Monday", "Monday Night", etc
                // or you may get "This Afternoon", "Tonight", "Monday", "Monday Night", etc
                foreach (XElement curElement in xmlCurrent.Elements("start-valid-time"))
                {
                    try
                    {
                        newPeriod = new ForecastPeriod();
                        newPeriod.TimeName = (string)(curElement.Attribute("period-name"));
                        newForecastList.Add(newPeriod);
                    }
                    catch (FormatException)
                    {

                    }
                }

                // now read in the weather data for each time period
                GetMinMaxTemperatures(xmlWeather, newForecastList);
                GetChancePrecipitation(xmlWeather, newForecastList);
                GetCurrentConditions(xmlWeather, newForecastList);
                GetWeatherIcon(xmlWeather, newForecastList);
                GetTextForecast(xmlWeather, newForecastList);

                // copy the data over
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    // copy forecast object over
                    Credit = newCredit;
                    Height = newHeight;
                    //CityName = newCityName;

                    ForecastList.Clear();

                    // copy the list of forecast time periods over
                    foreach (ForecastPeriod forecastPeriod in newForecastList)
                    {
                        ForecastList.Add(forecastPeriod);
                    }
                });

            }
            catch (FormatException)
            {
                // there was some kind of error processing the response from the web
                // additional error handling would normally be added here
                return;
            }
        }
Beispiel #10
0
        public static void Initialize(ForecastWebsiteContext context)
        {
            context.Database.EnsureCreated();

            if (context.Forecasts.Any() && context.VerifiedForecasts.Any() && context.ForecastPeriods.Any())
            {
                return;
            }

            Forecast fore1 = new Forecast
            {
                ForecastID           = 0,
                ForecastTime         = null,
                MinimumTemperature   = null,
                MaximumTemperature   = null,
                SurfaceTemperature   = null,
                SurfaceDewpoint      = null,
                SurfaceWindDirect    = null,
                SurfaceWindSpeed     = null,
                SurfaceMaxWindSpeed  = null,
                SeaLevelPressure     = null,
                CloudCover           = null,
                CloudCeiling         = null,
                Visibility           = null,
                ObservedWeather      = null,
                ProbOfPrecip         = null,
                PrecipCategory       = null,
                PrecipType           = null,
                SnowAccumulation     = null,
                Thunderstorms        = false,
                SevereWeatherFlood   = false,
                SevereWeatherWind    = false,
                SevereWeatherTornado = false,
                SevereWeatherHail    = false,
                FrontalPassage       = null,
                FrontalPassageTime   = null
            };

            context.Forecasts.Add(fore1);
            context.SaveChanges();

            ForecastPeriod forPer = new ForecastPeriod
            {
                ForecastTime1    = null,
                ForecastTime2    = null,
                ForecastTime3    = null,
                ForecastTime4    = null,
                ForecastTime5    = null,
                ForecastTimeUTC1 = new DateTime(1901, 1, 1, 12, 0, 0),
                ForecastTimeUTC2 = new DateTime(1901, 1, 1, 12, 0, 0),
                ForecastTimeUTC3 = new DateTime(1901, 1, 1, 12, 0, 0),
                ForecastTimeUTC4 = new DateTime(1901, 1, 1, 12, 0, 0),
                ForecastTimeUTC5 = new DateTime(1901, 1, 1, 12, 0, 0),
                //VerifiedForecast1 = null,
                //VerifiedForecast2 = null,
                //VerifiedForecast3 = null,
                //VerifiedForecast4 = null,
                //VerifiedForecast5 = null,
                VerifiedForecasts = new List <VerifiedForecast>(),
                City            = "",
                CityID          = "",
                StartingTimeUTC = new DateTime(1901, 1, 1),
                OpenTimeUTC     = new DateTime(1901, 1, 1),
                ClosedTimeUTC   = new DateTime(1901, 1, 1)
            };

            context.ForecastPeriods.Add(forPer);
            context.SaveChanges();

            VerifiedForecast vfore1 = new VerifiedForecast()
            {
                ForecastPeriod = forPer
            };

            context.VerifiedForecasts.Add(vfore1);
            context.SaveChanges();
        }