This is a migrated thread and some comments may be shown as answers.

Expanding recurrence in C# instead of using SQL UDF.

7 Answers 508 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
GrZeCh
Top achievements
Rank 2
GrZeCh asked on 08 Dec 2008, 11:34 AM
Hello!

Is there possibility to expand RecurrenceRule in C# instead of using SQL UDF (provided here: http://www.telerik.com/community/forums/aspnet-ajax/scheduler/sql-reporting-display-all-recurring-appointments.aspx)?

For example I have List of type Appointment and I want to expand Recurrences in elements which have RecurrencyRule != null so the result will be List of upcoming events ordered by Start attribute.

Is this possible?

Thanks in advance

EDIT:

I've opened ExpandRecurrence_UDF zip file from post about SQL UDF and I've found function which returns occurences for RecurrenceRule string but when I try to parse my RecurrenceRules which are being parsed by SQL UDF function I can't get this make to work under C#.

Function:

        public static IEnumerable ExpandRecurrence(string recurrenceRule, DateTime rangeStart, DateTime rangeEnd) 
        { 
            List<OccurrenceInfo> occurrences = new List<OccurrenceInfo>(); 
            RecurrenceRule rrule; 
            if (RecurrenceRule.TryParse(recurrenceRule, out rrule)) 
            { 
                rrule.SetEffectiveRange(rangeStart, rangeEnd); 
                foreach (DateTime occStart in rrule.Occurrences) 
                { 
                    OccurrenceInfo info = new OccurrenceInfo(occStart, occStart.Add(rrule.Range.EventDuration)); 
                    occurrences.Add(info); 
                } 
            } 
 
            return occurrences; 
        } 

Occurences class:

public class OccurrenceInfo 
    private DateTime start; 
    private DateTime end; 
 
    public OccurrenceInfo(DateTime start, DateTime end) 
    { 
        this.start = start; 
        this.end = end; 
    } 
 
    public DateTime Start 
    { 
        get { return start; } 
        set { start = value; } 
    } 
 
    public DateTime End 
    { 
        get { return end; } 
        set { end = value; } 
    } 

Sample RecurrenceRule string which I'm tryign to parse:

RecurrenceRule.TryParse("DTSTART:2008422T000000Z\nDTEND:2008423T000000Z\nRRULE:FREQ=YEARLY;INTERVAL=1;BYMONTHDAY=22;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=04\n"out rrule) 

I've tryed to use Replace function to convert \n to Environment.NewLine but it was returning false too.

EDIT2: I've found bug in my RecurrencyRule string. Month in DTSTART and DTEND was in X format (for months 1-9) instead of XX

7 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 09 Dec 2008, 12:33 PM
Hi,

You are right, the date format is definitely a problem. Everything seems to work fine if we fix it.

As for the initial question, you can evaluate the recurrence rules by referencing either Telerik.Web.UI.dll or the Telerik.Web.UI.RecurrenceEngine.dll. In a normal application we recommend to use the first. The latter contains only the RecurrenceRule class and its dependancies and was created specifically for use in SQL Server.

Sincerely yours,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
GrZeCh
Top achievements
Rank 2
answered on 09 Dec 2008, 08:08 PM
I think I'm having small issue with RecurrenceRule.TryParse. Details:

RecurrenceRule rrule; 

rrule Range:

EventDuration: {1.00:00:00} 
MaxOccurences: 2147483647 
MaxOccurrences: 2147483647 
RecursUntil: {31/12/9999 23:59:59} 
Start: {22/04/1904 00:00:00} 

DB RecurrencyRule content:

DTSTART:19040422T000000Z 
DTEND:19040423T000000Z 
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTHDAY=22;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=4 

When I run rrule in Immediate Window in VisualStudio I see MaximumCandidates set to 3000 and in rrule Range there is MaxOccurrences: 2147483647

but when I run:

rrule.Occurrences.Count() 

it shows 100. Occurences starts in 1904 and ends in 2003 and I want for example set SetEffectiveRange to whole 2008 year and it should return one occurence but since there is only 100 of them it will be not enough to reach 2008 year. How can I extend Occurences number?


0
Accepted
T. Tsonev
Telerik team
answered on 10 Dec 2008, 03:34 PM
Hi GrZeCh,

Thank you for the detailed description. It seems that you have hit one of the internal limits of the RecurrenceRule class. It gives up generating occurrences for appointments that start about 100 years in the past. We took care of this issue and the fix will be available in the next service pack release (scheduled for early January).

A temporary fix until then is to include this code before accessing the Occurrences property:

rrule.MaximumCandidates = 5000;

Your Telerik points have been updated for your involvement.

Greetings,
Tsvetomir Tsonev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
rjb227s
Top achievements
Rank 1
answered on 22 Jul 2009, 05:43 AM
Hello,

In this post, as well as several others, I am seeing members and methods of the Recurrence object that I do not seem to have access to in my code.   ex) Occurrences.Count(), Occurrences.Last() ... etc.  These would be extremely valuable to me in what I'm working on.

//sample code:
MessageDAO daoMsg = new MessageDAO();
MessageDTO dtoMsg = new MessageDTO();
string strRule;
RecurrenceRule objRule;

//Get message from database
dtoMsg = daoMsg.GetById(864);
strRule = dtoMsg.RecurrenceRule;
RecurrenceRule.TryParse(strRule, out objRule);
//objRule.Occurrences. ---> here I have limited functionality as Occurrences  (GetEnumerator, GetType, ToString)...thats it.
//I"m able to loop through the collection, but can't tell the count.

I am running Rad Ajax tools Q1 2009.  What am I doing wrong to not have access to these properties and methods?

Thanks in advance,

Ryan
0
Atanas Korchev
Telerik team
answered on 22 Jul 2009, 07:16 AM
Hello rjb227s,

Count() and Last() are extension methods available for all IEnumerable<T> objects. This is a feature of .NET 3.5 however - this means you cannot use it in .NET 2.0 projects.

Regards,
Albert
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
Sarah
Top achievements
Rank 1
answered on 04 Jan 2021, 06:48 PM
Does Anyone Have An updated UDF for expanding recurrences for Blazor's Scheduler?
0
Marin Bratanov
Telerik team
answered on 05 Jan 2021, 03:59 PM

Hello Sarah,

The Telerik.Recurrence package that comes with UI for Blazor has some helper methos that you could try if using the ones from the UI for ASP.NET AJAX suite or other application code does not suffice for your needs.

I am pasting a small example below, yet I must note that this package is at the 0.1.0 version at the moment, which is before an "official" 1.0.0 version so there may be issues, scenarios that are not covered yet, or API changes in the future - this package is not public API yet.

 

var expandOptions = new Telerik.Recurrence.RecurrenceOptions
{
    RangeStart = DateTime.Now,
    RangeEnd = DateTime.Now.AddMonths(1)
};
var rule = Telerik.Recurrence.RecurrenceRule.Parse("FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR");
var expandedRecurrences = rule.ExpandRecurrence(expandOptions);

foreach (Telerik.Recurrence.Occurrence item in expandedRecurrences)
{
    Console.WriteLine(item.Start);
}

As for any integration of this with SQL - we do not have such plans. The UI for Blazor package is data source agnostic and must not be tied to a specific infrastructure, database or data source. It targets .NET and C# and works with data collections in that context. You could wrap it in your own project similar to the one in this blog post, though, to use directly with an SQL UDF.

 

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Scheduler
Asked by
GrZeCh
Top achievements
Rank 2
Answers by
T. Tsonev
Telerik team
GrZeCh
Top achievements
Rank 2
rjb227s
Top achievements
Rank 1
Atanas Korchev
Telerik team
Sarah
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or