示例#1
0
        public static void LoadFile(string[] arguments, MainContext context)
        {
            string GetArguments(int index, string ifEmpty = null)
            {
                if (arguments.Length <= index)
                {
                    return(ifEmpty);
                }
                else
                {
                    return(arguments[index]);
                }
            }

            int countBefore = context.WordsBank.Flashcards.Count;

            FlashCardLoader.LoadFlags loadMode = GetArguments(2, "0") switch
            {
                "0" => FlashCardLoader.LoadFlags.Default,
                "1" => FlashCardLoader.LoadFlags.Invert,
                "2" => FlashCardLoader.LoadFlags.Both,
                _ => throw new ArgumentException("Unknown value as the third argument")
            };
            context.WordsBank.Add(FlashCardLoader.LoadFromFile(GetArguments(0), GetArguments(1, "-"), loadMode));
            ConsoleHelper.WriteLine($"Successfully loaded {context.WordsBank.Flashcards.Count - countBefore } flashcards from {arguments[0]}", Styles.Information);
        }
示例#2
0
        public static void ParseRaw(string[] arguments, MainContext context)
        {
            LinkedList <string> list = new LinkedList <string>();

            do
            {
                string line = ConsoleHelper.ReadLine(Styles.Symbols, false);
                if (!line.Equals(string.Empty))
                {
                    list.AddLast(line);
                }
                else
                {
                    break;
                }
            } while(true);
            var parsed = FlashCardLoader.Parse(list, "-", FlashCardLoader.LoadFlags.Default);
            int lenBef = context.WordsBank.Flashcards.Count;

            context.WordsBank.Add(parsed);
            ConsoleHelper.WriteLine($"Added {context.WordsBank.Flashcards.Count - lenBef} words");
        }