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); } }
private async Task SaveComicData() { var outFile = await _storageFolder.CreateFileAsync(ComicsDataFile, CreationCollisionOption.ReplaceExisting); using (var saveStream = await outFile.OpenStreamForWriteAsync()) { ComicDataSource.SaveComicData(saveStream); } }
private void RefreshCollection() { var newCollection = ComicDataSource.GetComics(_month.Year, _month.Month); _comics.Clear(); foreach (Comic c in newCollection) { _comics.Add(c); } }
private void RefreshYearsCollection() { var sampleDataGroups = ComicDataSource.GetYears(); _years.Clear(); foreach (int year in sampleDataGroups) { _years.Add(year); } }
private void RefreshCollection() { var newCollection = ComicDataSource.GetComics(_queryText); _comics.Clear(); foreach (Comic c in newCollection) { _comics.Add(c); } }
private void RefreshCollection() { var newCollection = ComicDataSource.GetMonths(_year); _months.Clear(); foreach (DateTime month in newCollection) { _months.Add(month); } }
/// <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; }
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); }
/// <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; }
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(); } }
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(); } }
// 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; }
private void ViewRandom(object sender, RoutedEventArgs e) { FlipView.SelectedItem = ComicDataSource.GetRandomComic(); }
private void ViewLatest(object sender, RoutedEventArgs e) { FlipView.SelectedItem = ComicDataSource.GetLatestComic(); }
private void LatestClick(object sender, EventArgs e) { DataContext = ComicDataSource.GetLatestComic(); }
private void RandomClick(object sender, EventArgs e) { DataContext = ComicDataSource.GetRandomComic(); }