From 3f225111007e39c5d34c76d015c23596bf934658 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 24 Nov 2008 16:09:39 +0000 Subject: Added address book example --- src/AddressBook/Program.cs | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/AddressBook/Program.cs (limited to 'src/AddressBook/Program.cs') diff --git a/src/AddressBook/Program.cs b/src/AddressBook/Program.cs new file mode 100644 index 00000000..b3e10cbb --- /dev/null +++ b/src/AddressBook/Program.cs @@ -0,0 +1,55 @@ +using System; + +namespace Google.ProtocolBuffers.Examples.AddressBook +{ + /// + /// Entry point. Repeatedly prompts user for an action to take, delegating actual behaviour + /// to individual actions. Each action has its own Main method, so that it can be used as an + /// invidual complete program. + /// + class Program { + 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; + } + } +} \ No newline at end of file -- cgit v1.2.3