Skip to content

Commit

Permalink
fix - Fixed vCalendar components population
Browse files Browse the repository at this point in the history
---

We've fixed population issues for calendar components causing their values to go to the base calendar instead of the named calendar component, causing all calls to value-related functions to return incorrect answers.

---

Type: fix
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 2, 2024
1 parent 0d9b8fb commit 2b306ea
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 98 deletions.
2 changes: 1 addition & 1 deletion VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private bool HasComponent<TComponent>(string expectedFieldName, TComponent compo
{
if (enumType is null)
return false;
var values = component.GetPartsArray(enumType, (CalendarPartsArrayEnum)enumeration);
var values = component.GetPartsArray((CalendarPartsArrayEnum)enumeration);
exists = values.Length > 0;
}
break;
Expand Down
60 changes: 37 additions & 23 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class Calendar : IEquatable<Calendar>
/// Gets a part array from a specified key
/// </summary>
/// <returns>An array of values or an empty part array []</returns>
public TPart[] GetPartsArray<TPart>() where TPart : BaseCalendarPartInfo
public virtual TPart[] GetPartsArray<TPart>() where TPart : BaseCalendarPartInfo
{
// Get the parts enumeration according to the type
var key = VCalendarParserTools.GetPartsArrayEnumFromType(typeof(TPart), CalendarVersion);
Expand All @@ -115,15 +115,15 @@ public TPart[] GetPartsArray<TPart>() where TPart : BaseCalendarPartInfo
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>An array of values or an empty part array []</returns>
public TPart[] GetPartsArray<TPart>(CalendarPartsArrayEnum key) where TPart : BaseCalendarPartInfo =>
public virtual TPart[] GetPartsArray<TPart>(CalendarPartsArrayEnum key) where TPart : BaseCalendarPartInfo =>
GetPartsArray<TPart>(key, version, partsArray);

/// <summary>
/// Gets a part array from a specified key
/// </summary>
/// <param name="partType">Target part type that derives from <see cref="BaseCalendarPartInfo"/></param>
/// <returns>An array of values or an empty part array []</returns>
public BaseCalendarPartInfo[] GetPartsArray(Type partType)
public virtual BaseCalendarPartInfo[] GetPartsArray(Type partType)
{
// Check the base type
if (partType.BaseType != typeof(BaseCalendarPartInfo))
Expand All @@ -142,7 +142,7 @@ public BaseCalendarPartInfo[] GetPartsArray(Type partType)
/// <param name="partType">Target part type that derives from <see cref="BaseCalendarPartInfo"/></param>
/// <param name="key">A key to use</param>
/// <returns>An array of values or an empty part array []</returns>
public BaseCalendarPartInfo[] GetPartsArray(Type partType, CalendarPartsArrayEnum key)
public virtual BaseCalendarPartInfo[] GetPartsArray(Type partType, CalendarPartsArrayEnum key)
{
// Check the base type
if (partType.BaseType != typeof(BaseCalendarPartInfo) && partType != typeof(BaseCalendarPartInfo))
Expand All @@ -151,6 +151,20 @@ public BaseCalendarPartInfo[] GetPartsArray(Type partType, CalendarPartsArrayEnu
return GetPartsArray(partType, key, version, partsArray);
}

/// <summary>
/// Gets a part array from a specified key
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>An array of values or an empty part array []</returns>
public virtual BaseCalendarPartInfo[] GetPartsArray(CalendarPartsArrayEnum key)
{
string prefix = VCalendarParserTools.GetPrefixFromPartsArrayEnum(key);
var (_, _, enumType, _, _, _, _, _, _) = VCalendarParserTools.GetPartType(prefix, "", CalendarVersion);
if (enumType is null)
throw new ArgumentException($"Enumeration type is not found for {key}");
return GetPartsArray(enumType, key, version, partsArray);
}

internal TPart[] GetPartsArray<TPart>(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray)
where TPart : BaseCalendarPartInfo
{
Expand Down Expand Up @@ -210,7 +224,7 @@ internal BaseCalendarPartInfo[] GetPartsArray(Type partType, CalendarPartsArrayE
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>A value or null if any other type either doesn't exist or the type is not supported by the card version</returns>
public CalendarValueInfo<string>[] GetString(CalendarStringsEnum key) =>
public virtual CalendarValueInfo<string>[] GetString(CalendarStringsEnum key) =>
GetString(key, version, strings);

internal CalendarValueInfo<string>[] GetString(CalendarStringsEnum key, Version version, Dictionary<CalendarStringsEnum, List<CalendarValueInfo<string>>> strings)
Expand All @@ -233,7 +247,7 @@ internal CalendarValueInfo<string>[] GetString(CalendarStringsEnum key, Version
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>A value or null if any other type either doesn't exist or the type is not supported by the card version</returns>
public CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key) =>
public virtual CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key) =>
GetInteger(key, version, integers);

internal CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key, Version version, Dictionary<CalendarIntegersEnum, List<CalendarValueInfo<double>>> integers)
Expand All @@ -254,7 +268,7 @@ internal CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key, Versio
/// <summary>
/// Saves this parsed card to the string
/// </summary>
public string SaveToString() =>
public virtual string SaveToString() =>
SaveToString(version, partsArray, strings, integers, VCalendarConstants._objectVCalendarSpecifier);

internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, Dictionary<CalendarStringsEnum, List<CalendarValueInfo<string>>> strings, Dictionary<CalendarIntegersEnum, List<CalendarValueInfo<double>>> integers, string objectType)
Expand Down Expand Up @@ -365,34 +379,34 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
if (objectType == VCalendarConstants._objectVCalendarSpecifier)
{
foreach (var calendarEvent in events)
cardBuilder.Append(calendarEvent.SaveToString(version, calendarEvent.partsArray, calendarEvent.strings, calendarEvent.integers, VCalendarConstants._objectVEventSpecifier));
cardBuilder.Append(calendarEvent.SaveToString());
foreach (var calendarTodo in todos)
cardBuilder.Append(calendarTodo.SaveToString(version, calendarTodo.partsArray, calendarTodo.strings, calendarTodo.integers, VCalendarConstants._objectVTodoSpecifier));
cardBuilder.Append(calendarTodo.SaveToString());
foreach (var calendarJournal in journals)
cardBuilder.Append(calendarJournal.SaveToString(version, calendarJournal.partsArray, calendarJournal.strings, calendarJournal.integers, VCalendarConstants._objectVJournalSpecifier));
cardBuilder.Append(calendarJournal.SaveToString());
foreach (var calendarFreeBusy in freeBusyList)
cardBuilder.Append(calendarFreeBusy.SaveToString(version, calendarFreeBusy.partsArray, calendarFreeBusy.strings, calendarFreeBusy.integers, VCalendarConstants._objectVFreeBusySpecifier));
cardBuilder.Append(calendarFreeBusy.SaveToString());
foreach (var calendarTimeZone in timeZones)
cardBuilder.Append(calendarTimeZone.SaveToString(version, calendarTimeZone.partsArray, calendarTimeZone.strings, calendarTimeZone.integers, VCalendarConstants._objectVTimeZoneSpecifier));
cardBuilder.Append(calendarTimeZone.SaveToString());
foreach (var calendarOther in others)
cardBuilder.Append(calendarOther.SaveToString(version, calendarOther.partsArray, calendarOther.strings, calendarOther.integers, calendarOther.ComponentName));
cardBuilder.Append(calendarOther.SaveToString());
}
else if (objectType == VCalendarConstants._objectVEventSpecifier)
{
foreach (var calendarAlarm in ((CalendarEvent)this).alarms)
cardBuilder.Append(calendarAlarm.SaveToString(version, calendarAlarm.partsArray, calendarAlarm.strings, calendarAlarm.integers, VCalendarConstants._objectVAlarmSpecifier));
cardBuilder.Append(calendarAlarm.SaveToString());
}
else if (objectType == VCalendarConstants._objectVTodoSpecifier)
{
foreach (var calendarAlarm in ((CalendarTodo)this).alarms)
cardBuilder.Append(calendarAlarm.SaveToString(version, calendarAlarm.partsArray, calendarAlarm.strings, calendarAlarm.integers, VCalendarConstants._objectVAlarmSpecifier));
cardBuilder.Append(calendarAlarm.SaveToString());
}
else if (objectType == VCalendarConstants._objectVTimeZoneSpecifier)
{
foreach (var calendarStandard in ((CalendarTimeZone)this).standards)
cardBuilder.Append(calendarStandard.SaveToString(version, calendarStandard.partsArray, calendarStandard.strings, calendarStandard.integers, VCalendarConstants._objectVStandardSpecifier));
cardBuilder.Append(calendarStandard.SaveToString());
foreach (var calendarDaylight in ((CalendarTimeZone)this).daylights)
cardBuilder.Append(calendarDaylight.SaveToString(version, calendarDaylight.partsArray, calendarDaylight.strings, calendarDaylight.integers, VCalendarConstants._objectVDaylightSpecifier));
cardBuilder.Append(calendarDaylight.SaveToString());
}

// End the card and return it
Expand Down Expand Up @@ -479,10 +493,10 @@ public override int GetHashCode()
public static bool operator !=(Calendar a, Calendar b)
=> !a.Equals(b);

internal void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value) =>
internal virtual void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value) =>
AddPartToArray(key, value, version, partsArray, VCalendarConstants._objectVCalendarSpecifier);

internal void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value, Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, string objectType)
internal virtual void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value, Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, string objectType)
{
if (value is null)
return;
Expand All @@ -509,10 +523,10 @@ internal void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo va
}
}

internal void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value) =>
internal virtual void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value) =>
AddString(key, value, strings);

internal void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value, Dictionary<CalendarStringsEnum, List<CalendarValueInfo<string>>> strings)
internal virtual void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value, Dictionary<CalendarStringsEnum, List<CalendarValueInfo<string>>> strings)
{
if (value is null || string.IsNullOrEmpty(value.Value))
return;
Expand All @@ -524,10 +538,10 @@ internal void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value
strings[key].Add(value);
}

internal void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value) =>
internal virtual void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value) =>
AddInteger(key, value, integers);

internal void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value, Dictionary<CalendarIntegersEnum, List<CalendarValueInfo<double>>> integers)
internal virtual void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value, Dictionary<CalendarIntegersEnum, List<CalendarValueInfo<double>>> integers)
{
if (value is null || value.Value == -1)
return;
Expand Down
30 changes: 22 additions & 8 deletions VisualCard.Calendar/Parts/CalendarAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CalendarAlarm : Calendar, IEquatable<CalendarAlarm>
/// Gets a part array from a specified key
/// </summary>
/// <returns>An array of values or an empty part array []</returns>
public new TPart[] GetPartsArray<TPart>() where TPart : BaseCalendarPartInfo
public override TPart[] GetPartsArray<TPart>()
{
// Get the parts enumeration according to the type
var key = VCalendarParserTools.GetPartsArrayEnumFromType(typeof(TPart), CalendarVersion);
Expand All @@ -54,29 +54,43 @@ public class CalendarAlarm : Calendar, IEquatable<CalendarAlarm>
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>An array of values or an empty part array []</returns>
public new TPart[] GetPartsArray<TPart>(CalendarPartsArrayEnum key) where TPart : BaseCalendarPartInfo =>
public override TPart[] GetPartsArray<TPart>(CalendarPartsArrayEnum key) =>
GetPartsArray<TPart>(key, CalendarVersion, partsArray);

/// <summary>
/// Gets a part array from a specified key
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>An array of values or an empty part array []</returns>
public override BaseCalendarPartInfo[] GetPartsArray(CalendarPartsArrayEnum key)
{
string prefix = VCalendarParserTools.GetPrefixFromPartsArrayEnum(key);
var (_, _, enumType, _, _, _, _, _, _) = VCalendarParserTools.GetPartType(prefix, "", CalendarVersion);
if (enumType is null)
throw new ArgumentException($"Enumeration type is not found for {key}");
return GetPartsArray(enumType, key, CalendarVersion, partsArray);
}

/// <summary>
/// Gets a string from a specified key
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>A value or null if any other type either doesn't exist or the type is not supported by the card version</returns>
public new CalendarValueInfo<string>[] GetString(CalendarStringsEnum key) =>
public override CalendarValueInfo<string>[] GetString(CalendarStringsEnum key) =>
GetString(key, CalendarVersion, strings);

/// <summary>
/// Gets a integer from a specified key
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>A value or null if any other type either doesn't exist or the type is not supported by the card version</returns>
public new CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key) =>
public override CalendarValueInfo<double>[] GetInteger(CalendarIntegersEnum key) =>
GetInteger(key, CalendarVersion, integers);

/// <summary>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
public override string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVAlarmSpecifier);

/// <summary>
Expand Down Expand Up @@ -136,13 +150,13 @@ public override int GetHashCode()
public static bool operator !=(CalendarAlarm a, CalendarAlarm b)
=> !a.Equals(b);

internal new void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value) =>
internal override void AddPartToArray(CalendarPartsArrayEnum key, BaseCalendarPartInfo value) =>
AddPartToArray(key, value, CalendarVersion, partsArray, VCalendarConstants._objectVAlarmSpecifier);

internal new void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value) =>
internal override void AddString(CalendarStringsEnum key, CalendarValueInfo<string> value) =>
AddString(key, value, strings);

internal new void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value) =>
internal override void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value) =>
AddInteger(key, value, integers);

internal CalendarAlarm(Version version) :
Expand Down
Loading

0 comments on commit 2b306ea

Please sign in to comment.