Ejemplo n.º 1
0
 /**
  * Pulls next card off Remaining deck, or Not Memorized deck, if available.
  * It makes currentSlide equal to this card.
  */
 private void ShowNextAvailableSlide()
 {
     if (deck.notMemorizedSlides.Count > 0)
     {
         currentSlide = deck.notMemorizedSlides[0];
     }
     else if (deck.remainingSlides.Count > 0)
     {
         currentSlide = deck.remainingSlides[0];
     }
     else
     {
         currentSlide = null;
     }
 }
Ejemplo n.º 2
0
 private void btnAddSlide_Click(object sender, RoutedEventArgs e)
 {
     Slide newSlide = new Slide(txtQuestion.Text, txtAnswer.Text);
     mainWindowRef.deck.notMemorizedSlides.Add(newSlide);
     Close();
 }
Ejemplo n.º 3
0
        /**
         * Prompt the user to browse for a file in Mnemosyne XML format.
         * Then import that file into the Not Memorized deck.
         **/
        private void ImportFile()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog().GetValueOrDefault())
            {
                try
                {
                    using (Stream fileStream = dialog.OpenFile())
                    {
                        StreamReader streamReader = new StreamReader(fileStream);
                        string xmlString = streamReader.ReadToEnd();
                        fileStream.Close();

                        using (XmlReader xmlReader = XmlReader.Create(new StringReader(xmlString)))
                        {
                            List<Slide> slidesFromFile = new List<Slide>();

                            while (xmlReader.ReadToFollowing("item"))
                            {
                                if (xmlReader.IsStartElement())
                                {
                                    xmlReader.ReadToFollowing("Q");
                                    xmlReader.Read();
                                    String question = xmlReader.Value;
                                    xmlReader.ReadToFollowing("A");
                                    xmlReader.Read();
                                    String answer = xmlReader.Value;
                                    Slide slide = new Slide(question, answer);
                                    slidesFromFile.Add(slide);
                                }
                            }

                            deck.notMemorizedSlides.AddRange(slidesFromFile);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }

                HandleNewSlides();
            }
        }