コード例 #1
0
        static void Main(string[] args)
        {
            var helpRequested = false;
            var sendMessage = false;
            var optionSet = new OptionSet
            {
                {"u|user="******"Username to use", user => _username = user},
                {"p|pass="******"Password for Username", pass => _password = pass},
                {"a|account=", "Account Reference to use", reference => _accountReference = reference},
                {
                    "s|send=", "Send a message to the provided number", sendTo =>
                    {
                        sendMessage = true;
                        _sendTo = sendTo;
                    }
                },
                {"b|bodies+", "Retrieve message bodies", v => _getBodies = true},
                {
                    "h|help", "Help about the command line interface", key => { helpRequested = key != null; }
                }
            };

            try
            {
                optionSet.Parse(args);
                if (!helpRequested && (string.IsNullOrEmpty(_username) ||
                                       string.IsNullOrEmpty(_password) ||
                                       string.IsNullOrEmpty(_accountReference)))
                    throw new ApplicationException("Samples require username, password and account reference be given");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                helpRequested = true;
            }

            if (helpRequested)
            {
                ShowUsage(optionSet);
                return;
            }

            EsendexCredentials credentials;
            try
            {
                credentials = new EsendexCredentials(_username, _password);
                var sessionService = new SessionService(credentials);

                credentials.SessionId = sessionService.CreateSession();
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
                return;
            }

            if (sendMessage)
            {
                Console.WriteLine("Send Message Example\r\n");
                SendMessageExample(credentials);
            }

            MessageBodyService messageBodyService = null;
            if (_getBodies)
            {
                messageBodyService = new MessageBodyService(credentials);
            }

            Console.WriteLine();
            Console.WriteLine("Sent Messages Example\r\n");
            GetSentMessagesExample(credentials, messageBodyService);

            Console.WriteLine();
            Console.WriteLine("Inbox Messages Example\r\n");
            GetInboxMessagesExample(credentials, messageBodyService);

            Console.WriteLine();
            Console.WriteLine("Contacts Example\r\n");
            GetContactsExample(credentials);

            Console.WriteLine();
            Console.WriteLine("Press enter to continue ... ");
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Use session authentication
            try
            {
                SessionService sessionService = new SessionService(Credentials);

                Credentials.SessionId = sessionService.CreateSession();
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }

            // TODO: Remove these comments to expose the example functionality.

            // SendMessageExample();

            // GetSentMessagesExample();

            // GetInboxMessagesExample();

            // GetContactsExample();

            Console.ReadLine();
        }