3 CalendarReader Suggestions

Hello,
Minor and handy features to request:

1 CalendarReader.GetTotalItemsCount or CalendarReader.GetTotalEventsCount or CalendarReader.Count
My code:
Public Function GetTotalItemsCount(ByVal InputCalendar As String) As Integer
Dim MyCounter As Integer = 0
Dim MyCalendarReader As CalendarReader = Nothing
Try
MyCalendarReader = New CalendarReader(InputCalendar, ASPLoadSetICS)
If MyCalendarReader IsNot Nothing Then
While MyCalendarReader.NextEvent
MyCounter = MyCounter + 1
End While
End If
Finally
GetTotalItemsCount = MyCounter
End Try
End Function

2 CalendarReader.IsMultiEvents (Boolean)
My achievement:
Public Function IsMultiEvents(ByVal InputCalendar As String) As Boolean
Dim MyCounter As Integer = 0
Dim MyCalendarReader As CalendarReader = Nothing
Try
MyCalendarReader = New CalendarReader(InputCalendar, ASPLoadSetICS)
If MyCalendarReader IsNot Nothing Then
While MyCalendarReader.NextEvent
MyCounter = MyCounter + 1
If MyCounter > 1 Then Return True
End While
End If
Finally
If MyCounter > 1 Then IsMultiEvents = True
End Try

AND LoadOptions:
Public Function ASPLoadSetICS() As AppointmentLoadOptions
On Error Resume Next
ASPLoadSetICS = New AppointmentLoadOptions
ASPLoadSetICS.ApplyLocalTZ = True
ASPLoadSetICS.DetectEncoding = True
ASPLoadSetICS.IgnoreSmtpAddressCheck = True
End Function

3 Finally, CalendarReader.Dispose so we can do Using / End Using - This is important :frowning:

Please let me know how it is?
If you have any suggestions for updating my functions for better/faster/safer achievement, please kindly comment :slight_smile:

@australian.dev.nerds,

I think all of these features would be a useful improvement to the CalendarReader.
Thanks for the suggestions.
Created a ticket for this:

Issue ID(s): EMAILNET-41048
1 Like

Hello,
Thanks, just like VCardContact.LoadAsMultiple which loads into List(Of VCardContact)
Maybe you like the idea of something like:
CalendarReader / Appointment :: LoadAsMultiple / LoadAsMultiEvent

MyICSCollection = New List(Of Appointment)
Dim MyCalendarReader = New CalendarReader(input, ASPLoadSetICS)
While MyCalendarReader.NextEvent()
Dim MyAppointment As Appointment = MyCalendarReader.Current
If MyAppointment IsNot Nothing Then
MyICSCollection.Add(MyAppointment)
MyAppointment = Nothing — No Appointment.Dispose too :frowning:
End If
End While

My code already works, just another suggestion to improve SDK.

@australian.dev.nerds,

Added this request to the ticket.

1 Like

Hi @australian.dev.nerds
All proposed features have been implemented and will be available in the next release. Except for the Dispose method which doesn’t make sense because the original stream is used only in the constructor and is not stored on the continuation of the reader’s life cycle and can be closed immediately after use.

            List<Appointment> appointments = new List<Appointment>();
            CalendarReader reader = new CalendarReader(stream);
            stream.Close();
            while (reader.NextEvent())
            {
                appointments.Add(reader.Current);
            } 

Using a file inside a constructor also looks like this:

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                this.Load(fs, options);
            }