Telerik blogs

The Q3 release RadControls will come packed with shiny features and a couple of new controls, but that’s not all! We’ve fiddled with the complex machinery under the hood and made it better too.

Let me introduce you the new and improved provider interface (ABC, actually) for RadScheduler:

public abstract class SchedulerProviderBase : ProviderBase
{
   
public virtual IEnumerable<Appointment> GetAppointments(ISchedulerInfo schedulerInfo) { }
   
public virtual IDictionary<ResourceType, IEnumerable<Resource>> GetResources(ISchedulerInfo schedulerInfo) { }
   
public virtual void Insert(ISchedulerInfo schedulerInfo, Appointment appointmentToInsert) { }
   
public virtual void Update(ISchedulerInfo schedulerInfo, Appointment appointmentToUpdate) { }
   
public virtual void Delete(ISchedulerInfo schedulerInfo, Appointment appointmentToDelete) { }
}

(code abbreviated for clarity)

The key difference between the old and the new version is that you now get a reference to ISchedulerInfo instead of RadScheduler. This allows you to easily send additional information to the provider without resorting to side-channels such as the Session.

We’ve also rolled the old GetResourceTypes and GetResourcesByType methods into a single method for convenience.

Note: All changes are backwards-compatible and any existing implementations of SchedulerProvider will continue to work without modification. For new implementations we recommend overriding the new methods that take ISchedulerInfo.

Let’s see how to take advantage of these improvements in practice:

Sending additional information to the provider (server-side binding)

1. Start by inheriting the default ISchedulerInfo implementation and add your custom properties.

    public class MySchedulerInfo : SchedulerInfo
   
{
       
public string User { get; set; }

       
public MySchedulerInfo(ISchedulerInfo baseInfo, string user)
       
{
           
ViewStart = baseInfo.ViewStart;
           
ViewEnd = baseInfo.ViewEnd;
           
TimeZoneOffset = baseInfo.TimeZoneOffset;
           
MinutesPerRow = baseInfo.MinutesPerRow;
           
EnableDescriptionField = baseInfo.EnableDescriptionField;

           
User = user;
       
}
   
}

Copying the base properties is tedious and we’ll add a copy constructor in place for the official release.

2. Send the customized MySchedulerInfo to RadScheduler in one of the following events:

  • AppointmentsPopulating
  • ResourcesPopulating
  • AppointmentInsert
  • AppointmentUpdate
  • AppointmentDelete

For example:

protected void RadScheduler1_AppointmentsPopulating(object sender, AppointmentsPopulatingEventArgs e)
{
   
e.SchedulerInfo = new MySchedulerInfo(e.SchedulerInfo, User.Identity.Name);
}

3. Cast the schedulerInfo to MySchedulerInfo in the corresponding provider method

public override IEnumerable<Appointment> GetAppointments(ISchedulerInfo schedulerInfo)
{
   
var myInfo = schedulerInfo as MySchedulerInfo;
    
   
// Access myInfo.User
    // ...
}

Sending additional information to the provider (web service binding)

The code is the same as when using server-side binding, but you’re sending the additional information in the client-side events instead:

<script type="text/javascript">
function appointmentsPopulating(sender, eventArgs)
{
   
eventArgs.get_schedulerInfo().User = "UserA";
}
</script>

 

That’s it! Go play with the Q3 Beta today and let us know if you like what you see!


About the Author

Iana Tsolova

is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.

Comments

Comments are disabled in preview mode.