Skip to content

Commit

Permalink
Merge pull request #1156 from bcgov/dev
Browse files Browse the repository at this point in the history
FOIMOD-3469 Dates Conversion issue UTC-PST, Zipper metadata condition removed.
  • Loading branch information
abin-aot authored Sep 19, 2024
2 parents a5ab758 + 4e6d6de commit 83af7ea
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ computingservices/ZippingServices/env/*
openshift/templates/zippingservice/zipper.env
*.locenv

MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDFUnitTests/SourceFiles/result_*.pdf
MCS.FOI.S3FileConversion/MCS.FOI.CalendarToPDFUnitTests/SourceFiles/result_*.pdf
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,20 @@ public CalendarFileProcessor(Stream sourceStream)
//Organizer Name and Email
if (e.Organizer != null)
{
organizer = e.Organizer.CommonName + "(" + e.Organizer.Value.AbsoluteUri + ")";
try
{
organizer = e.Organizer.CommonName + "(" + e.Organizer.Value.AbsoluteUri + ")";
}
catch
{

organizer = @"Unknown Organizer";
}

}
else
{
organizer = @"Unknown Organizer(mailto:unknownorganizer@calendar.google.com)";
organizer = @"Unknown Organizer(mailto:unknownorganizer@calendar.bcgov.ca)";
}
htmlString.Append(@"<tr>
<td><b>From: </b></td>
Expand All @@ -174,7 +182,7 @@ public CalendarFileProcessor(Stream sourceStream)
//Meeting created timestamp
htmlString.Append(@"<tr>
<td><b>Sent: </b></td>
<td>" + e.DtStamp.Date + "</td></tr>");
<td>" + GetPSTTime(e.DtStamp.Date) + "</td></tr>");

//Priority
htmlString.Append(@"<tr>
Expand All @@ -184,12 +192,12 @@ public CalendarFileProcessor(Stream sourceStream)
//Meeting Start Timestamp
htmlString.Append(@"<tr>
<td><b>Start Time: </b></td>
<td>" + e.DtStart.Date + "</td></tr>");
<td>" + GetPSTTime(e.DtStart.Value) + "</td></tr>");

//Meeting End Timestamp
htmlString.Append(@"<tr>
<td><b>End Time: </b></td>
<td>" + e.DtEnd.Date + "</td></tr>");
<td>" + GetPSTTime(e.DtEnd.Value) + "</td></tr>");
//Meeting Message
string message = @"" + e.Description?.Replace("\n", "<br>");
message = message.Replace("&lt;br&gt;", "<br>").Replace("&lt;br/&gt;", "<br/>");
Expand Down Expand Up @@ -243,6 +251,22 @@ public CalendarFileProcessor(Stream sourceStream)

}


private DateTime GetPSTTime(DateTime _timetoconvert)
{
DateTime converteddate = _timetoconvert;
if (TimeZone.CurrentTimeZone.StandardName != "Pacific Standard Time" || _timetoconvert.Kind == DateTimeKind.Utc )
{

converteddate = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(converteddate, "Pacific Standard Time");

}

return converteddate;
}



/// <summary>
/// Converts HTML string to PDF using syncfution library and blink engine
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ public void ProcessSimpleCalendarFilesTest()
Dictionary<MemoryStream, Dictionary<string,string>> attachments = new Dictionary<MemoryStream, Dictionary<string, string>>();
string rootFolder = getSourceFolder();
Stream output = new MemoryStream();
Stream testFile = new FileStream(Path.Combine(getSourceFolder(), "test-cal.ics"), FileMode.Open, FileAccess.Read);
Stream testFile = new FileStream(Path.Combine(getSourceFolder(), "Backlog refinement.ics"), FileMode.Open, FileAccess.Read);

CalendarFileProcessor calendarFileProcessor = new CalendarFileProcessor(testFile);
calendarFileProcessor.WaitTimeinMilliSeconds = 5000;
calendarFileProcessor.FailureAttemptCount = 10;
string outputPath = Path.Combine(getSourceFolder(), "output");
(isProcessed, message, output, attachments) = calendarFileProcessor.ProcessCalendarFiles();
Assert.IsTrue(isProcessed == true, $"Calendar to PDF Conversion failed");

SaveStreamAsFile(getSourceFolder(), output, "result_Backlog refinement.pdf");
}

[TestMethod]
Expand All @@ -60,7 +62,7 @@ public void ProcessCalendarFileWithAttachmentsTest()
Dictionary<MemoryStream, Dictionary<string, string>> attachments = new Dictionary<MemoryStream, Dictionary<string, string>>();
string rootFolder = getSourceFolder();
Stream output = new MemoryStream();
Stream testFile = new FileStream(Path.Combine(getSourceFolder(), "test-with-attachments.ics"), FileMode.Open, FileAccess.Read);
Stream testFile = new FileStream(Path.Combine(getSourceFolder(), "Backlog refinement.ics"), FileMode.Open, FileAccess.Read);

CalendarFileProcessor calendarFileProcessor = new CalendarFileProcessor(testFile);
calendarFileProcessor.WaitTimeinMilliSeconds = 5000;
Expand All @@ -71,6 +73,8 @@ public void ProcessCalendarFileWithAttachmentsTest()

bool isAttachmentsExists = attachments.Count == 2;
Assert.IsTrue(isAttachmentsExists, $"Attachments not found");

SaveStreamAsFile(getSourceFolder(), output, "result_Backlog refinement.pdf");
}

[TestMethod]
Expand All @@ -88,11 +92,27 @@ public void ProcessComplexCalendarFilesTest()
calendarFileProcessor.FailureAttemptCount = 10;
(isProcessed, message, output, attachments) = calendarFileProcessor.ProcessCalendarFiles();
Assert.IsTrue(isProcessed == true, $"Calendar to PDF Conversion failed");

SaveStreamAsFile(getSourceFolder(), output, "result_test-problematic-calendar.pdf");
}

private string getSourceFolder()
{
return "C:\\Projects\\foi-docreviewer\\MCS.FOI.S3FileConversion\\MCS.FOI.CalendarToPDFUnitTests\\SourceFiles";
return "C:\\AOT\\FOI\\Source\\foi-docreviewer\\foi-docreviewer\\MCS.FOI.S3FileConversion\\MCS.FOI.CalendarToPDFUnitTests\\SourceFiles";
}

public static void SaveStreamAsFile(string filePath, Stream stream, string fileName)
{
stream.Position = 0;
var path = Path.Combine(filePath, fileName);
var bytesInStream = new byte[stream.Length];

stream.Read(bytesInStream, 0, (int)bytesInStream.Length);

using (var outputFileStream = new FileStream(path, FileMode.Create))
{
outputFileStream.Write(bytesInStream, 0, bytesInStream.Length);
}
}
}
}
Expand Down
Loading

0 comments on commit 83af7ea

Please sign in to comment.