Beispiel #1
0
        // Lolz; process for loading anki .apkg: rename to .zip, unzip, load .anki2 into sqlite, read cards based on format
        // defined in this particular anki deck
        public override FlashDeck GetFlashDeck(CardServer cardServer, string deckPath, string deckName = null)
        {
            deckName = deckName ?? GetDeckNameFromFileName(deckPath);

            // SQLite connection
            string           connectionString = String.Format("Data Source={0};Version=3;", deckPath);
            SQLiteConnection connection       = new SQLiteConnection(connectionString);

            connection.Open();

            // Get Reader
            string sql     = "select flds from notes";
            var    command = new SQLiteCommand(sql, connection);

            command.CommandType = CommandType.Text;
            SQLiteDataReader dataReader = command.ExecuteReader();

            // Read
            FlashDeck deck = FlashDeck.FromNothing(cardServer, deckName);

            string[] unicodeSpaceSeperator = { "\u001f" };
            while (dataReader.Read())
            {
                string   row      = Convert.ToString(dataReader["flds"]);
                string[] splitRow = row.Split(unicodeSpaceSeperator, StringSplitOptions.None);
                string   french   = splitRow[1];
                string   english  = splitRow[3];

                Card loadedCard = new Card(french, english);
                deck.AddCard(loadedCard);
            }

            return(deck);
        }
Beispiel #2
0
        private void CreateReverse()
        {
            Card reverseCard = new Card(_currentCard.Back, _currentCard.Front);

            if (CreateCardsControl.SelectedDeckToAddTo == null)
            {
                MessageBox.Show("No selected deck to add to, go select one on the create cards page first.");
                return;
            }
            _database.AddCardToDeck(reverseCard, CreateCardsControl.SelectedDeckToAddTo);
            _myDeck.AddCard(reverseCard);
        }
Beispiel #3
0
        private FlashDeck LoadSingleColumnCSV(CardServer cardServer, string deckPath, string deckName, string delimiter = ",")
        {
            FlashDeck deckToLoad = FlashDeck.FromNothing(cardServer, deckName);

            using (TextFieldParser deckCSVParser = new TextFieldParser(@deckPath, System.Text.Encoding.GetEncoding("iso-8859-1")))
            {
                deckCSVParser.HasFieldsEnclosedInQuotes = false;
                deckCSVParser.TextFieldType             = FieldType.Delimited;
                deckCSVParser.SetDelimiters(delimiter);
                while (!deckCSVParser.EndOfData)
                {
                    string[] flashCardSides = deckCSVParser.ReadFields();
                    Card     loadedCard     = new Card(flashCardSides[0], flashCardSides[1]);
                    deckToLoad.AddCard(loadedCard);
                }
            }
            return(deckToLoad);
        }