Exemplo n.º 1
0
 private static void AddMySim(string[] args)
 {
     if (args.Length == 4)
     {
         var name       = args[0];
         var gender     = ParseGender(args[1]);
         var zodiacSign = ParseZodiacSign(args[2]);
         var path       = args[3];
         var sim        = new MySim(name, gender, zodiacSign, path);
         MySimFile.Add(sim);
     }
     else
     {
         throw new ArgumentException("'add' command takes 4 arguments.");
     }
 }
Exemplo n.º 2
0
 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.");
     }
 }
Exemplo n.º 3
0
 private static void RemoveMySim(string[] args)
 {
     if (args.Length == 1)
     {
         int i;
         try
         {
             i = int.Parse(args[0]);
         }
         catch
         {
             throw new ArgumentException("'remove' command takes an integer.");
         }
         MySimFile.Remove(i);
     }
     else
     {
         throw new ArgumentException("'remove' command takes 1 argument.");
     }
 }
Exemplo n.º 4
0
 private static void ReorderMySim(string[] args)
 {
     if (args.Length == 2)
     {
         int from, to;
         try
         {
             from = int.Parse(args[0]);
             to   = int.Parse(args[1]);
         }
         catch
         {
             throw new ArgumentException("'reorder' command takes 2 integers.");
         }
         MySimFile.Reorder(from, to);
     }
     else
     {
         throw new ArgumentException("'reorder' command takes 2 arguments.");
     }
 }
Exemplo n.º 5
0
 private static int ShowMySims(bool reorder = false)
 {
     return(MySimFile.Show(reorder));
 }
Exemplo n.º 6
0
        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;
            }
        }