Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Current »

Connexion includes a framework which lets you easily plug scheduling functionality into your devices. This framework includes a user interface for configuring schedules, as well as server-side functions to determine when your devices should perform specific functionality.

To enable scheduling, your configuration class should implement the IScheduleConfiguration interface. This interface defines a single property:

namespace Connexion.Core
{
  public interface IScheduleConfiguration
  {
    ScheduleConfig ScheduleConfiguration { get; }
  }
}

Implement it as follows in your configuration class:

  public class MyDeviceConfiguration : NotifyBase, IScheduleConfiguration
  {
    private ScheduleConfig m_ScheduleConfiguration;
    [DataMember]
    public ScheduleConfig ScheduleConfiguration
    {
      get
      {
        if (m_ScheduleConfiguration == null)
        {
          m_ScheduleConfiguration = new ScheduleConfig();
          m_ScheduleConfiguration.PropertyChanged += (o, e) => RaisePropertyChanged(e);
        }
        return m_ScheduleConfiguration;
      }
    }

The next step is to add the user interface component(s) and bind to your configuration class ScheduleConfiguration property. The schedule UI component is defined in the Connexion.ScheduleUi assembly (Connexion.ScheduleUi.dll), so you will need to reference this assembly.

In your device.xaml class, add a reference to the scheduling namespace:

<core:UserControlBase x:Class="mydevice.myDeviceUI"
                      xmlns:scheduleUi="clr-namespace:Connexion.ScheduleUi;assembly=Connexion.ScheduleUi"

There are 2 UI components available:

  • An icon adorner which will launch an ‘edit schedule’ popup window - this can be placed next to textboxes and similar controls to indicate additional scheduling functionality.

    <scheduleUi:SchedulerIcon ScheduleConfiguration="{Binding Config.ScheduleConfiguration}"
                              VerticalAlignment="Center" />
  • A schedule UI which can be placed directly onto your device UI - this can be placed on a separate tab or other large area if you only need a single schedule configuration.

    <Border>
       <scheduleUi:ScheduleControl ScheduleConfiguration="{Binding Config.ScheduleConfig}" />
    </Border>

Once the ScheduleConfiguration UI is bound to your configuration class, no further work is required on your device.xaml file.

The next step is to implement your scheduling logic in your device class. There are three important methods

  • StartScheduling(): This method starts the underlying scheduler, and is typically called from your Start() method.

  • StopScheduling(): This method stops the underlying scheduler, and is typically called from your Stop() method.

  • OnScheduleTimeout(OnScheduleTimeoutArgs args): This method is called when the underlying scheduler triggers. Override this method and include any logic to be run when the schedule expires.

public override void Start()
{
  // your start logic
  ...    
  StartScheduling();
}
public override void Stop()
{
  StopScheduling();

  // your stop logic
  ...
}
protected override async Task OnScheduleTimeout(OnScheduleTimeoutArgs args)
{
  // your logic to run when the schedule expires
  // (read from file/database and post on channel, for example)
  
  // or just flip a bit to let your device know it's within a scheduling period
  _IsWithinSchedule = true; // use this to determine if you can process messages or must sleep
}

If your OnScheduleTimeout method is long running, you should call StopScheduling() at the beginning and StartScheduling() in a finally block to ensure you don’t end up with multiple threads within OnScheduleTimeout.

  • No labels