From e84c64e826119f9af1b0c737f3d4f334494eec60 Mon Sep 17 00:00:00 2001 From: erikmtm Date: Thu, 15 Aug 2024 12:12:13 +0200 Subject: [PATCH] Fixed temp storage --- .../NyforvarvslistanFunction.cs | 66 ++++++++++++++----- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/func-nyforvarvslistan/NyforvarvslistanFunction.cs b/func-nyforvarvslistan/NyforvarvslistanFunction.cs index 2fb594f..c8ceae3 100644 --- a/func-nyforvarvslistan/NyforvarvslistanFunction.cs +++ b/func-nyforvarvslistan/NyforvarvslistanFunction.cs @@ -206,31 +206,65 @@ public static void CreateLists(ILogger log) // docxGenerator.GenerateDocx("brailleBook-" + Dates.GetCurrentYear(Dates.StartOfPreviousMonth) + "-" + Dates.GetMonthNameInSwedish(Dates.StartOfPreviousMonth) + ".docx", books); } List generatedFiles = new List(); - - if (talkingBooks.Any()) + if (Environment.GetEnvironmentVariable("WEBSITE_CONTENTSHARE") != null) { - string talkingBooksFile = "nyf-tb-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(talkingBooksFile); + if (talkingBooks.Any()) + { + string tempPath = Path.GetTempPath(); - string talkingBooksNoLinksFile = "nyf-tb-no-links-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(talkingBooksNoLinksFile); + string talkingBooksFile = Path.Combine(tempPath, $"nyf-tb-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(talkingBooksFile); - string talkingBooksSwedishOnlyFile = "nyf-tb-no-links-swedishonly-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(talkingBooksSwedishOnlyFile); - } + string talkingBooksNoLinksFile = Path.Combine(tempPath, $"nyf-tb-no-links-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(talkingBooksNoLinksFile); - if (brailleBooks.Any()) + string talkingBooksSwedishOnlyFile = Path.Combine(tempPath, $"nyf-tb-no-links-swedishonly-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(talkingBooksSwedishOnlyFile); + } + + if (brailleBooks.Any()) + { + string tempPath = Path.GetTempPath(); + + string brailleBooksFile = Path.Combine(tempPath, $"nyf-punkt-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(brailleBooksFile); + + string brailleBooksNoLinksFile = Path.Combine(tempPath, $"nyf-punkt-no-links-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(brailleBooksNoLinksFile); + + string brailleBooksSwedishOnlyFile = Path.Combine(tempPath, $"nyf-punkt-no-links-swedishonly-{DateTime.Now:yyyy-MM}.xml"); + generatedFiles.Add(brailleBooksSwedishOnlyFile); + } + } + else { - string brailleBooksFile = "nyf-punkt-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(brailleBooksFile); + if (talkingBooks.Any()) + { + string talkingBooksFile = "nyf-tb-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(talkingBooksFile); - string brailleBooksNoLinksFile = "nyf-punkt-no-links-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(brailleBooksNoLinksFile); + string talkingBooksNoLinksFile = "nyf-tb-no-links-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(talkingBooksNoLinksFile); - string brailleBooksSwedishOnlyFile = "nyf-punkt-no-links-swedishonly-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; - generatedFiles.Add(brailleBooksSwedishOnlyFile); + string talkingBooksSwedishOnlyFile = "nyf-tb-no-links-swedishonly-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(talkingBooksSwedishOnlyFile); + } + + if (brailleBooks.Any()) + { + string brailleBooksFile = "nyf-punkt-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(brailleBooksFile); + + string brailleBooksNoLinksFile = "nyf-punkt-no-links-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(brailleBooksNoLinksFile); + + string brailleBooksSwedishOnlyFile = "nyf-punkt-no-links-swedishonly-" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + ".xml"; + generatedFiles.Add(brailleBooksSwedishOnlyFile); + } } + + if (generatedFiles.Any()) { SendEmailWithAttachments(generatedFiles.ToArray(), "erik.johansson@mtm.se");