Structure
Last updated
Last updated
The application is organized around a straightforward Model View Controller structure.
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:
Entry[] GetStockSymbols()
Quote[] GetQuotes()
Each method blocks the thread to simulate a long running operation and randomly throws an exception.
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:
BindingList<Stock> GetWatchableStocks()
bool UpdateQuote(Stock stock)
And two static events:
Update
Error
The Stock class is a bindable model class (implements INotifyPropertyChanged) containing all the information used by the view (StockPanel) to render the UI.
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.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.