//assuming this SA is a manager it will broadcast the simulation data needed to connect to a simulation
        public void broadCastNewSimulation(object source, ElapsedEventArgs e)
        {
            //build XML sim setup message
            XMLSimSetupNotification setup = new XMLSimSetupNotification();
            setup.SimulationId = _appConfig.SIM_ID;
            setup.SimulationName = _appConfig.SIM_NAME;
            setup.ManagerIp = _appConfig.LOCAL_IP_ADDRESS;
            setup.ManagerPort = SimulationRunningConfig.TCP_SIMULATION_APP_PORT;
            setup.ManagerId = _appConfig.APP_ID;
            setup.Secure = false;
            //setup.Password = "******"
            setup.SimulationDescription = _appConfig.SIM_DESCRIPTION;

            //wrap XML message with DEM header and send out
            MessageWrapper wrap = new MessageWrapper();
            wrap.ApplicationId = _appConfig.APP_ID;
            wrap.ApplicationRole = _appConfig.APP_ROLE;
            wrap.MessageType = MessageBase.MESSAGE_SIM_SETUP;
            wrap.Message = setup;

            //setup.printToConsole();

            NetworkConnection netPipe = new NetworkConnection(_appConfig);
            netPipe.sendUdpBroadcast(wrap.toXmlString(), SimulationRunningConfig.UDP_NETWORK_BROADCAST_ADDRESS, SimulationRunningConfig.UDP_SIMULATION_APP_PORT);
        }
        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);
        }
        private void requestJoinSimulation(XMLSimSetupNotification simulation)
        {
            XMLSimJoinRequest joinRequest = new XMLSimJoinRequest();
            joinRequest.ParticipantId = _appConfig.APP_ID;
            joinRequest.ParticipantIp = _appConfig.LOCAL_IP_ADDRESS;

            //wrap XML message with Communications header and send out
            MessageWrapper wrap = new MessageWrapper();
            wrap.ApplicationId = _appConfig.APP_ID;
            wrap.ApplicationRole = _appConfig.APP_ROLE;
            wrap.MessageType = MessageBase.MESSAGE_JOIN_REQUEST;
            wrap.Message = joinRequest;

            System.Console.WriteLine("Sending: " + wrap.toXmlString());

            NetworkConnection netPipe = new NetworkConnection(_appConfig);
            netPipe.sendTcpDataConnectionRequest(wrap.toXmlString(), simulation.ManagerIp, simulation.ManagerPort);
        }
 public void joinSimulation(XMLSimSetupNotification simulation)
 {
     //start sending out simulation broadcasts on udp
     Task.Factory.StartNew(() => requestJoinSimulation(simulation));
 }