Skip to content

Commit

Permalink
add - brk|doc - Added CalendarValueInfo (vCalendar...
Browse files Browse the repository at this point in the history
...)

---

We've made a breaking change to add CalendarValueInfo in an attempt to add support for string and integer parameters.

---

Type: add
Breaking: True
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 2, 2024
1 parent 2f29101 commit 5b99aa0
Show file tree
Hide file tree
Showing 49 changed files with 596 additions and 385 deletions.
24 changes: 15 additions & 9 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public Parts.Calendar Parse()
bool isWithType = splitArgs.Length > 0;
List<ArgumentInfo> finalArgs = [];

// Extract the group name
string group = prefix.Contains(".") ? prefix.Substring(0, prefix.IndexOf(".")) : "";
prefix = prefix.RemovePrefix($"{group}.");

// Check to see if we have a BEGIN or an END prefix
if (prefix == VcardConstants._beginSpecifier)
{
Expand Down Expand Up @@ -203,10 +207,11 @@ public Parts.Calendar Parse()
continue;

// Set the string for real
var stringValueInfo = new CalendarValueInfo<string>([.. finalArgs], elementTypes, group, valueType, finalValue);
if (subPart is not null)
subPart.SetString(stringType, finalValue);
subPart.SetString(stringType, stringValueInfo);
else
calendar.SetString(stringType, finalValue);
calendar.SetString(stringType, stringValueInfo);
}
break;
case PartType.Integers:
Expand All @@ -220,10 +225,11 @@ public Parts.Calendar Parse()
double finalDouble = double.Parse(finalValue);

// Set the integer for real
var stringValueInfo = new CalendarValueInfo<double>([.. finalArgs], elementTypes, group, valueType, finalDouble);
if (subPart is not null)
subPart.SetInteger(integerType, finalDouble);
subPart.SetInteger(integerType, stringValueInfo);
else
calendar.SetInteger(integerType, finalDouble);
calendar.SetInteger(integerType, stringValueInfo);
}
break;
case PartType.PartsArray:
Expand All @@ -238,7 +244,7 @@ public Parts.Calendar Parse()

// Now, get the part info
finalValue = partsArrayType is CalendarPartsArrayEnum.IanaNames or CalendarPartsArrayEnum.NonstandardNames ? _value : value;
var partInfo = fromString(finalValue, [.. finalArgs], elementTypes, valueType, CalendarVersion);
var partInfo = fromString(finalValue, [.. finalArgs], elementTypes, group, valueType, CalendarVersion);

// Set the array for real
if (subPart is not null)
Expand Down Expand Up @@ -353,7 +359,7 @@ private bool HasComponent<TComponent>(string expectedFieldName, TComponent compo
{
case PartType.Strings:
{
string value = component.GetString((CalendarStringsEnum)enumeration);
string value = component.GetString((CalendarStringsEnum)enumeration)?.Value ?? "";
exists = !string.IsNullOrEmpty(value);
}
break;
Expand All @@ -367,7 +373,7 @@ private bool HasComponent<TComponent>(string expectedFieldName, TComponent compo
break;
case PartType.Integers:
{
double value = component.GetInteger((CalendarIntegersEnum)enumeration);
double value = component.GetInteger((CalendarIntegersEnum)enumeration)?.Value ?? -1;
exists = value != -1;
}
break;
Expand All @@ -385,7 +391,7 @@ private void ValidateAlarm(CalendarAlarm alarmInfo)
string[] expectedAudioAlarmFields = [VCalendarConstants._attachSpecifier];
string[] expectedDisplayAlarmFields = [VCalendarConstants._descriptionSpecifier];
string[] expectedMailAlarmFields = [VCalendarConstants._descriptionSpecifier, VCalendarConstants._summarySpecifier, VCalendarConstants._attendeeSpecifier];
string type = alarmInfo.GetString(CalendarStringsEnum.Action);
string type = alarmInfo.GetString(CalendarStringsEnum.Action)?.Value ?? "";
switch (type)
{
case "AUDIO":
Expand All @@ -403,7 +409,7 @@ private void ValidateAlarm(CalendarAlarm alarmInfo)
}

// Check to see if there is a repeat property
int repeat = (int)alarmInfo.GetInteger(CalendarIntegersEnum.Repeat);
int repeat = (int)(alarmInfo.GetInteger(CalendarIntegersEnum.Repeat)?.Value ?? -1);
string[] expectedRepeatedAlarmFields = [VCalendarConstants._durationSpecifier];
if (repeat >= 1)
{
Expand Down
2 changes: 1 addition & 1 deletion VisualCard.Calendar/Parsers/VCalendarParserTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal static (CalendarPartsArrayEnum, PartCardinality) GetPartsArrayEnumFromT
return (CalendarPartsArrayEnum.IanaNames, PartCardinality.Any);
}

internal static (PartType type, object enumeration, Type? enumType, Func<string, ArgumentInfo[], string[], string, Version, BaseCalendarPartInfo>? fromStringFunc, string defaultType, string defaultValue, string defaultValueType, string[] allowedExtraTypes, string[] allowedValues) GetPartType(string prefix, string objectType, Version calendarVersion)
internal static (PartType type, object enumeration, Type? enumType, Func<string, ArgumentInfo[], string[], string, string, Version, BaseCalendarPartInfo>? fromStringFunc, string defaultType, string defaultValue, string defaultValueType, string[] allowedExtraTypes, string[] allowedValues) GetPartType(string prefix, string objectType, Version calendarVersion)
{
string[] allowedStatuses =
objectType == VCalendarConstants._objectVEventSpecifier && calendarVersion.Major == 2 ? ["TENTATIVE", "CONFIRMED", "CANCELLED"] :
Expand Down
26 changes: 17 additions & 9 deletions VisualCard.Calendar/Parts/BaseCalendarPartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ public abstract class BaseCalendarPartInfo : IEquatable<BaseCalendarPartInfo>
/// <summary>
/// Final arguments
/// </summary>
public virtual ArgumentInfo[]? Arguments { get; internal set; }
public virtual ArgumentInfo[] Arguments { get; internal set; } = [];

/// <summary>
/// Card element type (home, work, ...)
/// </summary>
public virtual string[]? ElementTypes { get; internal set; }
public virtual string[] ElementTypes { get; internal set; } = [];

/// <summary>
/// Value type (usually set by VALUE=)
/// </summary>
public virtual string? ValueType { get; internal set; }
public virtual string ValueType { get; internal set; } = "";

/// <summary>
/// Property group
/// </summary>
public virtual string Group { get; internal set; } = "";

/// <summary>
/// Is this part preferred?
Expand Down Expand Up @@ -95,6 +100,7 @@ public bool Equals(BaseCalendarPartInfo source, BaseCalendarPartInfo target)
source.Arguments.SequenceEqual(target.Arguments) &&
source.ElementTypes.SequenceEqual(target.ElementTypes) &&
source.ValueType == target.ValueType &&
source.Group == target.Group &&
EqualsInternal(source, target)
;
}
Expand All @@ -106,10 +112,11 @@ public override bool Equals(object obj) =>
/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = -452519667;
hashCode = hashCode * -1521134295 + EqualityComparer<ArgumentInfo[]?>.Default.GetHashCode(Arguments);
hashCode = hashCode * -1521134295 + EqualityComparer<string[]?>.Default.GetHashCode(ElementTypes);
hashCode = hashCode * -1521134295 + EqualityComparer<string?>.Default.GetHashCode(ValueType);
int hashCode = -1053170623;
hashCode = hashCode * -1521134295 + EqualityComparer<ArgumentInfo[]>.Default.GetHashCode(Arguments);
hashCode = hashCode * -1521134295 + EqualityComparer<string[]>.Default.GetHashCode(ElementTypes);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ValueType);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Group);
return hashCode;
}

Expand All @@ -124,18 +131,19 @@ public override int GetHashCode()
internal virtual bool EqualsInternal(BaseCalendarPartInfo source, BaseCalendarPartInfo target) =>
true;

internal abstract BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string valueType, Version calendarVersion);
internal abstract BaseCalendarPartInfo FromStringVcalendarInternal(string value, ArgumentInfo[] finalArgs, string[] elementTypes, string group, string valueType, Version calendarVersion);

internal abstract string ToStringVcalendarInternal(Version calendarVersion);

internal BaseCalendarPartInfo()
{ }

internal BaseCalendarPartInfo(ArgumentInfo[] arguments, string[] elementTypes, string valueType)
internal BaseCalendarPartInfo(ArgumentInfo[] arguments, string[] elementTypes, string group, string valueType)
{
Arguments = arguments;
ElementTypes = elementTypes;
ValueType = valueType;
Group = group;
}
}
}
Loading

0 comments on commit 5b99aa0

Please sign in to comment.