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 ReceiveHubDataRequest(dynamic jsonData) { MainWindow.Current.Dispatcher.Invoke(() => { if (jsonData["Status"] != "ok") { AditHub.Current.Disconnect(); MessageBox.Show(jsonData["Status"], "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { AditHub.Current.ComputerList.Clear(); var computerList = jsonData["ComputerList"] as object[]; foreach (Dictionary <string, object> clientObj in computerList) { var newClient = new HubComputer() { ID = (string)clientObj["ID"], ComputerName = (string)clientObj["ComputerName"], CurrentUser = (string)clientObj["CurrentUser"], MACAddress = (string)clientObj["MACAddress"], ConnectionType = (ConnectionTypes)clientObj["ConnectionType"], LastReboot = (DateTime?)clientObj["LastReboot"], SessionID = (string)clientObj["SessionID"], Alias = (string)clientObj["Alias"], LastOnline = (DateTime?)clientObj["LastOnline"], IsOnline = (bool)clientObj["IsOnline"] }; AditHub.Current.ComputerList.Add(newClient); } Pages.Hub.Current.RefreshUICall(); } }); }