Exemple #1
0
        private async void LoadSubscriptions()
        {
            List <TreeItemBase> subscriptionItems = null;

            IsBusy = true;

            Exception error = null;

            try
            {
                IsOffline = false;

                subscriptionItems = await _subscriptionsManager.LoadSubscriptionsAsync();

                var readAllItem = subscriptionItems.FirstOrDefault(t => t.Id == SpecialTags.Read);
                if (readAllItem != null)
                {
                    _tileManager.UpdateAsync(readAllItem.UnreadCount);
                }

                await _localStorageManager.SaveSubscriptionsAsync(subscriptionItems);
            }
            catch (AuthenticationApiException)
            {
                _apiClient.ClearSession();
                _navigationService.Navigate(PageTokens.SignIn, null);
                return;
            }
            catch (Exception ex)
            {
                error = ex;
                _telemetryClient.TrackExceptionFull(ex);
            }
            finally
            {
                IsBusy = false;
            }

            if (subscriptionItems == null)
            {
                IsOffline = true;

                IsBusy            = true;
                subscriptionItems = await _localStorageManager.LoadSubscriptionsAsync();

                IsBusy = false;
            }

            if (subscriptionItems != null)
            {
                _rootItems = subscriptionItems;

                var cat = subscriptionItems.OfType <CategoryItem>()
                          .FirstOrDefault(c => !_isRoot && String.Equals(c.Id, _categoryId, StringComparison.OrdinalIgnoreCase));

                if (cat != null)
                {
                    SubscriptionsHeader = cat.Title;
                    _isRoot             = false;
                    TreeItems           = new List <TreeItemBase>(cat.Subscriptions);
                }
                else
                {
                    SubscriptionsHeader = Strings.Resources.SubscriptionsSectionHeader;
                    _isRoot             = true;
                    TreeItems           = _rootItems;
                }
            }

            if (error != null)
            {
                var msgbox = new MessageDialog(error.Message, Strings.Resources.ErrorDialogTitle);
                await msgbox.ShowAsync();
            }
        }