Exemple #1
0
        public ErrorEnums SendMessage(MessageOfRequest message)
        {
            var result = ErrorEnums.No_Errors;

            // Device can send any SMS but cannot send SMS with Id=2 (or Id%3=0)
            if (message.Id == 2)
            {
                result = ErrorEnums.Hardware_Is_Not_Connected;
            }
            if (message.Id % 3 == 0)
            {
                result = ErrorEnums.Sender_Is_Not_Ready;
            }

            return(result);
        }
        public List <MessageOfResponse> SendMessage(MessageOfRequest message)
        {
            var result = new List <MessageOfResponse>();

            var textForSend = message.Text.ToCharArray();
            var iteration   = 0;

            Func <string> getPartOfMessage = () => new String(textForSend.Skip(_maxSymbolsInOneMessage * iteration++).Take(_maxSymbolsInOneMessage).ToArray()).Trim();
            var           messagePart      = getPartOfMessage();

            while (!String.IsNullOrWhiteSpace(messagePart))
            {
                message.Text = messagePart;
                var resultResponse = _device.SendMessage(message);
                MessageOfResponse response;

                if (resultResponse == ErrorEnums.No_Errors)
                {
                    // good result
                    response = new MessageOfResponse()
                    {
                        Id       = message.Id.ToString(),
                        ServerId = Guid.NewGuid().ToString(),
                        Text     = message.Text,
                    };
                }
                else
                {
                    // bad result
                    response = new MessageOfResponse()
                    {
                        Id    = message.Id.ToString(),
                        Error = resultResponse.ToString(),
                    };
                }
                result.Add(response);

                messagePart = getPartOfMessage();
            }

            return(result);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start send some SMS");

            var server = "http://localhost";
            //server = "https://api.sms-center.business-man.space";

            var client = SMSSmartClient.CreateRequestPackage()
                         .UseServer(server)
                         .UsePort(7000)
                         .Login("r00t")
                         .Password("x777ak12")
                         .AddMessage(MessageOfRequest.CreateBuilder()
                                     .Receiver("+1-910-500-41-42")
                                     .Sender("Author 1")
                                     .Text("Hello from author 1")
                                     .Build())
                         .AddMessage(MessageOfRequest.CreateBuilder()
                                     .Receiver("+1-910-600-41-42")
                                     .Sender("Author 2")
                                     .Text("Hello from author 2")
                                     .Build())
                         .AddMessage(MessageOfRequest.CreateBuilder()
                                     .Receiver("+1-910-700-41-42")
                                     .Sender("Author 3")
                                     .Text("Hello from author 3")
                                     .Build())
                         .Build();

            var response = client.SendPackageAsync();

            var printService = new ConsolePrintService();

            printService.SetResponse(response.Result).Print();

            Console.WriteLine("Done. Press any key.");
            Console.ReadKey();
        }
        public ClientBuilder AddMessage(MessageOfRequest message)
        {
            _client.RequestPackage.Messages.Add(message);

            return(this);
        }