Example #1
0
        public MainWindowViewModel()
        {
            AvailableSimulationTimes = new [] { 1.0, 10, 60, 100, 600 };

            Goods             = new Goods(GoodGenerator.GenerateUniqueGoods(50).Cast <IGood>().ToList());
            CityMap           = new CityMapGenerator().Generate(Goods);
            VehicleModels     = new ObservableCollection <VehicleModel>(new VehicleModelGenerator().GenerateUniqueVehicleModels(20));
            Vehicles          = new ObservableCollection <Vehicle>(new VehicleGenerator().GenerateUniqueVehicles(50, VehicleModels, CityMap.Places.OfType <IWarehouse>().First()));
            SimulationService = new SimulationService(CityMap, VehicleModels, new Optimizer(CityMap));
            var canStartSimulation = SimulationService.WhenAnyValue(x => x.IsRunning)
                                     .ObserveOn(RxApp.MainThreadScheduler)
                                     .Select(x => !x);

            StartSimulationCommand = ReactiveCommand.Create(() =>
            {
                SimulationService.Start();
            }, canStartSimulation);

            var canStopSimulation = SimulationService.WhenAnyValue(x => x.IsRunning);

            StopSimulationCommand = ReactiveCommand.Create(() => SimulationService.Stop(), canStopSimulation);
        }