Skip to content

Commit

Permalink
Bug fix: Keeping export from GPU and XML in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
fstueber committed Mar 9, 2021
1 parent 3aefe65 commit 458c8c9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 32 deletions.
63 changes: 36 additions & 27 deletions src/Export/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,20 @@ await ecfTableWriter.WriteHeadersAsync(
{
if (absence.Type == GpuAbsenceType.Room)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.RoomId, absence.GetUntisRoomId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);
if (absence.IsInsideTerm(_untisDocument.GeneralSettings) && absence.GetEcfRoomId(_untisDocument.Rooms) != null)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.RoomId, absence.GetUntisRoomId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);

await ecfTableWriter.WriteAsync();
await ecfTableWriter.WriteAsync();

_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
}
}
}

Expand Down Expand Up @@ -458,17 +461,20 @@ await ecfTableWriter.WriteHeadersAsync(
{
if (absence.Type == GpuAbsenceType.Class)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, absence.GetUntisSchoolClassId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);
if (absence.IsInsideTerm(_untisDocument.GeneralSettings) && absence.GetEcfSchoolClassId(_untisDocument.Classes) != null)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, absence.GetUntisSchoolClassId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);

await ecfTableWriter.WriteAsync();
await ecfTableWriter.WriteAsync();

_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
}
}
}

Expand Down Expand Up @@ -681,17 +687,20 @@ await ecfTableWriter.WriteHeadersAsync(
{
if (absence.Type == GpuAbsenceType.Teacher)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.TeacherId, absence.GetUntisTeacherId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);
if (absence.IsInsideTerm(_untisDocument.GeneralSettings) && absence.GetEcfTeacherId(_untisDocument.Teachers) != null)
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, absence.Id);
ecfTableWriter.TrySetValue(EcfHeaders.TeacherId, absence.GetUntisTeacherId());
ecfTableWriter.TrySetValue(EcfHeaders.StartTimepoint, absence.StartDate);
ecfTableWriter.TrySetValue(EcfHeaders.EndTimepoint, absence.EndDate);
ecfTableWriter.TrySetValue(EcfHeaders.ReasonId, absence.Reason);
ecfTableWriter.TrySetValue(EcfHeaders.Description, absence.Text);

await ecfTableWriter.WriteAsync();
await ecfTableWriter.WriteAsync();

_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
_untisAbsencesCache.Add(absence.Id);
ecfRecordCounter++;
}
}
}

Expand Down
58 changes: 53 additions & 5 deletions src/Extensions/GpuAbsenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#endregion

using Enbrea.Untis.Gpu;
using Enbrea.Untis.Xml;
using System.Collections.Generic;

namespace Ecf.Untis
{
Expand All @@ -28,6 +30,45 @@ namespace Ecf.Untis
/// </summary>
public static class GpuAbsenceExtensions
{
public static string GetEcfRoomId(this GpuAbsence absence, List<UntisRoom> rooms)
{
var room = rooms.Find(x => x.Id == absence.GetUntisRoomId());
if (room != null)
{
return room.Id;
}
else
{
return default;
}
}

public static string GetEcfSchoolClassId(this GpuAbsence absence, List<UntisClass> schoolClasses)
{
var schoolClass = schoolClasses.Find(x => x.Id == absence.GetUntisSchoolClassId());
if (schoolClass != null)
{
return schoolClass.Id;
}
else
{
return default;
}
}

public static string GetEcfTeacherId(this GpuAbsence absence, List<UntisTeacher> teachers)
{
var teacher = teachers.Find(x => x.Id == absence.GetUntisTeacherId());
if (teacher != null)
{
return teacher.Id;
}
else
{
return default;
}
}

public static string GetUntisRoomId(this GpuAbsence absence)
{
if (string.IsNullOrEmpty(absence.ShortName))
Expand All @@ -40,28 +81,35 @@ public static string GetUntisRoomId(this GpuAbsence absence)
}
}

public static string GetUntisTeacherId(this GpuAbsence absence)
public static string GetUntisSchoolClassId(this GpuAbsence absence)
{
if (string.IsNullOrEmpty(absence.ShortName))
{
return null;
}
else
else
{
return "TR_" + absence.ShortName;
return "CL_" + absence.ShortName;
}
}

public static string GetUntisSchoolClassId(this GpuAbsence absence)
public static string GetUntisTeacherId(this GpuAbsence absence)
{
if (string.IsNullOrEmpty(absence.ShortName))
{
return null;
}
else
{
return "CL_" + absence.ShortName;
return "TR_" + absence.ShortName;
}
}

public static bool IsInsideTerm(this GpuAbsence absence, UntisGeneralSettings generalSettings)
{
return
(absence.StartDate >= generalSettings.TermBeginDate && absence.StartDate <= generalSettings.TermEndDate) ||
(absence.EndDate >= generalSettings.TermBeginDate && absence.EndDate <= generalSettings.TermEndDate);
}
}
}

0 comments on commit 458c8c9

Please sign in to comment.