コード例 #1
0
        public static void Run(
            [QueueTrigger("comment-queue", Connection = "AzureWebJobsStorage")] CommentQueueModel myQueueItem,
            [Table(tableName: "comments")] CloudTable cloudTable,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed");
            var comment = new CommentTableModel(myQueueItem.PostId, Guid.NewGuid())
            {
                Author  = myQueueItem.UserName,
                Comment = myQueueItem.Message,
                Status  = false
            };

            cloudTable.CreateIfNotExists();
            TableOperation operation = TableOperation.Insert(comment);
            TableResult    result    = cloudTable.Execute(operation);

            log.LogInformation("Comment added to table");
        }
コード例 #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "comment")] HttpRequest req,
            [Queue("comment-queue"), StorageAccount("AzureWebJobsStorage")] ICollector <string> commentQueue,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string            requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            CommentQueueModel comment     = JsonConvert.DeserializeObject <CommentQueueModel>(requestBody);

            if (comment != null)
            {
                commentQueue.Add(JsonConvert.SerializeObject(comment));
                log.LogInformation("Comment saved successfully.");
            }

            //json dosyasında özel bir parametreye erişim
            //var aa = Environment.GetEnvironmentVariable("myKey");

            string responseMessage = "This HTTP triggered function executed successfully.";

            return(new OkObjectResult(responseMessage));
        }