Work Management service in SharePoint 2013 (9): And on the client side?

I have mentioned already in the previous articles of this series, that the CSOM side have been implemented with almost the same methods as the server side. To finish this blog post with a goodie, I will create a Windows 8 store app, with a Windows Runtime Component which will reference the Work Management APIs (“Microsoft.SharePoint.WorkManagement.Client.dll” from Hive15/ISAPI), and fetch the task data.

You will, of course, need a ClientContext to create UserSettingsManager (instead of SPServiceContext which was used within the server side model).

ClientContext context = new ClientContext("http://server");
//user settings manager
Microsoft.SharePoint.WorkManagement.Client.UserSettingsManager usm = new Microsoft.SharePoint.WorkManagement.Client.UserSettingsManager(context);
//get all locations from usm
Microsoft.SharePoint.WorkManagement.Client.LocationClientCollection locations = usm.GetAllLocations();
context.Load(locations);
//user ordered session manager
Microsoft.SharePoint.WorkManagement.Client.UserOrderedSessionManager osm = new Microsoft.SharePoint.WorkManagement.Client.UserOrderedSessionManager(context);
//location oriented session
Microsoft.SharePoint.WorkManagement.Client.LocationOrientedUserOrderedSession uos = osm.CreateLocationOrientedSession();
//task query
Microsoft.SharePoint.WorkManagement.Client.TaskQuery tq = new Microsoft.SharePoint.WorkManagement.Client.TaskQuery(context);
//read tasks
Microsoft.SharePoint.WorkManagement.Client.LocationGroupClientCollection tcc = uos.ReadTasks(tq);
//batching done, client execute
context.Load(tcc);
context.ExecuteQuery();
//iterate through results
List<Microsoft.SharePoint.WorkManagement.Client.Task> allTasks = tcc.ToList<Microsoft.SharePoint.WorkManagement.Client.Task>();
 
foreach (Microsoft.SharePoint.WorkManagement.Client.Task task in allTasks)
{
//iterate through results, create an IEnumerable that can be bound to the View
}

The task data will be bound to an items page in the C# Windows Store app. This will work with both SharePoint on premise, and with Office 365. The result could look like: