Пример #1
0
        /// <summary>
        /// Form Constructor
        /// </summary>
        /// <param name="ProcList">Current Known Processes, Built from parent form data grid</param>
        /// <param name="client">Client for commands to be sent too</param>
        /// <param name="parent">parent form</param>
        public NewProcess(ClientThread client, ServerMain parent, Database db)
        {
            s = parent;
            List<string> ProcList = db.GetProcesses(client.GetCompID());
            ProcList.Sort();
            InitializeComponent();
            this.client = client;
            string clientName = client.GetComputerName().Split('\0')[0];
            lstBoxProcesses.Items.Clear();
            toolLblConnectedClient.Text += clientName;

            foreach(string procname in ProcList)
            {
                lstBoxProcesses.Items.Add(procname + ".exe");
            }
        }
Пример #2
0
        private void AddClientToDatabase(ClientThread client)
        {
            Messaging.SendCommand("return GetProcessDetails();", client.GetClientSocket());
            List<Process> compProc = (List<Process>)Messaging.RecieveProcessDetails(client.GetClientSocket());

            List<string> procnames = new List<string>();

            foreach (Process proc in compProc)
            {
                procnames.Add(proc.GetName());
            }

            procnames = procnames.Distinct().ToList();

            db.AddProcesses(client.GetCompID().Trim(), procnames);

            Messaging.SendCommand("return GetSystemDB()", client.GetClientSocket());
            string[] sysDB = Messaging.RecieveComputerDetails(client.GetClientSocket());

            db.InsertIntoTable("SYSTEMCOMPONENTS", sysDB);

            Messaging.SendCommand("return GetCompDB()", client.GetClientSocket());
            string[] compDB = Messaging.RecieveComputerDetails(client.GetClientSocket());

            db.InsertIntoTable("COMPUTER", compDB);
        }
Пример #3
0
        public void AddClients()
        {
            clients = new List<ClientThread>();
            TcpListener serverSocket = new TcpListener(IPAddress.Any, 8888);
            serverSocket.Start();
            TcpListener heartBeatListener = new TcpListener(IPAddress.Any, 8889);
            heartBeatListener.Start();
            while (true)
            {
                TcpClient tempClientSocket = new TcpClient();
                TcpClient heartBeatSocket = new TcpClient();
                tempClientSocket.ReceiveTimeout = 300;

                //SendMulticast();
                SendBroadcast();

                //Check and see if a computer is trying to connect.
                //If not, then sleep, and resend multicast in a second
                if (serverSocket.Pending())
                {
                    tempClientSocket = serverSocket.AcceptTcpClient();

                    heartBeatSocket = heartBeatListener.AcceptTcpClient();

                    ClientThread c = new ClientThread(tempClientSocket, heartBeatSocket);
                    Thread checkHeartBeat = new Thread(() => CheckHeartBeat(heartBeatSocket,c));
                    checkHeartBeat.Start();
                    string compid = c.GetCompID().Trim();
                    //Is New
                    if (!checkNewClient(c))
                    {

                        this.objectListView1.AddObject(c);
                        try
                        {
                            AddClientToDatabase(c);
                            db.InitialSetUptimes(c.GetCompID(), c.GetUptimeHours());
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    //It is Known Khaleesi
                    //It is known
                    else
                    {
                        changeOfflineclient(compid);

                    Console.WriteLine("Connected to " + c.GetClientIP() + " :: " + c.GetPort());

                        this.objectListView1.AddObject(c);

                        string group = db.GetClientGroup(compid.Trim());

                        foreach (Group g in groups)
                        {
                            if (g.GetID().Trim() == group)
                            {
                                c.SetGroup(g);
                            }
                        }

                        clients.Add(c);
                        SetStartGroups();

                    }

                }
                else
                {
                    Thread.Sleep(1000); //Sleep for a second, before sending the next multicast.
                }
            }
        }