Array

Building a List of Devices to Receive Notifications

Must Read

Admin
Admin
Just post!

Whenever a tenant creates a new survey, the Tailspin Surveys service must send notifications to all the devices that are interested in that survey. The criteria that the service uses to select the devices may change in future versions of the application, so the developers at Tailspin implemented an extensible filtering method to build the list.

The following code example from the Run method in the New SurveyNotificationCommand class retrieves a list of device URIs to which it will send notifications.

The NewSurveyNotificationCommand class implements a command that a Windows Azure worker role executes in response to receiving a message on a Windows Azure queue.

C#
var deviceUris =
from user in this.filteringService.GetUsersForSurvey(survey)
from deviceUri in this.userDeviceStore.GetDevices(user)
select deviceUri;

This code uses the FilteringService class to get a list of users who are interested in the new survey, and then it uses the GetDevices method in the UserDeviceStore class to get a list of device URIs for those users. The application populates the user device store when the mobile client registers for notifications with the MPNS. For more information

The following code example shows how the FilteringService class uses one or more ISurveyFilter instances in the GetUsersFor Survey method to filter the list of users.

C#
private readonly ISurveyFilter[] filters;

public IEnumerable<string> GetUsersForSurvey(Survey survey)
{
return
(from filter in this.filters
from user in filter.GetUsers(survey)
select user).Distinct();
}

The current version of the application uses a single filter class named TenantFilter to retrieve a list of users from the tenant filter store based on the tenant name. The following code example shows part of this TenantFilter class.

C#
public class TenantFilter : ISurveyFilter
{

private readonly ITenantFilterStore tenantFilterStore;

public IEnumerable<string> GetUsers(Survey survey)
{
return this.tenantFilterStore.GetUsers(survey.Tenant);
}
}

 

- Advertisement -

Latest News

Elevate Your Bentley Experience: The Bespoke Elegance of Bentayga EWB by Mulliner

Bentley Motors redefines the essence of bespoke luxury with the introduction of the Bentayga EWB's groundbreaking two-tone customization option—a...
- Advertisement -

More Articles Like This

- Advertisement -