public void UpdateSeperationEventStatus() { //Log if conditions for seperation event are no longer met. foreach (var e in CurrentEvents.events) { if (e is SeperationEvent) { string tag0 = e.InvolvedTracks[0].Tag; string tag1 = e.InvolvedTracks[1].Tag; TrackData track0; TrackData track1; //get updated track data try { track0 = CurrentTracks.Find(x => x.Tag == tag0); track1 = CurrentTracks.Find(x => x.Tag == tag1); //if the updated track data no longer matches conditions for SeperationEvent, set the isRaise-attribute to false if (CheckForSeperationEventConditions(track0, track1) == false) { //Mark that seperation event is no longer active - It will now be removed at next "cleanUp" e.isRaised = false; } } catch { //Mark that seperation event is no longer active - It will now be removed at next "cleanUp" e.isRaised = false; } } } }
public void UpdateTrackData(TrackData trackData) { // Update trackdata TrackData trackToEdit = CurrentTracks.Find(x => x.Tag == trackData.Tag); trackToEdit.CurrentHorzVel = CalculateTrackSpeed(trackData, trackToEdit); trackToEdit.CurrentCourse = CalculateTrackCourse(trackData, trackToEdit); trackToEdit.CurrentXcord = trackData.CurrentXcord; trackToEdit.CurrentYcord = trackData.CurrentYcord; trackToEdit.CurrentZcord = trackData.CurrentZcord; trackToEdit.CurrentHorzVel = trackToEdit.CurrentHorzVel; trackToEdit.TimeStamp = trackData.TimeStamp; //Replace old object with new object int index = CurrentTracks.FindIndex(x => x.Tag == trackData.Tag); CurrentTracks.RemoveAt(index); CurrentTracks.Insert(index, trackToEdit); }
public static string moveTrain(string state) { if (state == "MoveTrain") { if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Train"; return(state); } TrainForMove = CurrentTrains.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (TrainForMove == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a train named " + Homepage.namingTextBox.Text.Trim(); return(null); } Homepage.namingTextBox.Text = null; Homepage.ConsoleTextBox.Text = "Alright, we found your Train! It is at station " + TrainForMove.TrainCurrentLocation.Name + " .Go ahead and add any packages or press 'Yes' to continue."; state = "PackageManagement"; foreach (Package i in TrainForMove.TrainCurrentLocation.PackagesWaiting) { Homepage.packageSelectionDropDown.Items.Add(i.PackageType + "-" + i.PackageValue + "," + i.PackageDestinationStation.Name); } return(state); } else if (state == "MoveTrainDestination") { if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text += "Sorry! You have to pick a Station"; return(state); } var selectedStationForMoving = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (selectedStationForMoving == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim(); return(state); } var trackExists = CurrentTracks.Find(i => i.sourceStation == TrainForMove.TrainCurrentLocation && i.destinationStation == selectedStationForMoving); if (trackExists == null) { Homepage.ConsoleTextBox.Text = "Sorry, there is no track there. Transaction cancelled."; Homepage.namingTextBox.Text = null; return(null); } TrainForMove.TrainCurrentLocation = selectedStationForMoving; Homepage.ConsoleTextBox.Text = "You have moved!"; Homepage.namingTextBox.Text = null; Train.updateTrainInfoBox(); Station.updateStationInfoBox(); Homepage.packageSelectionDropDown.Items.Clear(); Homepage.packageSelectionDropDown.SelectedItem = null; foreach (Package i in TrainForMove.Holding) { if (i.PackageDestinationStation == TrainForMove.TrainCurrentLocation) { Bank.CurrentMoney += i.PackageValue; Homepage.ConsoleTextBox.Text = "Awesome! Packages have been successfully delivered!"; } } TrainForMove.Holding.RemoveAll(i => i.PackageDestinationStation == TrainForMove.TrainCurrentLocation); Bank.updateMoneyBox(); Train.updateTrainInfoBox(); Station.updateStationInfoBox(); state = null; } return(state); }