aboutsummaryrefslogtreecommitdiff
path: root/src/AddressBook/Program.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2008-11-24 16:09:39 +0000
committerJon Skeet <skeet@pobox.com>2008-11-24 16:09:39 +0000
commit3f225111007e39c5d34c76d015c23596bf934658 (patch)
tree79c63014adc56306b46db1956dadd2e382978e87 /src/AddressBook/Program.cs
parent828510cdbda47eff58682fd62c9166c39194810c (diff)
downloadprotobuf-3f225111007e39c5d34c76d015c23596bf934658.tar.gz
protobuf-3f225111007e39c5d34c76d015c23596bf934658.tar.bz2
protobuf-3f225111007e39c5d34c76d015c23596bf934658.zip
Added address book example
Diffstat (limited to 'src/AddressBook/Program.cs')
-rw-r--r--src/AddressBook/Program.cs55
1 files changed, 55 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// 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.
+ /// </summary>
+ 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