public void AddOrUpdateComputer(ClientConnection connection) { var onlineComputer = ComputerList.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.MACAddress) && x.MACAddress == connection.MACAddress); if (onlineComputer != null) { onlineComputer.IsOnline = true; } else { onlineComputer = new HubComputer() { IsOnline = true }; MainWindow.Current.Dispatcher.Invoke(() => { ComputerList.Add(onlineComputer); }); } onlineComputer.ID = connection.ID; onlineComputer.SessionID = connection.SessionID; onlineComputer.ConnectionType = connection.ConnectionType; onlineComputer.IsOnline = true; onlineComputer.CurrentUser = connection.CurrentUser; onlineComputer.ComputerName = connection.ComputerName; onlineComputer.LastOnline = DateTime.Now; onlineComputer.LastReboot = connection.LastReboot; onlineComputer.MACAddress = connection.MACAddress; }
private void btnMakeComputer_Click(object sender, EventArgs e) { try { lblStatus.Text = string.Empty; lblStatus.ForeColor = Color.Blue; //Create a new Computer Computer computer = new Computer(); //Set the properties from the screen computer.Description = txtDescription.Text; computer.EquipmentType = EquipmentType.Types.Desktop; computer.HardDriveSize = Convert.ToInt32(txtHardDriveSize.Text); computer.Manufacturer = txtManufacturer.Text; computer.SerialNo = txtSerialNo.Text; computer.RAM = Convert.ToInt32(txtRAM.Text); computer.Price = Convert.ToDouble(txtPrice.Text); computer.Model = txtModel.Text; if (computerList == null) { //Instantiate new computer list if not created already computerList = new ComputerList(); } computerList.Add(computer); Rebind(); } catch (BadHardDriveException ex) { lblStatus.Text = ex.Message; lblStatus.ForeColor = Color.Red; txtHardDriveSize.Focus(); txtHardDriveSize.SelectAll(); txtHardDriveSize.BackColor = Color.LightYellow; } catch (Exception ex) { lblStatus.Text = ex.Message; lblStatus.ForeColor = Color.Red; } }
public void Load() { var fi = new FileInfo(Path.Combine(Utilities.DataFolder, "Hub.json")); if (fi.Exists) { var savedList = Utilities.JSON.Deserialize <List <HubComputer> >(File.ReadAllText(fi.FullName)).Where(x => !string.IsNullOrWhiteSpace(x.MACAddress)); foreach (var computer in savedList) { if (!ComputerList.Any(x => x.MACAddress == computer.MACAddress)) { ComputerList.Add(computer); } } } MergeAditServerClientList(); }