Esempio n. 1
0
        private void OnClientConnectedEvent(object sender, ClientConnectEventArgs e)
        {
            Console.WriteLine("Client connected.");
            // Triggers when a new client connects to the server
            int    type       = e.Type;
            string macAddress = e.MACAddress;
            string ipAddress  = e.IPAddress;

            Console.WriteLine("Mac: " + macAddress);
            if (type == 1)
            {
                // New Connection
                if (sims.ContainsKey(macAddress))
                {
                    // Sim is cached within the database
                    // Update cachec information as needed and trigger sim as "online"
                    if (ipAddress != sims[macAddress].IpAddress)
                    {
                        sims[macAddress].IpAddress = ipAddress;
                        //db.UpdateExistingSim("", ipAddress, macAddress, "");
                        db.UpdateExistingSim(sims[macAddress]);
                    }
                    sims[macAddress].Online = true;
                    // Update panel to show as online
                    simWinMain.UpdateOnlineStatus(true, macAddress);
                    SendUpdatedSimInfo(sims[macAddress]);
                }
                else
                {
                    // New sim connecting to system for first time
                    Simulator s = new Simulator(0, macAddress, ipAddress, macAddress, true, "");
                    db.NewSimConnection(s);
                    sims.Add(macAddress, s);
                    //simWinMain.AddNewSim(sims, macAddress);
                    //simulatorsMenuBTN_Click(null, null);
                }
                SendNextBookingInfo(macAddress, true);
            }
            else if (type == 2)
            {
                // Client disconnecting
                if (sims.ContainsKey(macAddress))
                {
                    sims[macAddress].Online = false;
                    simWinMain.UpdateOnlineStatus(false, macAddress);
                }
            }
        }