public async void SendAsync <T>(Func <string, T> options) where T : class
        {
            try
            {
                if (options == null)
                {
                    throw new ArgumentException(nameof(options));
                }
                TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken);
                var code  = _verificationCode.Generate(out var result);
                var param = options.Invoke(code);
                if (!(param is CreateMessageOptions))
                {
                    return;
                }
                var msgOption = param as CreateMessageOptions;
                var message   = await MessageResource.CreateAsync(msgOption);

                MessageSentHandler?.Invoke(result, message);
            }
            catch (Exception ex)
            {
                VerificationCodoeExceptionHandler?.Invoke(ex);
            }
        }
 public void Send(string to)
 {
     try
     {
         if (string.IsNullOrEmpty(From))
         {
             throw new Exception("'From' cannot be empty");
         }
         if (string.IsNullOrEmpty(to))
         {
             throw new ArgumentException(nameof(to));
         }
         var code = _verificationCode.Generate(out var result);
         var text = _parser.Parse(code);
         TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken);
         var message = MessageResource.Create(
             from: new PhoneNumber(From),
             to: new PhoneNumber(to),
             body: text
             );
         MessageSentHandler?.Invoke(result, message);
     }
     catch (Exception ex)
     {
         VerificationCodoeExceptionHandler?.Invoke(ex);
     }
 }
Beispiel #3
0
        public static event MessageSentHandler OnMessageSent;         // Called when a message is sent
        #endregion

        public Client(string IP)
        {
            this.IP = IP;                                                  // Set the IP

            OnMessageReceived += new MessageReceivedHandler(MessageParse); // Add the received event
            OnMessageSent     += new MessageSentHandler(MessageSent);      // Add the sent event

            TClient      = new TcpClient();                                // Create a new TCP client
            PacketThread = new Thread(new ThreadStart(PacketUpdate));      // Create a new thread for packet updates
        }
Beispiel #4
0
        private void SubscribeToEvents()
        {
            // Creating and registering the MessageSentHandler
            var messageSentHandler = new MessageSentHandler(Messages);
            Events.RegisterHandler(messageSentHandler);

            // Creating and registering the UserKickedHandler
            var userKickedHandler = new UserKickedHandler(currentUser);
            Events.RegisterHandler(userKickedHandler);

            // Filtering for handlers are added in nvents 0.7
            // Events.RegisterHandler(userKickedHandler, e => e.UserId == currentUser.Id);
        }
Beispiel #5
0
        public async void SendAsync(string to)
        {
            try
            {
                if (string.IsNullOrEmpty(From))
                {
                    throw new Exception("'From' cannot be empty");
                }
                if (string.IsNullOrEmpty(to))
                {
                    throw new ArgumentException(nameof(to));
                }
                var code    = _verificationCode.Generate(out var result);
                var text    = _parser.Parse(code);
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress(From));
                message.To.Add(new MailboxAddress(to));
                message.Body = new TextPart {
                    Text = text
                };
                using (var emailClient = new SmtpClient())
                {
                    await emailClient.ConnectAsync(_configuration.SmtpServer, _configuration.SmtpPort, _configuration.UseSsl);

                    if (AuthenticateHandlerDelegate != null)
                    {
                        AuthenticateHandlerDelegate.Invoke(emailClient);
                    }
                    else
                    {
                        if (_configuration.RemoveXOauth2)
                        {
                            emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                        }
                        emailClient.Authenticate(_configuration.SmtpUsername, _configuration.SmtpPassword);
                    }

                    await emailClient.SendAsync(message);

                    MessageSentHandler?.Invoke(result, message);
                    emailClient.Disconnect(true);
                }
            }
            catch (Exception ex)
            {
                VerificationCodoeExceptionHandler?.Invoke(ex);
            }
        }
Beispiel #6
0
        public async void SendAsync <T>(Func <string, T> options) where T : class
        {
            try
            {
                if (options == null)
                {
                    throw new ArgumentException(nameof(options));
                }
                var code  = _verificationCode.Generate(out var result);
                var param = options.Invoke(code);
                if (!(param is MimeMessage))
                {
                    return;
                }
                var message = param as MimeMessage;
                using (var emailClient = new SmtpClient())
                {
                    await emailClient.ConnectAsync(_configuration.SmtpServer, _configuration.SmtpPort,
                                                   _configuration.UseSsl);

                    if (AuthenticateHandlerDelegate != null)
                    {
                        AuthenticateHandlerDelegate.Invoke(emailClient);
                    }
                    else
                    {
                        if (_configuration.RemoveXOauth2)
                        {
                            emailClient.AuthenticationMechanisms.Remove("XOAUTH2");
                        }
                        emailClient.Authenticate(_configuration.SmtpUsername, _configuration.SmtpPassword);
                    }

                    await emailClient.SendAsync(message);

                    MessageSentHandler?.Invoke(result, message);
                    emailClient.Disconnect(true);
                }
            }
            catch (Exception ex)
            {
                VerificationCodoeExceptionHandler?.Invoke(ex);
            }
        }
Beispiel #7
0
        public async void SendAsync(string to)
        {
            if (string.IsNullOrEmpty(From))
            {
                throw new Exception("'From' cannot be empty");
            }
            if (string.IsNullOrEmpty(to))
            {
                throw new ArgumentException(nameof(to));
            }
            var code = _verificationCode.Generate(out var result);
            var text = _parser.Parse(code);

            TwilioClient.Init(_configuration.AccountSid, _configuration.AuthToken);
            var message = await CallResource.CreateAsync(
                from : new PhoneNumber(From),
                to : new PhoneNumber(to),
                url : new Uri(
                    $"{Url ?? "http://twimlets.com/message?" + WebUtility.UrlEncode("Message[0]=")}{text}"
                    )
                );

            MessageSentHandler?.Invoke(result, message);
        }
Beispiel #8
0
        public static event MessageSentHandler OnMessageSent; // Called when a message is sent
        #endregion

        public Server()
        {
            OnMessageSent += new MessageSentHandler(MessageSent);      // Add the message sent event

            Listener = new TcpListener(IPAddress.Any, Variables.Port); // Create the TCP Listener with the 634 port
        }
 public MessageSentHandlerTests()
 {
     vm = new ShellViewModel(null);
     handler = new MessageSentHandler(vm);
 }