예제 #1
0
 public Lesson(Lesson other)
 {
     Fill(other);
 }
예제 #2
0
        public static String ImportFromFile(Stream importStream, out List <Lesson> lessons, out int vocabRound, out int kanjiRound)
        {
            kanjiRound = 0;
            vocabRound = 0;

            lessons = new List <Lesson>();

            StringBuilder sb = new StringBuilder();

            using (AppStreamReader sr = new AppStreamReader(importStream))
            {
                try
                {
                    vocabRound = Convert.ToInt32(sr.ReadLine());
                    kanjiRound = Convert.ToInt32(sr.ReadLine());

                    int importedLessons = 0;
                    int importedWords   = 0;
                    int importedKanjis  = 0;
                    int importedClozes  = 0;

                    while (!sr.EndOfStream)
                    {
                        Lesson lesson = new Lesson(sr.ReadLine());

                        for (int i = 0; i < lesson.size; ++i)
                        {
                            switch (lesson.Type)
                            {
                            case Lesson.EType.vocab: lesson.Words.Add(new Word(sr.ReadLine(), lesson)); break;

                            case Lesson.EType.insert: lesson.Clozes.Add(new Cloze(sr.ReadLine(), lesson)); break;

                            case Lesson.EType.kanji: lesson.Kanjis.Add(new Kanji(sr.ReadLine(), lesson)); break;
                            }
                        }

                        lessons.Add(lesson);

                        importedWords  += lesson.Words.Count;
                        importedClozes += lesson.Clozes.Count;
                        importedKanjis += lesson.Kanjis.Count;
                    }

                    importedLessons = lessons.Count;

                    sb.AppendLine(importedLessons + " Lektionen,");
                    sb.AppendLine(importedWords + " Vokabeln,");
                    sb.AppendLine(importedKanjis + " Kanjis und");
                    sb.AppendLine(importedClozes + " Lückentexte gefunden");
                    sb.AppendLine("Datenbank wirklich wiederherstellen?");
                    sb.AppendLine("Achtung! Dabei wird die derzeitige Datenbank überschrieben!");
                }
                catch (Exception e)
                {
                    sb.Clear();
                    sb.AppendLine("Import Fehlgeschlagen in Zeile: " + sr.CurrentLine);
                    sb.AppendLine("System: " + e.Message);
                }
            }

            return(sb.ToString());
        }
예제 #3
0
 public void Fill(Lesson other)
 {
     name = other.name;
     size = other.size;
     type = other.type;
 }
예제 #4
0
        public static String AddContentFromFile(Stream contentStream)
        {
            using (AppStreamReader sr = new AppStreamReader(contentStream))
            {
                StringBuilder sb = new StringBuilder();

                try
                {
                    List <Lesson> lessons = new List <Lesson>();

                    int importedLessons = 0;
                    int importedWords   = 0;
                    int importedKanjis  = 0;
                    int importedClozes  = 0;

                    //read content from stream till end
                    while (!sr.EndOfStream)
                    {
                        Lesson lesson = new Lesson(sr.ReadLine());

                        for (int i = 0; i < lesson.size; ++i)
                        {
                            switch ((Lesson.EType)lesson.Type)
                            {
                            case Lesson.EType.vocab: lesson.Words.Add(new Word(sr.ReadLine(), lesson)); break;

                            case Lesson.EType.kanji: lesson.Kanjis.Add(new Kanji(sr.ReadLine(), lesson)); break;

                            case Lesson.EType.insert: lesson.Clozes.Add(new Cloze(sr.ReadLine(), lesson)); break;
                            }
                        }

                        importedWords  += lesson.Words.Count;
                        importedClozes += lesson.Clozes.Count;
                        importedKanjis += lesson.Kanjis.Count;

                        lessons.Add(lesson);
                    }

                    importedLessons = lessons.Count;

                    foreach (Lesson lesson in lessons)
                    {
                        switch (lesson.Type)
                        {
                        case Lesson.EType.vocab: ImportWords(lesson); break;

                        case Lesson.EType.insert: ImportClozes(lesson); break;

                        case Lesson.EType.kanji: ImportKanjis(lesson); break;
                        }
                    }

                    sb.AppendLine("Import erfolreich (^ω^)/");
                    sb.AppendLine("Importierte Lektionen:\t" + importedLessons);
                    sb.AppendLine("Importierte Wörter:\t" + importedWords);
                    sb.AppendLine("Importierte Kanjis:\t" + importedKanjis);
                    sb.AppendLine("Importierte Lückentexte:\t" + importedClozes);

                    database.SubmitChanges();
                }
                catch (Exception e)
                {
                    sb.Clear();
                    sb.AppendLine("Inhalt hinzufügen Fehlgeschlagen in Zeile: " + sr.CurrentLine);
                    sb.AppendLine("System: " + e.Message);
                }

                return(sb.ToString());
            }
        }