private async void ButtonAdd_Click(object sender, EventArgs e)
        {
            string[] words = new string[dataGridViewWords.RowCount];

            for (int i = 0; i < dataGridViewWords.RowCount; i++)
            {
                words[i] = dataGridViewWords.Rows[i].Cells[1].Value.ToString();
            }

            int countWordsBefore = wordList.Count();

            wordList.Add(words);
            wordList.Save();
            int countWordsAfter = wordList.Count();

            if (countWordsAfter != countWordsBefore + 1)
            {
                await ShowInfoTextAsync("Duplicate", Color.DarkRed);
            }
            else
            {
                await ShowInfoTextAsync("Added.", Color.Green);
            }

            FormAddWorks_OnWordsAdded(this, new EventArgs());
        }
Beispiel #2
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (_wordList.Count() == 0)
            {
                MessageBox.Show("There is no word to remove");
            }
            if (WorddataGridView.CurrentCell == null)
            {
                return;
            }

            var wordIndex = WorddataGridView.CurrentCell.RowIndex;

            if (WorddataGridView.SelectedCells[0].Value == null)
            {
                WorddataGridView.Rows.RemoveAt(wordIndex);
                return;
            }

            var word = WorddataGridView.SelectedCells[0].Value.ToString();


            WorddataGridView.Rows.RemoveAt(wordIndex);

            _wordList.Remove(0, word);
            WorldCounttextBox.Text = _wordList.Count().ToString();
        }
Beispiel #3
0
 public static void SelectedListDoesntContainWords(WordList loadedList)
 {
     if (loadedList.Count() < 1)
     {
         throw new Exception($"This list doesn't contain any words.");
     }
 }
 private void ShowAllWords()
 {
     dataGridViewWords.Rows.Clear();
     WordList.List(0, translations => dataGridViewWords.Rows.Add(translations));
     labelNoOfWords.Text = WordList.Count().ToString();
     dataGridViewWords.ClearSelection();
 }
Beispiel #5
0
        private void updateDataList()
        {
            var languages = wordListObject.Languages;

            listBoxLanguages.Items.Clear();
            listBoxLanguages.Items.AddRange(languages);
            var counter = wordListObject.Count();

            wordListCount.Text = $"Word count: {counter}";

            dt    = new DataTable();
            dtAdd = new DataTable();

            dt.Rows.Clear();
            dtAdd.Rows.Clear();
            dtAdd.Columns.Add();
            dtAdd.Columns.Add();
            var numberOfLanguages = 0;

            for (var i = 0; i < languages.Length; i++)
            {
                dt.Columns.Add(languages[i]);
                dtAdd.Rows.Add(languages[i]);
                numberOfLanguages = i;
            }

            Action <string[]> listWords = word => { dt.Rows.Add(word); };

            wordListObject.List(numberOfLanguages, listWords);
            dataGridView2.DataSource = dtAdd;
            dataGridView1.DataSource = dt;
        }
Beispiel #6
0
        private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Removebutton.Enabled   = true;
            Savebutton.Enabled     = true;
            Practicebutton.Enabled = true;
            AddWordbutton.Enabled  = true;

            var name = listBox.GetItemText(listBox.SelectedItem);

            _wordList = WordList.LoadList(name);


            if (_wordList == null)
            {
                return;
            }

            const int sortBy = 0;

            var languages = _wordList.Languages;

            WorddataGridView.Columns.Clear();
            WorddataGridView.Rows.Clear();
            WorddataGridView.Refresh();

            WorldCounttextBox.Text = _wordList.Count().ToString();
            foreach (var item in languages)
            {
                WorddataGridView.Columns.Add(item, item);
            }

            _wordList.List(sortBy, x => { WorddataGridView.Rows.Add(x); });
        }
        private void Save()
        {
            if (listBox1.SelectedItem?.ToString() == null)
            {
                return;
            }
            FileName = listBox1.SelectedItem.ToString();
            var modifiedList  = new WordList(FileName, WordList.LoadList(FileName).Languages);
            var correctLength = true;

            for (var i = 0; i < TranslationGrid.Rows.Count; i++)
            {
                var words = new string[modifiedList.Languages.Length];
                for (var j = 0; j < words.Length; j++)
                {
                    if (TranslationGrid.Rows[i].Cells[j].Value != null &&
                        !string.IsNullOrWhiteSpace(TranslationGrid.Rows[i].Cells[j].Value.ToString()))
                    {
                        words[j] = TranslationGrid.Rows[i].Cells[j].Value.ToString().ToLower();
                    }
                    else
                    {
                        var emptySlots = TranslationGrid.Rows.Count - modifiedList.Count();
                        for (var k = 0; k < emptySlots; k++)
                        {
                            TranslationGrid.Rows.RemoveAt(modifiedList.Count());
                        }

                        var caption = "Error Detected in Input";
                        var message =
                            "You did not add a word for every language. \nThe empty indexes will not be saved";
                        var buttons = MessageBoxButtons.OK;
                        MessageBox.Show(message, caption, buttons);
                        correctLength = false;
                        break;
                    }
                }

                if (!correctLength)
                {
                    break;
                }
                modifiedList.Add(words);
                modifiedList.Save();
                CountLabel.Text = $"There are {WordList.LoadList(FileName).Count()} words in the list";
            }
        }
 private void listBoxLists_SelectedIndexChanged(object sender, EventArgs e)
 {
     listBoxLanguages.Items.Clear();
     LoadedList            = WordList.LoadList(listBoxLists.SelectedItem.ToString());
     labelWordCounter.Text = LoadedList.Count().ToString();
     for (int i = 0; i < LoadedList.Languages.Length; i++)
     {
         listBoxLanguages.Items.Add(LoadedList.Languages[i]);
     }
 }
        /// <summary>
        /// Skriver ut hur många ord det finns i namngiven lista.
        /// </summary>
        /// <param name="args">Måste innehålla parametern "list name".</param>
        /// <returns>True om kommandot är skrivet i rätt format, annars false.</returns>
        static bool ExecuteCountCommand(string[] args)
        {
            if (args.Length == 2)
            {
                string   listName = args[1];
                WordList wordList = WordList.LoadList(listName);

                if (wordList == null)
                {
                    PrintWordListNotLoadedError();
                    return(true);
                }

                Console.WriteLine("Word count in {0}: {1}", listName, wordList.Count());
                Console.WriteLine("Translation count in {0}: {1}", listName, wordList.Count() * wordList.Languages.Length);
                return(true);
            }
            return(false);
        }
Beispiel #10
0
        private static void HandleCount(List <object> userInput)
        {
            WordList wordList = WordList.LoadList(userInput[2].ToString());

            if (wordList == null)
            {
                System.Console.WriteLine("\nThe list don't exist.\n");
                return;
            }
            System.Console.WriteLine(
                $"\nThere are {wordList.Count()} words in list '{wordList.Name}'\n");
        }
 private void ListBoxWordLists_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBoxWordLists?.SelectedItem == null)
     {
         return;
     }
     listBoxLanguages.Items.Clear();
     WordList = WordList.LoadList(listBoxWordLists?.SelectedItem?.ToString());
     listBoxLanguages.Items.AddRange(WordList.Languages);
     labelWordCount.Text  = $"Word Count: {WordList.Count()}";
     buttonSelect.Enabled = true;
 }
        private void listBoxLists_SelectedIndexChanged(object sender, EventArgs e)
        {
            buttonAddWord.Enabled    = false;
            buttonPractice.Enabled   = false;
            buttonRemoveWord.Enabled = false;
            dataGridViewWords.Columns.Clear();
            dataGridViewWords.Rows.Clear();
            dataGridViewWords.ClearSelection();
            labelNoOfWords.Text = "";

            try
            {
                WordList = WordList.LoadList(listBoxLists.SelectedItem.ToString());

                if (WordList.Languages.Length < 4)
                {
                    dataGridViewWords.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                }
                else
                {
                    dataGridViewWords.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                }

                foreach (string language in WordList.Languages)
                {
                    dataGridViewWords.Columns.Add(language, language.ToUpper());
                }
                ShowAllWords();

                buttonAddWord.Enabled = true;
                if (WordList.Count() > 0)
                {
                    buttonPractice.Enabled = true;
                }
                listBoxLists.Focus();
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show($"The list '{listBoxLists.SelectedItem}' wasn't found.", "Error");
            }
            catch (Exception ex)
            {
                if (ex is FileLoadException || ex is InvalidDataException)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
                else
                {
                    MessageBox.Show($"Could not read '{listBoxLists.SelectedItem}': {ex.Message}.", "Error");
                }
            }
        }
Beispiel #13
0
        private static void HandleAdd(List <object> userInput)
        {
            WordList wordList = WordList.LoadList(userInput[2].ToString());

            if (wordList == null)
            {
                System.Console.WriteLine($"\nThe list named '{userInput[2]}' doesn't exist. Please add it first.\n");
                return;
            }
            System.Console.WriteLine("\nPress enter (empty line) to stop input of new words.\n");
            var           userStrings  = new List <string>();
            int           i            = 1;
            int           duplicates   = 0;
            List <string> consoleTexts = CreateConsoleTextsWhenAddingWords(wordList);
            string        input        = ReturnAllowedStringsFromConsole(consoleTexts[i - 1], "Only letters and numbers are allowed.");

            while (input != string.Empty)
            {
                userStrings.Add(input);
                if (i % wordList.Languages.Length == 0) //modulo
                {
                    int countWordsBefore = wordList.Count();
                    wordList.Add(userStrings.ToArray());
                    wordList.Save();
                    int countWordsAfter = wordList.Count();
                    if (countWordsAfter != countWordsBefore + 1)
                    {
                        System.Console.WriteLine("\nNot added. The new word was already in the list.\n");
                        duplicates++;
                    }
                    userStrings.Clear();
                }
                i++;
                input = ReturnAllowedStringsFromConsole(consoleTexts[(i - 1) % wordList.Languages.Length],
                                                        "Only letters and numbers are allowed.");
            }

            System.Console.WriteLine($"\n{((i - 1) / wordList.Languages.Length) - duplicates} word(s) was added to list '{wordList.Name}'.\n");
        }
Beispiel #14
0
        static void CountWords(string[] args)
        {
            if (args.Length < 2)
            {
                ShowHelp("You must specify a list name, as:", "-count");
                return;
            }
            WordList wordList = LoadWordList(args[1]);

            if (wordList == null)
            {
                return;
            }

            ShowMessage($"The list '{args[1]}' contains {wordList.Count()} words.");
        }
Beispiel #15
0
        private void listBoxWordLists_Click(object sender, EventArgs e)
        {
            if (listBoxWordLists.SelectedItem == null)
            {
                return;
            }
            listBoxLanguages.Items.Clear();
            ListName = WordList.LoadList(listBoxWordLists.SelectedItem.ToString());
            foreach (var language in ListName.Languages)
            {
                listBoxLanguages.Items.Add(language);
            }

            wordCount.Text       = $"Word count: {ListName.Count()}";
            buttonSelect.Enabled = true;
        }
 private void buttonRemoveWord_Click(object sender, EventArgs e)
 {
     try
     {
         WordList.Remove(0, dataGridViewWords.SelectedRows[0].Cells[WordList.Languages[0]].Value.ToString());
         WordList.Save();
         ShowAllWords();
         if (WordList.Count() == 0)
         {
             buttonPractice.Enabled = false;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Could not remove word: {ex.Message}.", "Error");
     }
 }
Beispiel #17
0
 //Shows the languages of the selected list - DONE!
 private void listBox1_ShowLists_SelectedIndexChanged(object sender, EventArgs e)
 {
     listBox2_ShowLanguages.Items.Clear();
     if (listBox1_ShowLists.SelectedItem != null)
     {
         WordList wordList = WordList.LoadList(listBox1_ShowLists.SelectedItem.ToString());
         foreach (var item in wordList.Languages)
         {
             listBox2_ShowLanguages.Items.Add(Capitilize(item));
         }
         //Displays number of words in the selected list.
         label_NumberOfWords.Text = Convert.ToString(wordList.Count());
     }
     else
     {
         MessageBox.Show("Please select a list!");
     }
 }
Beispiel #18
0
        private void button2_Click(object sender, EventArgs e) //New word-button.
        {
            if (listView1 != null)
            {
                LoadWordList wordList      = new LoadWordList(WordList.LoadList);
                WordList     wordList1     = wordList.Invoke(localPath);
                string[]     languages     = wordList1.Languages;
                bool         areWordsAdded = false;

                while (true)
                {
                    string[] translations     = new string[wordList1.Languages.Length];
                    string   firstTranslation = translations[0] = Interaction.InputBox($"Type a word in {wordList1.Languages[0]}");

                    if (firstTranslation == string.Empty)
                    {
                        break;
                    }

                    for (int i = 1; i < translations.Length; i++)
                    {
                        string wordsToTranslate;
                        do
                        {
                            wordsToTranslate = Interaction.InputBox($"Translate {firstTranslation} to {wordList1.Languages[i]}");
                        } while (wordsToTranslate == string.Empty);

                        translations[i] = wordsToTranslate;
                    }
                    wordList1.Add(translations);
                    areWordsAdded = true;
                }
                if (areWordsAdded)
                {
                    wordList1.Save();
                }
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
            else if (listView1 == null)
            {
                MessageBox.Show("You have to choose a list to add words to.", "Warning!");
                btn_NewWord.Enabled = false;
            }
        }
 private void buttonAddWord_Click(object sender, EventArgs e)
 {
     using (FormAddWord formAddWord = new FormAddWord(WordList))
     {
         formAddWord.ShowDialog();
         try
         {
             ShowAllWords();
             if (WordList.Count() > 0)
             {
                 buttonPractice.Enabled = true;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show($"Could not show words: {ex.Message}.", "Error");
         }
     }
 }
Beispiel #20
0
        private void button3_Click(object sender, EventArgs e) //remove-button
        {
            LoadWordList wordList  = new LoadWordList(WordList.LoadList);
            WordList     wordList1 = wordList.Invoke(localPath);

            string[] languages       = wordList1.Languages;
            string   languagesInList = Interaction.InputBox("Choose the language you want to remove a word from: ");

            string inputRemoveWord;
            int    langIndex = -1;

            inputRemoveWord = Interaction.InputBox("Please enter word(s) you wish to remove." +
                                                   "\nSeparate the words with semicolon", "Remove word");
            string[] wordsToBeRemoved = inputRemoveWord.Split(' ', ';').ToArray <string>();


            for (int i = 0; i < languages.Length; i++)
            {
                if (languages[i].Equals(languagesInList, StringComparison.InvariantCultureIgnoreCase))
                {
                    langIndex = i;
                    break;
                }
            }

            if (langIndex > -1)
            {
                foreach (var w in wordsToBeRemoved)
                {
                    if (wordList1.Remove(langIndex, w))
                    {
                        MessageBox.Show($"{w} was removed from list.");
                    }
                    else
                    {
                        MessageBox.Show($"Could not find the word {w}");
                    }
                }
                wordList1.Save();
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
        }
Beispiel #21
0
        private void btn_viewList_Click(object sender, EventArgs e) //Load list-button
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = localPath;
                openFileDialog.Filter           = "(*.dat)|*.dat";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    listView1.Items.Clear();

                    localPath = openFileDialog.FileName.Split('.')[0];

                    WordList list = WordList.LoadList(localPath);
                    string[] lang = list.Languages;

                    string output = string.Join(',', lang);

                    lbl_languages.Visible = true;
                    lbl_languages.Text    = $"Languages: " + output;


                    //Enables the counter-lable
                    label1.Visible       = true;
                    label1.Text          = "Number of words: " + list.Count().ToString();
                    lbl_fileName.Visible = true;
                    lbl_fileName.Text    = "List loaded:\n" + localPath;
                }
            }
            //Enables buttons after list is loaded.
            btn_NewWord.Enabled    = true;
            btn_removeWord.Enabled = true;
            btn_sortList.Enabled   = true;
            btn_practice.Enabled   = true;
        }
Beispiel #22
0
        private void button4_Click(object sender, EventArgs e) //New list - button
        {
            string localPath     = WordList.localPath;
            string fileNameInput = Interaction.InputBox("Enter the name of the new file.\n " + "Exclude the file type.", "New list", "", -1, -1);

            if (fileNameInput == "" || fileNameInput == " ")
            {
                MessageBox.Show("Invalid input. Filename can't be empty.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string languagesInput = Interaction.InputBox($"Enter which languages to be in \"{fileNameInput}\"." +
                                                             $"\nSeparate the languages with semicolon.", "Languages", "", -1, -1);
                if (languagesInput == "" || languagesInput == " ")
                {
                    MessageBox.Show("Invalid input. Languages needs to be added.", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        var fileCreated = File.Create(Path.Combine(localPath, fileNameInput + ".dat"));
                        fileCreated.Close();
                        MessageBox.Show(fileNameInput + " created successfully.", "New list created");

                        File.WriteAllText(Path.Combine(localPath, fileNameInput + ".dat"), languagesInput);
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message, "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                LoadWordList wordList      = new LoadWordList(WordList.LoadList);
                WordList     wordList1     = wordList.Invoke(fileNameInput);
                string[]     languages     = wordList1.Languages;
                bool         areWordsAdded = false;

                while (true)
                {
                    string[] translations     = new string[wordList1.Languages.Length];
                    string   firstTranslation = translations[0] = Interaction.InputBox($"Type a word in {wordList1.Languages[0]}");

                    if (firstTranslation == string.Empty)
                    {
                        break;
                    }

                    for (int i = 1; i < translations.Length; i++)
                    {
                        string wordsToTranslate;
                        do
                        {
                            wordsToTranslate = Interaction.InputBox($"Translate {firstTranslation} to {wordList1.Languages[i]}");
                        } while (wordsToTranslate == string.Empty);

                        translations[i] = wordsToTranslate;
                    }
                    wordList1.Add(translations);
                    areWordsAdded = true;
                }
                if (areWordsAdded)
                {
                    wordList1.Save();
                }
                label1.Text = "Number of words: " + wordList1.Count().ToString();
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            string[]      listArray;
            List <string> languages  = new List <string>();
            Regex         regexMatch = new(@"^[a-z.\-A-Z]{1,20}$");

            for (int i = 0; i < args.Length; i++)
            {
                args[i] = args[i].ToLower();
            }
            if (args[0] == "-lists")
            {
                listArray = WordList.GetLists();
                foreach (var name in listArray)
                {
                    //hämta information fårn en mapp
                    Console.WriteLine(name);
                }
                return;
            }
            for (int i = 0; i < args.Length - 2; i++)
            {
                languages.Add(args[i + 2]);
            }
            WordList wordList = new WordList(args[1], languages.ToArray());

            DirectoryInfo directory = new (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

            if (args.Length < 2)
            {
                getInfo();
                Environment.Exit(0);
            }
            else if (args[0] == "-new")
            {
                if (Match(regexMatch, args) && args.Length > 3)
                {
                    args[1] = args[1].Trim(new Char[] { ' ', '<', '>' });
                    NewList(wordList);
                }
                else
                {
                    getInfo();
                }


                /*
                 * using (StreamWriter newFile = new (directory + "\\" + args[1]))
                 * {
                 *  for (int i = 2; i < args.Length; i++)
                 *  {
                 *      args[i] = args[i].Trim(new Char[] { ' ', '<', '>' });
                 *      if (i == args.Length - 1)
                 *      {
                 *          newFile.Write(args[i]);
                 *      }
                 *      else newFile.Write(args[i] + ", ");
                 *  }
                 * }*/
            }
            else if (args[0] == "-add")
            {
                try
                {
                    wordList = WordList.LoadList(args[1]);
                }
                catch (Exception)
                {
                    Console.WriteLine("File is empty!");
                    getInfo();
                    return;
                }
                if (Match(regexMatch, args))
                {
                    AddWord(wordList);
                }
            }
            else if (args[0] == "-remove")
            {
                if (Match(regexMatch, args))
                {
                    RemoveWord(args);
                }
            }
            else if (args[0] == "-words")
            {
                try
                {
                    wordList = WordList.LoadList(args[1]);
                }
                catch (Exception)
                {
                    Console.WriteLine("File is empty!");
                    getInfo();
                    return;
                }
                if (Match(regexMatch, args))
                {
                    for (int i = 0; i < wordList.Languages.Length; i++)
                    {
                        if (wordList.Languages[i] == args[2])
                        {
                            PrintList(i, wordList);
                        }
                    }
                }
            }
            else if (args[0] == "-count")
            {
                if (Match(regexMatch, args))
                {
                    Console.WriteLine("There is " + wordList.Count() + " Words in this list!");
                }
            }
            else if (args[0] == "-practice")
            {
                try
                {
                    wordList = WordList.LoadList(args[1]);
                }
                catch (Exception)
                {
                    Console.WriteLine("File is empty!");
                    getInfo();
                    return;
                }
                if (Match(regexMatch, args))
                {
                    practiceWord(wordList);
                }
            }
            else
            {
                getInfo();
            }
        }
    //PICK WORD

    private static string PickWord()
    {
        return(words[randomGen.Next(0, words.Count() - 1)]);
    }
Beispiel #25
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Use any of following parameters:\n");
                Console.WriteLine("-lists");
                Console.WriteLine("-new < list name > < language 1 > < language 2 > .. < language n >");
                Console.WriteLine("-add < list name >");
                Console.WriteLine("-remove < list name > < language > < word 1 > < word 2 > .. < word n >");
                Console.WriteLine("-words<list name> < sortByLanguage >");
                Console.WriteLine("-count < list name >");
                Console.WriteLine("-practice<list name>\n");
            }
            else
            {
                switch (Input(args)[0])
                {
                case "-lists":
                    var files = WordList.GetLists();
                    foreach (var file in files)
                    {
                        if (WordList.LoadList(file) != null)
                        {
                            Console.WriteLine(file);
                        }
                    }
                    break;

                case "-new":
                    string name = args[1];

                    if (File.Exists(WordList.GetLists() + name + ".dat"))
                    {
                        Console.WriteLine($"{name} already exists! Give new name.");
                        return;
                    }

                    if (args.Length < 4)
                    {
                        Console.WriteLine(
                            $"Add at  least two languages to languages, you added{args.Length - 2}");
                        break;
                    }

                    var languageList = new string[args.Length - 2];
                    for (int i = 2; i < args.Length; i++)
                    {
                        languageList[i - 2] = args[i];
                    }

                    WordList wordList = new WordList(name, languageList);
                    wordList.Save();
                    AddWords(wordList);
                    break;

                case "-add":
                    name = args[1];

                    if (WordList.LoadList(name) == null)
                    {
                        Console.WriteLine("List does not exists!");
                    }
                    else
                    {
                        AddWords(WordList.LoadList(name));
                    }
                    break;

                case "-remove":
                    var deleteLanguage = 0;
                    var list           = WordList.LoadList(args[1]);
                    if (args.Length >= 2 && list == null)
                    {
                        Console.WriteLine("List does not exists!");
                    }

                    else if (args.Length > 2 && list != null)
                    {
                        for (int i = 0; i < list.Languages.Length; i++)
                        {
                            if (list.Languages[i] == args[2])
                            {
                                deleteLanguage = i;
                            }
                        }

                        for (int i = 3; i < args.Length; i++)
                        {
                            Console.WriteLine(
                                list.Remove(deleteLanguage, args[i])
                                        ? $"The {list.Languages[deleteLanguage]} word {args[i]} was removed\n"
                                        : "Nothing was removed\n");
                        }
                    }
                    break;

                case "-words":
                    if (WordList.LoadList(args[1]) == null)
                    {
                        Console.WriteLine("List does not exists!\n");
                    }

                    else
                    {
                        var sortByTranslations = 0;
                        languageList = WordList.LoadList(args[1]).Languages;
                        if (args.Length > 2)
                        {
                            for (int i = 0; i < languageList.Length; i++)
                            {
                                if (args.Length > 1 && args[2] == languageList[i])
                                {
                                    sortByTranslations = i;
                                }
                            }
                        }

                        foreach (var languages in languageList)
                        {
                            Console.Write(languages.PadRight(20).ToUpper());
                        }

                        Console.WriteLine();
                        WordList.LoadList(args[1]).List(sortByTranslations, x =>
                        {
                            foreach (var text in x)
                            {
                                Console.Write(text.PadRight(20));
                            }

                            Console.WriteLine();
                        });
                    }
                    break;

                case "-count":
                    name = args[1];
                    Console.WriteLine(WordList.LoadList(name) == null
                            ? "List does not exists!\n"
                            :$"{WordList.LoadList(name).Count()} words in the list '{name}'\n");
                    break;

                case "-practice":
                    name = args[1];
                    if (WordList.LoadList(name) != null)
                    {
                        languageList = WordList.LoadList(name).Languages;
                        wordList     = WordList.LoadList(name);
                        if (wordList.Count() != 0)
                        {
                            var isRunning = true;
                            var score     = 0;
                            var attempts  = 0;
                            while (isRunning)
                            {
                                var practiceWord = wordList.GetWordToPractice();
                                Console.Write(
                                    $"Translate the  {languageList[practiceWord.FromLanguage]} word {practiceWord.Translations[practiceWord.FromLanguage]}" +
                                    $" to {languageList[practiceWord.ToLanguage]} translation: ");
                                var input = Console.ReadLine().ToLower();

                                if (input == practiceWord.Translations[practiceWord.ToLanguage].ToLower())
                                {
                                    Console.WriteLine("Wow great! Correct answer!");
                                    score++;
                                    attempts++;
                                }

                                else if (!string.IsNullOrWhiteSpace(input))
                                {
                                    Console.WriteLine($"The answer is wrong! The correct translation is {practiceWord.Translations[practiceWord.ToLanguage].ToLower()}");
                                    attempts++;
                                }

                                if (!string.IsNullOrWhiteSpace(input))
                                {
                                    continue;
                                }
                                Console.WriteLine($"Your score is  {score} out of {attempts}");
                                Console.WriteLine($"{(score * 100 / attempts)}% of your answers were correct.\n");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("This list is empty.\n");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Given list does not exists!\n");
                    }
                    break;
                }
            }
        }
        /// <summary>
        ///Ber användaren översätta ett slumpvis valt ord ur listan från ett slumpvis valt språk till ett annat.Skriver ut om det var rätt eller fel, och fortsätter fråga efter ord tills användaren lämnar en tom inmatning.Då skrivs antal övade ord ut, samt
        /// hur stor andel av orden man haft rätt på.
        /// </summary>
        /// <param name="args">Måste innehålla parametern "list name".</param>
        /// <returns>True om kommandot är skrivet i rätt format, annars false.</returns>
        static bool ExecutePracticeCommand(string[] args)
        {
            if (args.Length == 2)
            {
                WordList wordList = WordList.LoadList(name: args[1]);

                if (wordList == null)
                {
                    PrintWordListNotLoadedError();
                    return(true);
                }

                int score     = 0;
                var timeStart = DateTime.Now;

                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("Starting Word Practicing Game!");

                int    consumedCount = 0;
                Word[] consumedWords = new Word[wordList.Count() * wordList.Languages.Length];

                while (true)
                {
                    if (consumedCount >= consumedWords.Length)
                    {
                        EndPracticeAndPrintScore(score, timeStart);
                        return(true);
                    }

                    Word practiceWord = wordList.GetWordToPractice();

                    while (Array.Exists(consumedWords, w => w != null && w.Equals(practiceWord)))
                    {
                        practiceWord = wordList.GetWordToPractice();
                    }

                    consumedWords[consumedCount++] = practiceWord;

                    Console.ForegroundColor = ConsoleColor.Gray;

                    Console.Write("Please translate {0} in {1} to {2}: ",
                                  practiceWord.Translations[practiceWord.FromLanguage], wordList.Languages[practiceWord.FromLanguage], wordList.Languages[practiceWord.ToLanguage]);

                    string answer = Console.ReadLine();

                    if (!answer.Equals(practiceWord.Translations[practiceWord.ToLanguage], StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (answer == string.Empty)
                        {
                            EndPracticeAndPrintScore(score, timeStart);
                            return(true);
                        }

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Wrong answer!");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Correct answer!");

                        score++;
                    }
                }
            }
            return(false);
        }