Examples

The Multinotes solution contains examples for each of the supported Microsoft client frameworks.

  • Windows Store
  • Windows Phone
  • WPF
  • ASP.NET
  • Silverlight

Fork the repository, pull the code, and build the solution. Join a message board from any two clients, and they will collaborate with one another.

Each of the clients defines its own SynchronizationService. It initializes a Community with storage and communication strategies, and registers the model.

public void Initialize()
{
    var storage = new FileStreamStorageStrategy();
    var http = new HTTPConfigurationProvider();
    var communication = new BinaryHTTPAsynchronousCommunicationStrategy(http);

    _community = new Community(storage);
    _community.AddAsynchronousCommunicationStrategy(communication);
    _community.Register<CorrespondenceModel>();
}

Then it subscribes to the parts of the model that the user is interested in.

_community.Subscribe(() => Individual);
_community.Subscribe(() => Individual.MessageBoards);

The ViewModelLocator calls the initializer, and then creates each of the view models that the views data bind to.

public class ViewModelLocator : ViewModelLocatorBase
{
    private readonly SynchronizationService _synchronizationService;

    public ViewModelLocator()
    {
        _synchronizationService = new SynchronizationService();
        if (!DesignMode)
            _synchronizationService.Initialize();
        else
            _synchronizationService.InitializeDesignMode();
    }

    public object Main
    {
        get
        {
            return ViewModel(() => new MainViewModel(
                _synchronizationService.Individual));
        }
    }
}

The view model projects the model so that it could be data bound.

public class MainViewModel
{
    private readonly Individual _individual;

    public MainViewModel(
        Individual individual)
    {
        _individual = individual;
    }

    public IEnumerable<MessageBoardViewModel> MessageBoards
    {
        get
        {
            return
                from share in _individual.Shares
                orderby share.MessageBoard.Topic
                select new MessageBoardViewModel(share);
        }
    }
}

Child view models continue the projection.

public class MessageBoardViewModel
{
    private readonly Share _share;
        
    public MessageBoardViewModel(Share share)
    {
        _share = share;
    }

    public string Topic
    {
        get { return _share.MessageBoard.Topic; }
    }

    public IEnumerable<messageviewmodel> Messages
    {
        get
        {
            return
                from message in _share.MessageBoard.Messages
                select new MessageViewModel(message);
        }
    }
}

Each of these examples is based on a shared model, so that they can collaborate with one another. They register the model with a Community, define a ViewModelLocator to construct the top-level view models, and then define bindable properties for use in the views.