Skip to content

Commit

Permalink
imp - All calendar components support saving
Browse files Browse the repository at this point in the history
---

We've added saving feature to all the calendar components.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 11, 2024
1 parent 4be5c6a commit 58bc6f0
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 29 deletions.
38 changes: 33 additions & 5 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ internal int GetInteger(CalendarIntegersEnum key, Version version, Dictionary<Ca
/// Saves this parsed card to the string
/// </summary>
public string SaveToString() =>
SaveToString(version, partsArray, strings, VCalendarConstants._objectVCalendarSpecifier);
SaveToString(version, partsArray, strings, integers, VCalendarConstants._objectVCalendarSpecifier);

internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, Dictionary<CalendarStringsEnum, string> strings, string objectType)
internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, Dictionary<CalendarStringsEnum, string> strings, Dictionary<CalendarIntegersEnum, int> integers, string objectType)
{
// Initialize the card builder
var cardBuilder = new StringBuilder();
Expand Down Expand Up @@ -323,9 +323,37 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
}
}

// Then, the events
foreach (var calendarEvent in events)
cardBuilder.Append(calendarEvent.SaveToString(version, calendarEvent.partsArray, calendarEvent.strings, VCalendarConstants._objectVEventSpecifier));
// Then, the components
if (objectType == VCalendarConstants._objectVCalendarSpecifier)
{
foreach (var calendarEvent in events)
cardBuilder.Append(calendarEvent.SaveToString(version, calendarEvent.partsArray, calendarEvent.strings, calendarEvent.integers, VCalendarConstants._objectVEventSpecifier));
foreach (var calendarTodo in todos)
cardBuilder.Append(calendarTodo.SaveToString(version, calendarTodo.partsArray, calendarTodo.strings, calendarTodo.integers, VCalendarConstants._objectVTodoSpecifier));
foreach (var calendarJournal in journals)
cardBuilder.Append(calendarJournal.SaveToString(version, calendarJournal.partsArray, calendarJournal.strings, calendarJournal.integers, VCalendarConstants._objectVJournalSpecifier));
foreach (var calendarFreeBusy in freeBusyList)
cardBuilder.Append(calendarFreeBusy.SaveToString(version, calendarFreeBusy.partsArray, calendarFreeBusy.strings, calendarFreeBusy.integers, VCalendarConstants._objectVFreeBusySpecifier));
foreach (var calendarTimeZone in timeZones)
cardBuilder.Append(calendarTimeZone.SaveToString(version, calendarTimeZone.partsArray, calendarTimeZone.strings, calendarTimeZone.integers, VCalendarConstants._objectVTimeZoneSpecifier));
}
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));
}
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));
}
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));
foreach (var calendarDaylight in ((CalendarTimeZone)this).daylights)
cardBuilder.Append(calendarDaylight.SaveToString(version, calendarDaylight.partsArray, calendarDaylight.strings, calendarDaylight.integers, VCalendarConstants._objectVDaylightSpecifier));
}

// End the card and return it
cardBuilder.AppendLine($"{VCalendarConstants._endSpecifier}:{objectType}");
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CalendarAlarm : Calendar, IEquatable<CalendarAlarm>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -68,7 +69,7 @@ public class CalendarAlarm : Calendar, IEquatable<CalendarAlarm>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVAlarmSpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVAlarmSpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -103,16 +104,19 @@ public bool Equals(CalendarAlarm source, CalendarAlarm target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -130,6 +134,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarAlarm(Version version) :
base(version)
{ }
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarDaylight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CalendarDaylight : Calendar, IEquatable<CalendarDaylight>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -68,7 +69,7 @@ public class CalendarDaylight : Calendar, IEquatable<CalendarDaylight>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVDaylightSpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVDaylightSpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -103,16 +104,19 @@ public bool Equals(CalendarDaylight source, CalendarDaylight target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -130,6 +134,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarDaylight(Version version) :
base(version)
{ }
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CalendarEvent : Calendar, IEquatable<CalendarEvent>
internal readonly List<CalendarAlarm> alarms = [];
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Alarm list
Expand Down Expand Up @@ -75,7 +76,7 @@ public class CalendarEvent : Calendar, IEquatable<CalendarEvent>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVEventSpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVEventSpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -110,16 +111,19 @@ public bool Equals(CalendarEvent source, CalendarEvent target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -137,6 +141,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarEvent(Version version) :
base(version)
{ }
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarFreeBusy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CalendarFreeBusy : Calendar, IEquatable<CalendarFreeBusy>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -68,7 +69,7 @@ public class CalendarFreeBusy : Calendar, IEquatable<CalendarFreeBusy>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVFreeBusySpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVFreeBusySpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -103,16 +104,19 @@ public bool Equals(CalendarFreeBusy source, CalendarFreeBusy target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -130,6 +134,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarFreeBusy(Version version) :
base(version)
{ }
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CalendarJournal : Calendar, IEquatable<CalendarJournal>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -68,7 +69,7 @@ public class CalendarJournal : Calendar, IEquatable<CalendarJournal>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVJournalSpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVJournalSpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -103,16 +104,19 @@ public bool Equals(CalendarJournal source, CalendarJournal target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -130,6 +134,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarJournal(Version version) :
base(version)
{ }
Expand Down
13 changes: 10 additions & 3 deletions VisualCard.Calendar/Parts/CalendarStandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CalendarStandard : Calendar, IEquatable<CalendarStandard>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -68,7 +69,7 @@ public class CalendarStandard : Calendar, IEquatable<CalendarStandard>
/// Saves this parsed card to the string
/// </summary>
public new string SaveToString() =>
SaveToString(CalendarVersion, partsArray, strings, VCalendarConstants._objectVStandardSpecifier);
SaveToString(CalendarVersion, partsArray, strings, integers, VCalendarConstants._objectVStandardSpecifier);

/// <summary>
/// Saves the contact to the returned string
Expand Down Expand Up @@ -103,16 +104,19 @@ public bool Equals(CalendarStandard source, CalendarStandard target)
// Check all the properties
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings)
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1047895655;
int hashCode = 1333672311;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -130,6 +134,9 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
SetInteger(key, value, integers);

internal CalendarStandard(Version version) :
base(version)
{ }
Expand Down
Loading

0 comments on commit 58bc6f0

Please sign in to comment.