Пример #1
0
        public static string[] Languages(string args)
        {
            WordList loadedList = WordList.LoadList(args);

            string[] languages = new string[loadedList.Languages.Length];

            for (int i = 0; i < languages.Length; i++)
            {
                languages[i] = loadedList.Languages[i];
            }

            return(languages);
        }
Пример #2
0
 public static void Lists()
 {
     if (Directory.GetFiles(WordList.LocalApplicationDirectory).Length != 0)
     {
         Console.WriteLine("Available lists:");
         foreach (string list in WordList.GetLists())
         {
             Console.WriteLine(list);
         }
     }
     else
     {
         Console.WriteLine("Could not find any lists.");
     }
 }
Пример #3
0
        public static void Add(string[] args)
        {
            if (args.Length > 1)
            {
                if (File.Exists($"{WordList.LocalApplicationDirectory}{args[1]}.dat"))
                {
                    WordList loadedList = WordList.LoadList(args[1]);

                    string[] wordInput = new string[loadedList.Languages.Length];

                    do
                    {
                        if (!wordInput.Contains(null))
                        {
                            loadedList.Add(wordInput);

                            loadedList.Save();
                        }

                        Console.WriteLine("Enter translations for the new word:");

                        for (int i = 0; i < wordInput.Length; i++)
                        {
                            Console.Write($"Enter {loadedList.Languages[i]} translation: ");
                            wordInput[i] = Console.ReadLine();

                            if (wordInput[i] == "")
                            {
                                break;
                            }
                        }
                    } while (!wordInput.Contains(""));

                    loadedList.Save();
                }
                else
                {
                    Console.WriteLine("Could not find list.");
                }
            }
            else
            {
                Console.WriteLine("No list name was entered.");
            }
        }
Пример #4
0
        public static void Count(string[] args)
        {
            if (args.Length > 1)
            {
                if (File.Exists($"{WordList.LocalApplicationDirectory}{args[1]}.dat"))
                {
                    WordList loadedList = WordList.LoadList(args[1]);

                    Console.WriteLine($"There are {loadedList.Count()} words in {args[1]}.");
                }
                else
                {
                    Console.WriteLine("Could not find list.");
                }
            }
            else
            {
                Console.WriteLine("Enter a list name.");
            }
        }
Пример #5
0
        public static WordList LoadList(string name)
        {
            if (File.Exists($"{LocalApplicationDirectory}{name}.dat"))
            {
                string[] linesOfText = File.ReadAllLines($"{LocalApplicationDirectory}{name}.dat");

                string[] languages = linesOfText[0].TrimEnd(';').Split(';');

                WordList bufferWordList = new WordList(name, languages);

                for (int i = 1; i < linesOfText.Length; i++)
                {
                    string[] wordSplits = linesOfText[i].TrimEnd(';').Split(';');

                    bufferWordList.words.Add(new Word(wordSplits));
                }

                return(bufferWordList);
            }
            else
            {
                throw new IOException("File not found.");
            }
        }
Пример #6
0
        public static void Remove(string[] args)
        {
            if (args.Length > 3)
            {
                if (File.Exists($"{WordList.LocalApplicationDirectory}{args[1]}.dat"))
                {
                    WordList loadedList = WordList.LoadList(args[1]);

                    string[] words = new string[args.Length - 3];

                    for (int i = 0; i < words.Length; i++)
                    {
                        words[i] = args[i + 3];
                    }

                    for (int index = 0; index < loadedList.Languages.Length; index++)
                    {
                        if (loadedList.Languages[index] == args[2])
                        {
                            foreach (string word in words)
                            {
                                if (loadedList.Remove(index, word))
                                {
                                    Console.WriteLine($"Removed {word} and it's translations.");
                                }
                                else
                                {
                                    Console.WriteLine("Could not find word.");

                                    return;
                                }
                            }

                            loadedList.Save();

                            return;
                        }
                    }

                    Console.WriteLine($"Can not find language in file.");
                }
                else
                {
                    Console.WriteLine("Could not find file.");
                }
            }
            else
            {
                if (args.Length == 1)
                {
                    Console.WriteLine("Please provide list name, language and word.");
                    return;
                }
                else if (args.Length == 2)
                {
                    Console.WriteLine("Please provide language and word.");
                    return;
                }
                else
                {
                    Console.WriteLine("Please provide word.");
                }
            }
        }
Пример #7
0
        public static void Remove(string name, Word wordToRemove)
        {
            WordList loadedList = WordList.LoadList(name);

            loadedList.Remove(0, wordToRemove.Translations[0]);
        }
Пример #8
0
 public static string[] Lists()
 {
     return(WordList.GetLists());
 }
Пример #9
0
        public static int Count(string args)
        {
            WordList loadedList = WordList.LoadList(args);

            return(loadedList.Count());
        }