private static void UpdateSimsImage(string[] args) { if (args.Length == 2) { int index; try { index = int.Parse(args[0]); } catch { throw new ArgumentException("The index must be an integer."); } MySimFile.UpdateImage(index, args[1]); } else { throw new ArgumentException("'update-image' command takes 2 arguments."); } }
private static void ReadFromStandardInput(string imageFilepath = null) { while (true) { string command; if (imageFilepath == null) { Console.WriteLine("Type 'add', 'remove', 'reorder', 'update-image', 'show', or 'help'."); command = RemoveMeaninglessSpaces(Console.ReadLine() ?? ""); } else { command = "add"; } switch (command) { case "add": NameEntry: Console.WriteLine("Enter the name of a new Sim."); var newName = Console.ReadLine(); if (newName == null) { goto NameEntry; } GenderEntry: Console.WriteLine("Enter the gender of the Sim. Type 'male' or 'female'."); var gender = Console.ReadLine() ?? ""; try { ParseGender(gender); } catch { goto GenderEntry; } SignEntry: Console.WriteLine("Enter the zodiac sign of the Sim. Type 'aquarius', 'aries', 'cancer', 'capricorn', 'gemini', 'leo', 'libra', 'pisces', 'sagittarius', 'scorpio', 'taurus', or 'virgo'."); var sign = Console.ReadLine() ?? ""; try { ParseZodiacSign(sign); } catch { goto SignEntry; } ImageFileEntry: if (imageFilepath != null) { AddMySim(new string[] { newName, gender, sign, imageFilepath }); Console.WriteLine("The operation was completed successfully."); break; } Console.WriteLine("Enter the path of a image of the Sim."); var filepath = Console.ReadLine() ?? ""; if (filepath == "") { goto ImageFileEntry; } AddMySim(new string[] { newName, gender, sign, filepath }); Console.WriteLine("The operation was completed successfully."); break; case "remove": var defaultColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; var c = ShowMySims(); Console.ForegroundColor = defaultColor; if (c == 0) { return; } Console.WriteLine("--------------------------------------------------"); int i; while (true) { Console.WriteLine("Type the index number of a Sim you want to remove."); var number = Console.ReadLine() ?? ""; if (number != "") { if (int.TryParse(number, out i)) { break; } } } MySimFile.Remove(i); Console.WriteLine("The operation was completed successfully."); break; case "reorder": var count = ShowMySims(true); if (count == 0) { return; } Console.WriteLine("--------------------------------------------------"); int source, destination; SourceEntry: Console.WriteLine("Type the index number of a Sim you want to move."); try { source = int.Parse(Console.ReadLine() ?? ""); } catch { goto SourceEntry; } DestinationEntry: Console.WriteLine("Type a destination index number."); try { destination = int.Parse(Console.ReadLine() ?? ""); } catch { goto DestinationEntry; } MySimFile.Reorder(source, destination); Console.WriteLine("The operation was completed successfully."); break; case "update-image": var co = ShowMySims(false); if (co == 0) { return; } Console.WriteLine("--------------------------------------------------"); int index; IndexEntry: Console.WriteLine("Type the index number of a Sim you want to update its image."); try { index = int.Parse(Console.ReadLine() ?? ""); } catch { goto IndexEntry; } ImageEntry: Console.WriteLine("Enter the path of a new image of the Sim."); var fp = Console.ReadLine() ?? ""; if (fp == "") { goto ImageEntry; } MySimFile.UpdateImage(index, fp); Console.WriteLine("The operation was completed successfully."); break; case "show": ShowMySims(); break; case "help": ShowHelp(); break; default: continue; } break; } }