예제 #1
0
        private async Task LoadComicsDataFile(StorageFolder folder)
        {
            var inFile = await folder.GetFileAsync(ComicsDataFile).AsTask().ConfigureAwait(false);

            using (var readStream = await inFile.OpenStreamForReadAsync().ConfigureAwait(false))
            {
                ComicDataSource.LoadDataFromFile(readStream);
            }
        }
예제 #2
0
        private async Task SaveComicData()
        {
            var outFile = await _storageFolder.CreateFileAsync(ComicsDataFile, CreationCollisionOption.ReplaceExisting);

            using (var saveStream = await outFile.OpenStreamForWriteAsync())
            {
                ComicDataSource.SaveComicData(saveStream);
            }
        }
예제 #3
0
        private void RefreshCollection()
        {
            var newCollection = ComicDataSource.GetComics(_month.Year, _month.Month);

            _comics.Clear();
            foreach (Comic c in newCollection)
            {
                _comics.Add(c);
            }
        }
예제 #4
0
        private void RefreshYearsCollection()
        {
            var sampleDataGroups = ComicDataSource.GetYears();

            _years.Clear();
            foreach (int year in sampleDataGroups)
            {
                _years.Add(year);
            }
        }
예제 #5
0
        private void RefreshCollection()
        {
            var newCollection = ComicDataSource.GetComics(_queryText);

            _comics.Clear();
            foreach (Comic c in newCollection)
            {
                _comics.Add(c);
            }
        }
예제 #6
0
        private void RefreshCollection()
        {
            var newCollection = ComicDataSource.GetMonths(_year);

            _months.Clear();
            foreach (DateTime month in newCollection)
            {
                _months.Add(month);
            }
        }
예제 #7
0
파일: App.xaml.cs 프로젝트: tadams1138/xkcd
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            var rootFrame = Window.Current.Content as Frame;

            LoadComicDataSource();
            UpdateComicDataSource();

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                int latestComicNumber = ComicDataSource.GetNumberOfLatestComic();
                if (!rootFrame.Navigate(typeof(ComicPage), latestComicNumber))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();

            _windowBounds = Window.Current.Bounds;

            // Added to listen for events when the window size is updated.
            Window.Current.SizeChanged += OnWindowSizeChanged;
        }
예제 #8
0
        private void RefreshCollection()
        {
            var newCollection = ComicDataSource.GetComics(_queryText);

            _comics.Clear();
            foreach (Comic c in newCollection)
            {
                _comics.Add(c);
            }

            string stateName = _comics.Any() ? "ResultsFound" : "NoResultsFound";

            VisualStateManager.GoToState(this, stateName, true);
        }
예제 #9
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            var comic = ComicDataSource.GetComic((int)navigationParameter);

            DefaultViewModel["Items"] = ComicDataSource.AllItems;
            FlipView.SelectedItem     = comic;

            RegisterForPrinting();
            SearchPane.GetForCurrentView().ShowOnKeyboardInput = true;
            _dataTransferManager = DataTransferManager.GetForCurrentView();
            _dataTransferManager.DataRequested += OnDataRequested;
        }
예제 #10
0
        private async void UpdateComicDataSource()
        {
            bool failedUpdate = false;

            try
            {
                await ComicDataSource.UpdateComicData();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to get update form web.");
                failedUpdate = true;
            }

            if (!failedUpdate)
            {
                await SaveComicData();
            }
        }
예제 #11
0
파일: App.xaml.cs 프로젝트: tadams1138/xkcd
        private async void UpdateComicDataSource()
        {
            bool failedUpdate = false;

            try
            {
                await ComicDataSource.UpdateComicData();
            }
            catch (Exception)
            {
                failedUpdate = true;
            }

            if (!failedUpdate)
            {
                await SaveComicData();
            }
            else
            {
                var dialog = new MessageDialog("Failed to get update form web.");
                await dialog.ShowAsync();
            }
        }
예제 #12
0
        // Load data for the ViewModel Items
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string number;
            Comic  comic;

            if (NavigationContext.QueryString.TryGetValue(NumberKey, out number))
            {
                _currentComicNumber = Int32.Parse(number);
                comic = ComicDataSource.GetComic(_currentComicNumber);
            }
            else if (State.ContainsKey(NumberKey))
            {
                _currentComicNumber = (int)State[NumberKey];
                comic = ComicDataSource.GetComic(_currentComicNumber);
            }
            else
            {
                // On app load...
                comic = ComicDataSource.GetLatestComic();
                _currentComicNumber = comic.Number;
            }

            DataContext = comic;
        }
예제 #13
0
 private void ViewRandom(object sender, RoutedEventArgs e)
 {
     FlipView.SelectedItem = ComicDataSource.GetRandomComic();
 }
예제 #14
0
 private void ViewLatest(object sender, RoutedEventArgs e)
 {
     FlipView.SelectedItem = ComicDataSource.GetLatestComic();
 }
예제 #15
0
 private void LatestClick(object sender, EventArgs e)
 {
     DataContext = ComicDataSource.GetLatestComic();
 }
예제 #16
0
 private void RandomClick(object sender, EventArgs e)
 {
     DataContext = ComicDataSource.GetRandomComic();
 }