Exemplo n.º 1
0
        public override void Execute()
        {
            var sid    = EnvironmentVariableHelper.GetEnvironmentVariable(sidKey);
            var token  = EnvironmentVariableHelper.GetEnvironmentVariable(tokenKey);
            var number = EnvironmentVariableHelper.GetEnvironmentVariable(numberKey);

            var client = new TwilioRestClient(sid, token);

            foreach (var reminder in In.DueReminders)
            {
                var contact = "+" + reminder.Contact;
                var result  = client.SendSmsMessage(number, contact, reminder.Message);
                var error   = result.RestException;
                if (error == null)
                {
                    Out.Sent++;
                }
                else
                {
                    Out.Errors++;
                    Console.WriteLine(
                        "SMS to {0} failed with a status of {1} and reason of {2}.",
                        reminder.Contact,
                        error.Status,
                        error.Code + ": " + error.Message
                        );
                }
            }
        }
Exemplo n.º 2
0
        public static DbConnection Connect()
        {
            // Reference: github.com/gregoryjscott/chic/TaskExtensions
            var providerName     = EnvironmentVariableHelper.GetEnvironmentVariable(providerKey);
            var connectionString = EnvironmentVariableHelper.GetEnvironmentVariable(connectionKey);

            DbProviderFactory factory;

            try{
                factory = DbProviderFactories.GetFactory(providerName);
            }
            catch (Exception) { // TODO: Figure out how to load config for tests (Shim for db tests)
                factory = Npgsql.NpgsqlFactory.Instance;
            }

            if (factory == null)
            {
                throw new Exception("Could not obtain factory for provider \"" + providerName + "\"");
            }

            DbConnection connection = factory.CreateConnection();

            if (connection == null)
            {
                throw new Exception("Could not obtain connection from factory for " + providerName);
            }

            connection.ConnectionString = connectionString;
            connection.Open();

            return(connection);
        }
Exemplo n.º 3
0
        public override void Execute()
        {
            var apiKey    = EnvironmentVariableHelper.GetEnvironmentVariable(mandrillAPIKey);
            var fromEmail = EnvironmentVariableHelper.GetEnvironmentVariable(fromEmailKey);

            var api = new MandrillApi(apiKey);

            Console.WriteLine("Sending {0} emails.", In.DueReminders.Length);
            foreach (var reminder in In.DueReminders)
            {
                var results = api.SendMessage(
                    new EmailMessage {
                    to = new List <EmailAddress> {
                        new EmailAddress {
                            email = reminder.Contact
                        }
                    },
                    from_email = fromEmail,
                    subject    = "Reminder!",
                    text       = reminder.Message
                });

                // This assumes that emails are sent one at time to each address, therefore just look
                // at the first result.
                EmailResult result = results[0];
                if (result.Status == EmailResultStatus.Sent)
                {
                    Out.Sent++;
                }
                else
                {
                    Out.Errors++;
                    Console.WriteLine(
                        "Email {0} failed with a status of {1} and reason of {2}.",
                        result.Email,
                        result.Status,
                        result.RejectReason
                        );
                }
            }
        }