Exemple #1
0
        /*
         * The ViewModel constructor includes
         *
         * -the initialization of the properties and variables
         * -the registration of the messages sent by the model
         * -the call for the startUp method on the model
         * */
        public SimulationViewModel()
        {
            //Current time starts from 0
            _viewModelCurrentTime = 0;

            //Server is not available until the model starts up
            _serverIsAvailable = false;

            //Server is not playing upon the start of the program
            _serverIsPlaying = false;

            //Client current time is in sync with the server time at the start of the program
            _syncTimeWithServer = true;

            //newly created track flag
            newTrackCreated = false;

            //Track list is initialized
            _tracks = new BindingList <ViewModelTrack>();

            //Initialize the model
            model = new SimulationModel();

            //Register the possible incoming message from the model
            Messenger.Default.Register <int>(this, "serverTime", handleServerTimeUpdate);
            Messenger.Default.Register <bool>(this, "serverAvailability", checkIfServerIsAvailable);
            Messenger.Default.Register <bool>(this, "serverIsPlaying", checkIfServerIsPlaying);
            Messenger.Default.Register <Scenario>(this, "newScenario", handleNewScenario);
            Messenger.Default.Register <Track>(this, "createTrack", handleCreateTrack);
            Messenger.Default.Register <Track>(this, "removeTrack", handleRemoveTrack);
            Messenger.Default.Register <Track>(this, "editTrack", handleEditTrack);
            Messenger.Default.Register <Plot>(this, "createPlot", handleCreatePlot);
            Messenger.Default.Register <Plot>(this, "removePlot", handleRemovePlot);
            Messenger.Default.Register <Plot>(this, "editPlot", handleEditPlot);

            //Start up the model
            model.startUp();
        }