Exemplo n.º 1
0
        /// <summary>
        /// Executes once LoadRequest has executed. Will also happen when deserializing cached data
        /// </summary>
        public override object Deserialize(DayLoadContext loadContext, Type objectType, Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            string html = PageParser.GetHtml(stream);

            List<Entry> entries = PageParser.ExtractEntriesFromHtml(html, true);
            var viewModel = new DayViewModel(loadContext);

            if (loadContext.ReverseOrder)
            {
                for (int i = entries.Count - 1; i >= 0; i--)
                {
                    viewModel.Highlights.Add(entries[i]);
                }
            }
            else
            {
                foreach (Entry entry in entries)
                {
                    viewModel.Highlights.Add(entry);
                }
            }

            return viewModel;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes once LoadRequest has executed. Will also happen when deserializing cached data
        /// </summary>
        public override object Deserialize(DayLoadContext loadContext, Type objectType, Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            string html = PageParser.GetHtml(stream);
            var entries = PageParser.ExtractEntriesFromHtml(html, false);
            var viewModel = new DeathsViewModel(loadContext);

            if (loadContext.ReverseOrder)
            {
                entries.Reverse();
            }

            var groupings = entries.GroupBy(PageParser.GroupByYear());
            foreach (IGrouping<string, Entry> grouping in groupings)
            {
                var displayGroup = new GroupedEntries
                {
                    Name = grouping.Key,
                    Entries = grouping.ToList()
                };
                viewModel.Deaths.Add(displayGroup);
            }

            return viewModel;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes once LoadRequest has executed. Will also happen when deserializing cached data
        /// </summary>
        public override object Deserialize(DayLoadContext loadContext, Type objectType, Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            string html = PageParser.GetHtml(stream);
            var holidays = PageParser.ExtractHolidaysFromHtml(html);
            var viewModel = new HolidaysViewModel(loadContext);

            foreach (Entry entry in holidays)
            {
                viewModel.Holidays.Add(entry);
            }

            return viewModel;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load either from the cache on internet
        /// </summary>
        private void LoadData(int numberOfStarts, ITransition transition = null)
        {
            IndicateStartedLoading(numberOfStarts);

            var loadContext = new DayLoadContext(CurrentDateForWiki, AppSettings.ShowNewestItemsFirst);
            this.DataContext = DataManager.Current.Load<DayViewModel>(
                loadContext,
                vm =>
                {
                    if (App.ReloadRequired)
                    {
                        App.ReloadRequired = false;
                    }
                    else if (App.FontSizeChanged)
                    {
                        vm.UpdateLayout();
                        App.FontSizeChanged = false;
                    }

                    if (App.ReverseRequired)
                    {
                        vm.Highlights = new ObservableCollection<Entry>(vm.Highlights.Reverse());
                        vm.Events.Events = new ObservableCollection<GroupedEntries>(vm.Events.Events.Reverse());
                        vm.Births.Births = new ObservableCollection<GroupedEntries>(vm.Births.Births.Reverse());
                        vm.Deaths.Deaths = new ObservableCollection<GroupedEntries>(vm.Deaths.Deaths.Reverse());
                        App.ReverseRequired = false;
                    }

                    if (!App.IsMemoryLimited && App.FirstLoad)
                    {
                        SetUpLiveTile(numberOfStarts);
                    }

                    if (App.IsMemoryLimited)
                    {
                        ((ApplicationBarMenuItem)ApplicationBar.MenuItems[3]).IsEnabled = false;
                    }

                    IndicateStoppedLoading();

                    if (!inTransition && transition != null)
                    {
                        inTransition = true;
                        transition.Begin();
                    }

                    AdPanel.Opacity = 100;
                },
                ex =>
                {
                    GlobalLoading.Instance.IsLoading = false;
                    GlobalLoading.Instance.LoadingText = null;

                    if (NetworkInterface.GetIsNetworkAvailable())
                    {
                        var extraData = new Collection<CrashExtraData>
                        {
                            new CrashExtraData { Key = "Date", Value = CurrentDateForWiki }
                        };
                        BugSenseHandler.Instance.SendExceptionMap(ex, extraData);
                    }
                    else
                    {
                        MessageBox.Show(Strings.ErrorInternetConnection);
                    }

                    if (!inTransition && transition != null)
                    {
                        inTransition = true;
                        transition.Begin();
                    }
                });

            SetPivotTitle();
        }