private void JoinSimulation(object sender, RoutedEventArgs e) { Button simJoinBtn = (Button)sender; string simId = "" + simJoinBtn.Content; XMLSimSetupNotification simulation = new XMLSimSetupNotification(); _setupMessages.TryGetValue(simId, out simulation); if(String.Equals(simulation.ManagerId, _simConfig.APP_ID)) { MessageBox.Show("You are already a part of this simulation. Please click the simulation tab to for more info."); return; } if(simulation == null) { MessageBox.Show("An Error has occured...unable to join simulation - reference is null or empty."); return; } logToConsole("====Attempting to Join Sim====="); logToConsole("simulation: " + simulation.ManagerId); logToConsole("simulation: " + simulation.ManagerPort); logToConsole("simulation: " + simulation.ManagerIp); logToConsole("simulation: " + simulation.SimulationName); SimulationManagementHelper _simManager = new SimulationManagementHelper(_simConfig, DATA_SOURCE_STRING); _simManager.joinSimulation(simulation); }
//This SA will act as a Simulation Manager public void CreateSimulation(object sender, RoutedEventArgs e) { String simId = Sim_ID.Text; String simName = Sim_Name.Text; if(simId.Length > SIM_ID_MAX_LENGTH || simId.Length < SIM_ID_MIN_LENGTH){ MessageBox.Show("Simulation ID requires at least 5-36 characters"); return; } if (simName.Length > SIM_NAME_MAX_LENGTH) { MessageBox.Show("Simulation Name must be less than 50 characters"); return; } else if (simName == "") Sim_Name.Text = simName = "Cyber Threat Simulation #" + simId; //start a sim manager _simConfig.APP_ROLE = SimulationRunningConfig.ROLE_MANAGER; _simConfig.SIM_ID = simId; _simConfig.SIM_NAME = simName; if(Sim_Description.Text == "") _simConfig.SIM_DESCRIPTION = "None"; else _simConfig.SIM_DESCRIPTION = Sim_Description.Text; AppRoleTextBox.Text = "ROLE: MANAGER"; //start a new simulation as the simulation manager _simManager = new SimulationManagementHelper(_simConfig, DATA_SOURCE_STRING); _simManager.startBroadcastingSimulation(); //add manager to list //generate this managers sim application config and add to participant list XMLSimApplication saConfig = new XMLSimApplication(); saConfig.ElementId = SimulationManagementHelper.generateElementId(); saConfig.ParticipantId = _simConfig.APP_ID; saConfig.ParticipantIp = _simConfig.LOCAL_IP_ADDRESS; saConfig.ParticipantRole = _simConfig.APP_ROLE; saConfig.SystemProfile = _simConfig._systemProfile; saConfig.loadSimApplicationConfiguration(_simConfig); saConfig.Status = "Listening"; //Note that the NetworkConnectionState is null because the manager will not be communicating with itself //In addition, SA should not communicate with each other unless sending through the UDP network, they only //communicate with the manager at the time of connection setup or rejoin if disconnected. SimulationParticipant manager = new SimulationParticipant(saConfig, new NetworkConnectionState()); _participantList.Add(saConfig.ParticipantId, manager); startSimulationServer(); }