This is a migrated thread and some comments may be shown as answers.
Occurences Count
5 Answers 33 Views
This is a migrated thread and some comments may be shown as answers.
rjb227s
Top achievements
Rank 1
rjb227s asked on 21 Jul 2009, 06:27 AM
Hello,

I am implementing a solution where I look at the current time and loop through a series of appointments to see if any of the appointments occur during this minute.  My current solution is not working well as it is inefficient and I'm having trouble finding a way to do a more efficient search.

I am currently looping through the Occurrences collection of the recurrence rule for every appointment in my list (can be hundreds or thousands).  The only limiting factor that makes my algorithm slightly efficient is that I end the loop through the occurrences once the current occurrence time is in the future (or past the current minute).

Question:
I'd like to do a binary search through the occurrences collection.  This would require that I know the # of occurrences in the appointment so I can look at the midway point to determine if it is in the future or past.

ex)
intPosition = Floor(Appointment.Occurrences.Count / 2);
if((DateTime)Appointment.Occurrences[intPosition] > dateCurrent) --> Continue with Binary search...

The only issue is that there does not seem to be any information available to me about the Occurrences collection.

Question
Is there any way to do what I mentioned above?  Is there a better way to approach this given my scenario of having  a list of appointments and needing to see if the current time is the time for any of the appointments?

Thanks in advance,

Ryan


5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 22 Jul 2009, 02:30 PM
Hi Ryan,

You can get the  number of occurrences, but yo still have to parse the recurrence rule. For example:
protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)  
    {  
        if (e.Appointment.RecurrenceState == RecurrenceState.Master)  
        {  
            RecurrenceRule rrule;  
            string recurrenceString = e.Appointment.RecurrenceRule;  
            RecurrenceRule.TryParse(recurrenceString, out rrule);             
            Response.Write("Number of occurrences: " + rrule.Occurrences.Count());  
        }  
    } 

Is this what you need?

All the best,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
rjb227s
Top achievements
Rank 1
answered on 22 Jul 2009, 07:03 PM
Peter,

I learned today from another post i made that because the the Occurrences object is a generic IEnumerable<T> object that the count() and last() property is not available in .net 2.0.  This proves to be extremely limiting.  I am not in a position to upgrade and the current Occurences object provides very little functionality to anyone using .NET 2.0. 

Is there anyway that an additional property can be provided to either provide the Occurences count or to provide an Occurrences like object for .NET 2.0 that provides public access to count or indexing

ex) rule.OcurrencesCollection[intIndex] ?

Thanks,

Ryan
0
Peter
Telerik team
answered on 23 Jul 2009, 07:30 AM
Hi Ryan,

I will forward your request to our developers who will be able to look into it next week. Please, excuse us for this limitation of the control.


Greetings,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Accepted
Peter
Telerik team
answered on 27 Jul 2009, 01:19 PM
Hi again Ryan,

Here is a workaround which you can try  for .net 2.0:
 protected void Page_Load(object sender, EventArgs e)  
    {          
        RecurrenceRule rrule;  
        string recurrenceString = "DTSTART:20090727T123000Z\r\nDTEND:20090727T133000Z\r\nRRULE:FREQ=DAILY;COUNT=70;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU";  
        RecurrenceRule.TryParse(recurrenceString, out rrule);  
        List<DateTime> appList = new List<DateTime>(rrule.Occurrences);         
        Response.Write("Number of occurrences: " + appList.Count);         
    } 


Regards,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
rjb227s
Top achievements
Rank 1
answered on 03 Aug 2009, 12:48 AM
Peter,

I wanted to thank you for your prompt response.  This is exactly what I needed.

Thank You,

Ryan

[How to get Recurrence Rule occurrence count in .NET 2.0]
[How to get index of occurrences for Recurrence Rule in .NET 2.0]
Asked by
rjb227s
Top achievements
Rank 1
Answers by
Peter
Telerik team
rjb227s
Top achievements
Rank 1
Share this question
or