Beispiel #1
0
        private static int Main(string[] args)
        {
            if (args.Length > 1)
            {
                Console.Error.WriteLine("Usage: AddressBook [file]");
                Console.Error.WriteLine("If the filename isn't specified, \"addressbook.data\" is used instead.");
                return(1);
            }
            string addressBookFile = args.Length > 0 ? args[0] : "addressbook.data";

            bool stopping = false;

            while (!stopping)
            {
                Console.WriteLine("Options:");
                Console.WriteLine("  L: List contents");
                Console.WriteLine("  A: Add new person");
                Console.WriteLine("  Q: Quit");
                Console.Write("Action? ");
                Console.Out.Flush();
                char choice = Console.ReadKey().KeyChar;
                Console.WriteLine();
                try
                {
                    switch (choice)
                    {
                    case 'A':
                    case 'a':
                        AddPerson.Main(new string[] { addressBookFile });
                        break;

                    case 'L':
                    case 'l':
                        ListPeople.Main(new string[] { addressBookFile });
                        break;

                    case 'Q':
                    case 'q':
                        stopping = true;
                        break;

                    default:
                        Console.WriteLine("Unknown option: {0}", choice);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception executing action: {0}", e);
                }
                Console.WriteLine();
            }
            return(0);
        }
Beispiel #2
0
        private static int Main(string[] args)
        {
            if (args.Length > 3)
            {
                Console.Error.WriteLine("Usage: AddressBookProto [file], AddressBookXml [file] ");
                Console.Error.WriteLine("If the filename are not specified, \"addressbook.bin\" and \"addressbook.xml\" are used instead.");
                return(1);
            }

            string addressBookJson  = args.Length > 2 ? args[2] : "addressbook.json";
            string addressBookXml   = args.Length > 1 ? args[1] : "addressbook.xml";
            string addressBookProto = args.Length > 0 ? args[0] : "addressbook.bin";


            bool stopping = false;

            while (!stopping)
            {
                Console.WriteLine("Options:");
                Console.WriteLine("  L: List contents");
                Console.WriteLine("  A: Add new person");
                Console.WriteLine("  G: Generate multiple persons");
                //Console.WriteLine("  J: Generate Json class");
                Console.WriteLine("  Q: Quit");
                Console.Write("Action? ");
                Console.Out.Flush();
                char choice = Console.ReadKey().KeyChar;
                Console.WriteLine();
                try
                {
                    switch (choice)
                    {
                    case 'A':
                    case 'a':
                        AddPerson.Main(new string[] { addressBookProto, addressBookXml, addressBookJson });
                        break;

                    case 'L':
                    case 'l':
                        ListPeople.Main(new string[] { addressBookProto, addressBookXml, addressBookJson });
                        break;

                    case 'G':
                    case 'g':
                        GeneratePersons.Main(new string[] { addressBookProto, addressBookXml, addressBookJson });
                        break;

                    //case 'J':
                    //case 'j':
                    //  Json.GenerateJsonClass.Main();
                    //  break;
                    case 'Q':
                    case 'q':
                        stopping = true;
                        break;

                    default:
                        Console.WriteLine("Unknown option: {0}", choice);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception executing action: {0}", e);
                }
                Console.WriteLine();
            }
            return(0);
        }