public ConnectionMonitor(RemoteComputer computer) { this.interval = Settings.Default.PingInterval; remoteComputer = computer; InitializeBackgroundWorker(); Start(); }
// 1. Check if it already exists // 2. Add to the GUI table // 3. Add to the GUI tabs // 4. Add to the database and set its ID // 5. Start monitoring the network connection public static void Add(RemoteComputer computer) { if (Master.table.TableContainsHostname(computer.hostname)) { Master.main.ChangeStatusBarText(computer.hostname + " already exists."); return; } Master.table.dataGrid.Items.Add(computer); Master.logManager.Add(computer); if (computersTable.Find(computer.hostname).Rows.Count == 0) { computer.ID = computersTable.Insert( computer.hostname, computer.ipAddressStr, computer.credentials.UserName, computer.credentials.Password); DebugLog.DebugLog.Log("Added new computer (" + computer.ID + ", " + computer.hostname + ", " + computer.ipAddressStr + ") to the database."); } new ConnectionMonitor(computer); Master.main.ChangeStatusBarText(computer.ipAddressStr + " added."); }
public void GetHostEntryAsync(RemoteComputer computer) { if (!bgWorker.IsBusy) { bgWorker.RunWorkerAsync(computer); } }
/// <summary> /// Tests whether the "hostnameOrIp" input is a hostname or IP address and resolves accordingly. /// </summary> /// <returns>Null if the input was invalid.</returns> public RemoteComputer GetValidRemoteComputer(string hostnameOrIp, string username, string password) { if (string.IsNullOrEmpty(username.Trim()) || string.IsNullOrEmpty(password.Trim())) { if (!(hostnameOrIp == "localhost" || hostnameOrIp == "127.0.0.1")) { MessageBox.Show("Username and password are required for remote connections.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } RemoteComputer computer = new RemoteComputer(hostnameOrIp, IPAddress.None, username, password); if (!IsValidIpAddress(hostnameOrIp)) { computer.hostname = hostnameOrIp; } else { computer.ipAddress = IPAddress.Parse(hostnameOrIp); } new NetUtils().GetHostEntryAsync(computer); return(computer); }
public void WriteToComputerTab(RemoteComputer computer, string text, bool printTimestamp = true) { try { tabControl.Dispatcher.Invoke((Action)(() => { TabItem thisTab = GetTabItem(computer); if (thisTab == null) { Add(computer); thisTab = GetTabItem(computer); } tabControl.SelectedItem = thisTab; RichTextBox textBox = ((RichTextBox)(((TabItem)thisTab).Content)); if (textBox != null) { if (printTimestamp) { textBox.AppendText("[" + DateTime.Now + "] " + text + Environment.NewLine); } else { textBox.AppendText(text + Environment.NewLine); } textBox.ScrollToEnd(); } })); } catch (Exception ex) { DebugLog.DebugLog.Log(ex); } }
private TabItem CreateTabItemForComputer(RemoteComputer computer) { return(new TabItem { Header = computer.hostname, Content = CreateTextBox(), ContextMenu = CreateTabItemMenu() }); }
public void Remove(RemoteComputer computer) { try { tabControl.Items.Remove(GetTabItem(computer)); } catch (Exception ex) { DebugLog.DebugLog.Log(ex); } }
/// <summary> /// Add a computer to this testbed. Attach this testbed as an observer of the computer. /// </summary> /// <param name="item"></param> public void Add(RemoteComputer item) { if (!items.Contains(item)) { items.Add(item); item.Attach(this); Notify(); } }
public void InitializeInfo(RemoteComputer comp) { computer = comp; TextBoxHostname.Text = comp.hostname; TextBoxIpAddress.Text = comp.ipAddressStr; TextBoxUsername.Text = comp.credentials.UserName; PasswordBoxPassword.Password = comp.credentials.Password; }
public void Add(RemoteComputer computer) { if (TabControlContains(computer.hostname)) { return; } TabItem newTab = CreateTabItemForComputer(computer); tabControl.Items.Add(newTab); selectedTab = newTab; // Bring the new tab into focus. }
private TabItem GetTabItem(RemoteComputer computer) { foreach (TabItem item in tabControl.Items) { if (item.Header.ToString().Equals(computer.hostname, StringComparison.InvariantCultureIgnoreCase) || item.Header.ToString().Equals(computer.ipAddressStr, StringComparison.InvariantCultureIgnoreCase)) { return(item); } } return(null); }
private void worker_DoWork(object sender, DoWorkEventArgs e) { RemoteComputer computer = (RemoteComputer)e.Argument; if (computer.ipAddress == IPAddress.None) { computer.ipAddress = GetIPv4FromHostname(computer.hostname); } else { computer.hostname = GetHostname(computer.ipAddressStr); } e.Result = computer; }
public static ManagementScope SetUpScope(RemoteComputer computer, string wmiClass = "none") { // Since NMU's hostnames are messed up, I have to use the IP address to access the machine. // This creates an issue with RenameComputer. string serverPath = String.Format(@"\\{0}\root\cimv2", computer.ipAddressStr); if (wmiClass == WmiClass.PowerPlan) // PowerPlan is a special case. { serverPath = String.Format(@"\\{0}\root\cimv2\power", computer.ipAddressStr); } ConnectionOptions connectionOptions; // localhost case if (computer.hostname.Equals("localhost", StringComparison.InvariantCultureIgnoreCase) || computer.ipAddressStr.Equals("127.0.0.1", StringComparison.InvariantCultureIgnoreCase)) { connectionOptions = new ConnectionOptions { EnablePrivileges = true, Impersonation = ImpersonationLevel.Impersonate }; } else { string decryptedPassword = Encryption.Decrypt(computer.credentials.Password); connectionOptions = new ConnectionOptions { EnablePrivileges = true, Authentication = AuthenticationLevel.PacketPrivacy, Impersonation = ImpersonationLevel.Impersonate, Username = computer.credentials.UserName, Password = decryptedPassword }; // computer.Log("Connection created with password '" + decryptedPassword + "'."); } return(new ManagementScope(serverPath, connectionOptions)); }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(TextBoxHostnameIp.Text.Trim())) { return; } string encryptedPassword = Encryption.Encrypt(PasswordBoxPassword.Password); ConnectionInfoChecker checker = new ConnectionInfoChecker(); RemoteComputer computer = checker.GetValidRemoteComputer( TextBoxHostnameIp.Text, TextBoxUsername.Text, encryptedPassword); if (computer != null) { ActiveTestbed.Add(computer); } Close(); }
// 1. Update the GUI table // 2. Update the database public static void Update(RemoteComputer computer) { List <RemoteComputer> items = new List <RemoteComputer>(); foreach (RemoteComputer item in Master.table.dataGrid.Items) { items.Add(item); // Copy so we don't modify the collection } foreach (RemoteComputer item in items) { if (item.hostname == computer.hostname && item.ipAddressStr == computer.ipAddressStr) { Master.table.dataGrid.Items.Remove(item); Master.table.dataGrid.Items.Add(computer); } } computersTable.Update(computer.ID, computer.hostname, computer.ipAddressStr, computer.credentials.UserName, computer.credentials.Password); }
public RunningProcessesQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.Process); }
public LocalTimeQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.LocalTime); }
public EventViewerQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.EventViewer); }
public ProgramsQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.Product); }
public RenameComputerTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.ComputerSystem); }
public ScheduledJobsQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.ScheduledJob); }
public DriveInfoTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.Disk); }
public DriverQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.PnPSignedDriver); }
public NetworkQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.NetworkConfig); }
public ComputerSystemProductQueryTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.ComputerSystemProduct); }
public RemoteTaskManager(RemoteComputer computer) { remoteComputer = computer; }
public BiosVersionTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.BIOS); }
public BatteryInfoTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.Battery); }
public PowerPlanTask(RemoteComputer computer) : base(computer) { SetUpWmiConnection(WmiClass.PowerPlan); }
public void Update(RemoteComputer item) { Notify(); }