示例#1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ExecutionContext context,
            ILogger log)
        {
            try
            {
                string year  = req.Query["year"];
                string month = req.Query["month"];
                string day   = req.Query["day"];
                bool.TryParse(req.Query["onlyWarnings"], out bool onlyWarnings);

                string tableContent = await ReportProcessor.GetHtmlReport(year, month, day, onlyWarnings);

                string content = File.ReadAllText($"{context.FunctionAppDirectory}\\template.html");
                content = content.Replace("[replace]", tableContent);

                return(new ContentResult()
                {
                    Content = content,
                    ContentType = "text/html",
                });
            }
            catch (Exception ex)
            {
                return(new ContentResult()
                {
                    Content = ex.ToString(),
                    ContentType = "text/html",
                });
            }
        }
 public static async Task<string> GetLastDaysHtmlReport(int days, bool onlyWarnings)
 {
     string tableContent = string.Empty;
     for (int i = 0; i < days; i++)
     {
         DateTime startDate = DateTime.UtcNow.AddDays(-i);
         tableContent += await ReportProcessor.GetHtmlReport(startDate.Year.ToString("d2"), startDate.Month.ToString("d2"), startDate.Day.ToString("d2"), onlyWarnings);
     }
     return tableContent;
 }