//
        // Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue
        //
        static int Main(string[] args) {
            Options options = new Options(args);

            Connection connection = null;
            try
            {
                connection = new Connection(options.Url, options.ConnectionOptions);
                connection.Open();
                Session session = connection.CreateSession();
                Receiver receiver = session.CreateReceiver(options.Address);
                Duration timeout = options.Forever ? 
                                   DurationConstants.FORVER : 
                                   DurationConstants.SECOND * options.Timeout;
                Message message = new Message();

                while (receiver.Fetch(ref message, timeout))
                {
                    Dictionary<string, object> properties = new Dictionary<string, object>();
                    properties = message.Properties;
                    Console.Write("Message(properties={0}, content='", 
                                  message.MapAsString(properties));

                    if ("amqp/map" == message.ContentType)
                    {
                        Dictionary<string, object> content = new Dictionary<string, object>();
                        message.GetContent(content);
                        Console.Write(message.MapAsString(content));
                    }
                    else if ("amqp/list" == message.ContentType)
                    {
                        Collection<object> content = new Collection<object>();
                        message.GetContent(content);
                        Console.Write(message.ListAsString(content));
                    }
                    else
                    {
                        Console.Write(message.GetContent());
                    }
                    Console.WriteLine("')");
                    session.Acknowledge();
                }
                receiver.Close();
                session.Close();
                connection.Close();
                return 0;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }
        static int Main(string[] args) {
            Options options = new Options(args);

            Connection connection = null;
            try
            {
                connection = new Connection(options.Url, options.ConnectionOptions);
                connection.Open();
                Session session = connection.CreateSession();
                Sender sender = session.CreateSender(options.Address);
                Message message;
                if (options.Entries.Count > 0)
                {
                    Dictionary<string, object> content = new Dictionary<string, object>();
                    SetEntries(options.Entries, content);
                    message = new Message(content);
                }
                else
                {
                    message = new Message(options.Content);
                    message.ContentType = "text/plain";
                }
                Address replyToAddr = new Address(options.ReplyTo);

                Stopwatch stopwatch = new Stopwatch();
                TimeSpan timespan = new TimeSpan(0,0,options.Timeout);
                stopwatch.Start();
                for (int count = 0;
                    (0 == options.Count || count < options.Count) &&
                    (0 == options.Timeout || stopwatch.Elapsed <= timespan);
                    count++) 
                {
                    if ("" != options.ReplyTo) message.ReplyTo = replyToAddr;
                    string id = options.Id ;
                    if ("" == id) {
                        Guid g = Guid.NewGuid();
                        id = g.ToString();
                    }
                    string spoutid = id + ":" + count;
                    message.SetProperty("spout-id", spoutid);
                    sender.Send(message);
                }
                session.Sync();
                connection.Close();
                return 0;
            } catch (Exception e) {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
            }
            return 1;
        }