WinRT

Windows 8 represents the most advanced client runtime for Correspondence yet conceived. It takes full advantage of asynchronous processing to give the user a responsive experience.

Add the NuGet package Correspondence.AllInOne to a Windows 8 project. You can start modeling your application in the text file provided, and run the T4 templates to turn it into C# code. Write your view models against that code, and data bind them to the view.

Progressive UI updates

The Windows 8 version of Correspondence takes additional steps to ensure that the UI is responsive when you are data bound to a persisted model. Take this example:

Model.fact

namespace ToDo.Model;

fact Individual {
key:
    string anonymousId;

query:
    Job* jobs {
        Job j : j.assignedTo = this
            where not j.isComplete
    }
}

fact Job {
key:
    unique;
    Individual assignedTo;

mutable:
    string description;

query:
    bool isComplete {
        exists JobComplete c : c.job = this
    }
}

fact JobComplete {
key:
    Job job;
}

MainViewModel.cs

public class MainViewModel
{
    private Community _community;
    private Individual _individual;

    public MainViewModel(Community community, Individual individual)
    {
        _community = community;
        _individual = individual;
    }

    public IEnumerable<JobViewModel> Jobs
    {
        get
        {
            return
                from job in _individual.Jobs
                select new JobViewModel(job);
        }
    }
}

This application defines a list of jobs assigned to the Individual. The view model data binds to this list, so when jobs are added, completed, or modified, the view updates. This happens whether the change originated from this device or one across the Internet.

When the application first starts up, Correspondence will render an empty list of jobs. It won’t make the user wait while it connects to the server. It won’t even pause while loading the data from the disk. It returns immediately so that the UI stays responsive. It will progressively update the UI as time goes on:

  • Render an empty list immediately.
  • When data is loaded from disk, update the UI.
  • As changes come in from the server, write them to disk and update the UI again.

Asynchronous queries

When it comes time for the program to take some action, it needs to know that it is acting upon the full results of the query. But even then, a Windows 8 application should not block. Use the EnsureAsync() method to await the results of the query:

public async Task CompleteAll()
{
    foreach (var job in await _individual.Jobs.EnsureAsync())
        _community.AddFactAsync(new JobComplete(job));
}

And now you can be sure that you are acting upon the full list, and not the empty result set that will progressively be loaded.