Exemplo n.º 1
0
        public static void Run([QueueTrigger("logging", Connection = "AzureWebJobsStorage")] string myQueueItem,
                               [CosmosDB(
                                    databaseName: "rbrandssite",
                                    collectionName: "collection1",
                                    ConnectionStringSetting = "CosmosDBConnection")] out ActivityLogItem logItem,
                               ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            logItem = JsonConvert.DeserializeObject <ActivityLogItem>(myQueueItem);
            if (String.IsNullOrEmpty(logItem.Tenant))
            {
                logItem.Tenant = "rbrands";
            }
            // logItem lives 2 days
            logItem.TimeToLive = 172800;
            string logItemSerialized = JsonConvert.SerializeObject(logItem);

            log.LogInformation($"LogToDb: {logItemSerialized}");
        }
Exemplo n.º 2
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
                                        [Queue("logging")] out ActivityLogItem queuedLog,
                                        ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                string requestBody = new StreamReader(req.Body).ReadToEnd();
                queuedLog = JsonConvert.DeserializeObject <ActivityLogItem>(requestBody);
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                queuedLog = null;
                return(new BadRequestObjectResult(ex.Message));
            }

            return((ActionResult) new OkObjectResult("Message queued"));
        }
Exemplo n.º 3
0
        public static void Run([QueueTrigger("sendmail", Connection = "AzureWebJobsStorage")] string myQueueItem,
                               [SendGrid(ApiKey = "SendGridApiKey")] out SendGridMessage message,
                               [Queue("logging")] out ActivityLogItem activityLog,
                               ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            EMail email = JsonConvert.DeserializeObject <EMail>(myQueueItem);

            message = new SendGridMessage();
            message.AddTo(email.Email);
            message.SetFrom(new EmailAddress(email.From, email.FromName));
            message.SetSubject(email.Subject);
            message.AddContent("text/html", email.HtmlText);
            log.LogInformation($"From: {email.From} - To: {email.Email} - Subject: {email.Subject}");
            activityLog            = new ActivityLogItem();
            activityLog.User       = email.From;
            activityLog.Category   = "Info";
            activityLog.ClientInfo = "Functions.rbrandssitetools2.SendMail";
            activityLog.MessageTag = $"SendGrid to {email.Email}";
            activityLog.Message    = email.Subject;
        }