Structure

MVC

The application is organized around a straightforward Model View Controller structure.

MarketService

MarketService.cs is a static class that simulates a service to retrieve a list of stock symbols and to retrieve their latest value. It exposes two static methods:

  1. Entry[] GetStockSymbols()

  2. Quote[] GetQuotes()

Each method blocks the thread to simulate a long running operation and randomly throws an exception.

StockManager

StockManager.cs is the controller. It is also a static class shared by all sessions. It starts a single task when it's loaded and periodically uses MarketService to retrieve stock values. It is also in charge of updating the model when a stock quote changes.

It exposes two static methods:

  1. BindingList<Stock> GetWatchableStocks()

  2. bool UpdateQuote(Stock stock)

And two static events:

  1. Update

  2. Error

Stock

The Stock class is a bindable model class (implements INotifyPropertyChanged) containing all the information used by the view (StockPanel) to render the UI.

StockPanel

StockPanel.cs is the view. An instance of the StockPanel user control is created and anchored inside the MainPage. The code in StockPanel contains a DataRepeater panel template that is bound to the model.

StockPanel subscribes to the Update and Error events broadcasted by the StockManager class and when it receives an Update notification it asks the controller to update the model. Any update to the model is automatically reflected in the UI through the data binding infrastructure.

When the StockPanel detects that a stock value has changed, it fired a StockValueChanged event. The only listener to this event is the MainView.

MainView

MainView.cs is the main page of the application. It contains a header and an instance of the StockPanel anchored to the top and bottom edge. It listens to the StockValueChanged event to play a sound and update the LastUpdate label.

Last updated