Exemplo n.º 1
0
        //Async load of the items
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                WeatherStations.Clear();
                //From the main page we want to always show them all the data
                bool succ = await WeatherStationDependency.RefreshWeatherSets(WeatherSet.WeatherSetDateRanges.AllTime);

                IEnumerable <WeatherStation> items = await WeatherStationDependency.GetAllWeatherSets(true);

                foreach (var item in items)
                {
                    WeatherStations.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        public async Task LoadObservableCollection()
        {
            IsBusy = true;

            bool succ = await WeatherStationDependency.RefreshWeatherSets(WeatherSet.WeatherSetDateRanges.AllTime);

            IEnumerable <WeatherStation> items = await WeatherStationDependency.GetAllWeatherSets(true);

            _rgSets.Clear();
            foreach (var item in items)
            {
                if (item.StationName == Item.StationName)
                {
                    Item.rgWeatherSets.Clear();
                    foreach (var weatherSet in item.rgWeatherSets)
                    {
                        Item.rgWeatherSets.Add(weatherSet);
                    }
                }
            }

            await Task.Run(() =>
            {
                DateTime upperbound = DateTime.Now;
                DateTime lowerbound;

                try
                {
                    switch (dateRange)
                    {
                    case WeatherSet.WeatherSetDateRanges.Today:
                        lowerbound = upperbound.Date;
                        break;

                    case WeatherSet.WeatherSetDateRanges.PastThreeDays:
                        lowerbound = upperbound.Date.AddDays(-3);
                        break;

                    case WeatherSet.WeatherSetDateRanges.PastWeek:
                        lowerbound = upperbound.Date.AddDays(-7);
                        break;

                    case WeatherSet.WeatherSetDateRanges.ThisMonth:
                        lowerbound = new DateTime(upperbound.Year, upperbound.Month, 1);
                        break;

                    case WeatherSet.WeatherSetDateRanges.ThisYear:
                        lowerbound = new DateTime(upperbound.Year, 1, 1);
                        break;

                    default:
                        lowerbound = DateTime.MinValue;
                        break;
                    }

                    _rgSets.Clear();
                    foreach (WeatherSet weatherItem in Item.rgWeatherSets)
                    {
                        if (weatherItem.RecordedTime <= upperbound.AddMinutes(1) && weatherItem.RecordedTime >= lowerbound)
                        {
                            _rgSets.Add(weatherItem);
                        }
                    }

                    RgSets.ClearAndAddRange(_rgSets);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception during loading station data: " + ex.Message);
                }
                finally
                {
                    IsBusy = false;
                }
            });
        }