public static async Task RunAsync([TimerTrigger("0 0 */6 * * *")] TimerInfo myTimer, ILogger log)

        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            UtilsQuerys uq   = new UtilsQuerys();
            int         vent = uq.getVentilators();

            //Missing get ventilators here
            if (vent <= 5)
            {
                UserAdmin user = uq.getUserAdmin();

                var adminEmail = user.email;
                var adminName  = user.fullName;

                string sendgridApi = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
                string fromEmail   = Environment.GetEnvironmentVariable("FROMEMAIL");
                string fromUser    = Environment.GetEnvironmentVariable("FROMUSER");

                var           client  = new SendGridClient(sendgridApi);
                var           from    = new EmailAddress(fromEmail, fromUser);
                var           subject = "Ventilators are running out!";
                var           to      = new EmailAddress(adminEmail, adminName);
                StringBuilder strHtml = uq.getTemplateEmail("low_ventilators");
                //var plainTextContent = "";
                var htmlContent = strHtml.ToString(); //MISSING TEMPLATE
                var msg         = MailHelper.CreateSingleEmail(from, to, subject, "", htmlContent);
                var response    = await client.SendEmailAsync(msg);
            }
            else
            {
                log.LogInformation($"there are enough ventilator");
            }
        }
Esempio n. 2
0
        public static void Run([TimerTrigger("0 0 0 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            List <InventoryAvaible> lowInventor = ReadLowInventoryDB();

            if (lowInventor.Count > 0)
            {
                // send Email
                string json_lowInventor = JsonConvert.SerializeObject(lowInventor);

                UtilsQuerys uq   = new UtilsQuerys();
                UserAdmin   user = uq.getUserAdmin();

                string sendgridApi = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
                string fromEmail   = Environment.GetEnvironmentVariable("FROMEMAIL");
                string fromUser    = Environment.GetEnvironmentVariable("FROMUSER");

                var adminEmail = user.email;
                var adminName  = user.fullName;

                var client  = new SendGridClient(sendgridApi);
                var from    = new EmailAddress(fromEmail, fromUser);
                var subject = "Alarm we need more supplies";
                var to      = new EmailAddress(adminEmail, adminName);
                //var plainTextContent = json_lowInventor;
                StringBuilder   strHtml     = uq.getTemplateEmail("low_supplies", json_lowInventor);
                string          htmlContent = strHtml.ToString();
                var             msg         = MailHelper.CreateSingleEmail(from, to, subject, " ", htmlContent);
                Task <Response> response    = client.SendEmailAsync(msg);
                response.Wait();
                var rep = response.Result;
            }
            else
            {
                log.LogInformation($"We have enough supplies!! ");
            }
        }