예제 #1
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            CardsGridView.ItemTemplate = SideATemplate;
            if (e.Parameter != null)
            {
                Dictionary<String, Object> p = e.Parameter as Dictionary<String, Object>;
                if (p.ContainsKey("DeckFile"))
                {
                    loadDeckFromFile(p["DeckFile"] as StorageFile);
                }
                else if (p.ContainsKey("Deck"))
                {
                    this.currentDeck = p["Deck"] as Deck;
                    this.DataContext = this.currentDeck;
                }
                if (p.ContainsKey("Card"))
                {
                    CardsGridView.SelectedItem = p["Card"] as Card;
                    CardsGridView.Loaded += scrollToSelected;
                }

            }
            else
            {
                currentDeck = new Deck();
                this.currentDeck.title = "My Deck Name";
                this.currentDeck.sideAName = "Side A";
                this.currentDeck.sideBName = "Side B";
                this.DataContext = this.currentDeck;
            }


        }
예제 #2
0
 private async void loadData(StorageFile file) {
     //File Picker, feed to processor, wait and show progress
     DeckPackageProcessor dpp = new DeckPackageProcessor();
     progring.IsEnabled = true;
     progring.IsActive = true;
     await dpp.readPackageAsync(file);
     //Once we're done, kill progress, set up controls, and update the display
     progring.IsEnabled = false;
     progring.IsActive = false;
     NextCardBtn.Visibility = Visibility.Visible;
     PrevCardBtn.Visibility = Visibility.Visible;
     this.currentDeck = dpp.deck;
     this.currentDeck.shuffle();
     this.DataContext = this.currentDeck;
     CardStackPanel.DataContext = this.currentDeck.getNextCard();
     this.updateVisibleCard();
 }
예제 #3
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                Dictionary<String, Object> p = e.Parameter as Dictionary<String, Object>;
                if (p.ContainsKey("Deck"))
                {
                    this.currentDeck = p["Deck"] as Deck;
                    this.DataContext = this.currentDeck;
                }

            }
            else
            {
                currentDeck = new Deck();
                this.currentDeck.title = "My new deck";
                this.currentDeck.sideAName = "Side A";
                this.currentDeck.sideBName = "Side B";
                this.DataContext = this.currentDeck;
            }
        }
예제 #4
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {            
            //e.Parameter should contain deck info, either StorageFile or Deck object
            if (e.Parameter != null)
            {
                Dictionary<String, Object> p = e.Parameter as Dictionary<String, Object>;
                if (p.ContainsKey("DeckFile"))
                {
                    loadData(p["DeckFile"] as StorageFile);
                }
                else if (p.ContainsKey("Deck"))
                {
                    this.currentDeck = p["Deck"] as Deck;
                    this.currentDeck.shuffle();
                    this.DataContext = this.currentDeck;
                    CardStackPanel.DataContext = this.currentDeck.getNextCard();
                    this.updateVisibleCard();
                }

            }
        }
예제 #5
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                Dictionary<String, Object> p = e.Parameter as Dictionary<String, Object>;
                if (p.ContainsKey("Deck"))
                {
                    this.currentDeck = p["Deck"] as Deck;
                    this.DataContext = this.currentDeck;
                    if (p.ContainsKey("Card"))
                    {
                        this.currentCard = p["Card"] as Card;
                    }
                    else
                    {
                        this.currentCard = new Card();
                        this.isNewCard = true;
                    }
                    SideAStackPanel.DataContext = this.currentCard;
                    SideBStackPanel.DataContext = this.currentCard;
                    if (this.currentCard.hasSideAImage()) {
                        ClearSideAImgBtn.IsEnabled = true;
                    }
                    if (this.currentCard.hasSideBImage())
                    {
                        ClearSideBImgBtn.IsEnabled = true;
                    }
                }
                else
                {
                    ShowErrorAndGoBack("The current deck is invalid");
                }

            }
            else
            {
                ShowErrorAndGoBack("The current deck is invalid");
            }

        }
예제 #6
0
 public DeckPackageProcessor(String p)
 {
     this.deck = new Deck();
     this.packagePath = p;
 }
예제 #7
0
        public async Task<bool> writePackageAsync(StorageFile file, Deck outDeck)
        {
            this.deck = outDeck;
            StorageFolder tmpFolder = ApplicationData.Current.TemporaryFolder;
            //create a MemoryStream to build ZipArchive in Memory
            using (MemoryStream zipStream = new MemoryStream())
            {

                //Create ZipArchive using MemoryStream
                using (ZipArchive archive = new ZipArchive(zipStream,ZipArchiveMode.Create,true)) { //leave zipstream open so we can copy from it later.
                    //Write File(s) to ZipArchive as entries
                    //for every image referenced by a card, we'll need to copy them over
                    String[] segments;
                    ZipArchiveEntry en;
                    foreach (Card c in this.deck.cards)
                    {
                        if (c.hasSideAImage())
                        {
                            segments = c.sideAImage.UriSource.Segments;
                            StorageFile inFile = await tmpFolder.GetFileAsync(segments[segments.Count() - 1]); //to be copied

                            using (Stream s = await inFile.OpenStreamForReadAsync()) //incoming stream
                            {
                                en = archive.CreateEntry(segments[segments.Count() - 1]);
                                using (Stream sout = en.Open()) //outgoing stream. Can't use en.Open() directly because it won't get properly disposed.
                                {
                                    await s.CopyToAsync(sout);
                                }
                            }
                        }
                        if (c.hasSideBImage())
                        {
                            segments = c.sideBImage.UriSource.Segments;
                            StorageFile inFile = await tmpFolder.GetFileAsync(segments[segments.Count() - 1]); //to be copied

                            using (Stream s = await inFile.OpenStreamForReadAsync()) //incoming stream
                            {
                                en = archive.CreateEntry(segments[segments.Count() - 1]);
                                using (Stream sout = en.Open()) //outgoing stream. Can't use en.Open() directly because it won't get properly disposed.
                                {
                                    await s.CopyToAsync(sout);
                                }
                            }
                        }

                    }
                    //Then we write the deck description file
                    deckToXml();
                    en = archive.CreateEntry("deckdescription.xml");
                    using (StreamWriter sw = new StreamWriter(en.Open()))
                    {
                        sw.Write(this.deckXml);
                    }

                }
            //Copy MemoryStream (entire Zip Archive) to file specified
                zipStream.Position = 0;
                using (Stream s = await file.OpenStreamForWriteAsync())
                {
                    zipStream.CopyTo(s);
                }
            }

            return true;
        }
예제 #8
0
 public DeckPackageProcessor()
 {
     this.deck = new Deck();
     this.packagePath = null;
 }
예제 #9
0
 private async void loadDeckFromFile(StorageFile file)
 {
     //File Picker, feed to processor, wait and show progress
     DeckPackageProcessor dpp = new DeckPackageProcessor();
     progressRing.IsEnabled = true;
     progressRing.IsActive = true;
     if (await dpp.readPackageAsync(file))
     {
         //Once we're done, kill progress, set up controls, and update the display
         progressRing.IsEnabled = false;
         progressRing.IsActive = false;
         this.currentDeck = dpp.deck;
         this.DataContext = this.currentDeck;
     }
     else
     {
         Windows.UI.Popups.MessageDialog errorDialog = new Windows.UI.Popups.MessageDialog("There was a problem loading the file you selected. Make sure you've selected a valid QuizCards deck.", "Uh oh! I couldn't load that file.");
         await errorDialog.ShowAsync();
         Frame.Navigate(typeof(LandingPage));
     }
     //CardsGridView.DataContext = this.currentDeck;       
 }