public void CheckComputer(ComputerObjects.Computer HorusComputer) { string checkComputerExists = "SELECT TOP 1 * FROM HorusComputer WHERE ComputerName = '" + HorusComputer.HostName + "'"; string inserNewComputer = "INSERT INTO HorusComputer (ComputerName) Values ('" + HorusComputer.HostName + "')"; try { SqlConnection myConnection = new SqlConnection(@"Data Source=" + Properties.Settings.Default.ServerAddress + @"\SQLEXPRESS;Database=" + Properties.Settings.Default.DatabaseName + ";Integrated Security=SSPI"); myConnection.Open(); SqlCommand sq_checkComputerExists = new SqlCommand(checkComputerExists, myConnection); SqlCommand sq_insertNewCompter = new SqlCommand(inserNewComputer, myConnection); SqlDataReader sdr_DataReader = sq_checkComputerExists.ExecuteReader(); List <string> ReturnedComputers = new List <string>(); while (sdr_DataReader.Read()) { ReturnedComputers.Add(sdr_DataReader.GetValue(1).ToString().Trim()); } sdr_DataReader.Close(); if (ReturnedComputers.Contains(HorusComputer.HostName)) { } else { sq_insertNewCompter.ExecuteNonQuery(); } myConnection.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void GetHorusOnlineClients() { UpdateOnlineClientsProgressBar(true); string[] knownClients = AdminClient.GetClients(); try { foreach (string horusClient in knownClients) { new Thread(() => { Thread.CurrentThread.IsBackground = true; try { HorusShared.ComputerObjects.Computer newClient = AdminClient.GetComputer(horusClient); HorusClientsOnline.Add(newClient); } catch (Exception e) { } }).Start(); } } catch (Exception e) { MessageBox.Show(e.Message); } while (HorusClientsOnline.Count < knownClients.Length) { } UpdateOnlineClientsListView(); //Thread.Sleep(20000); }