コード例 #1
0
 public ConnectionMonitor(RemoteComputer computer)
 {
     this.interval  = Settings.Default.PingInterval;
     remoteComputer = computer;
     InitializeBackgroundWorker();
     Start();
 }
コード例 #2
0
        // 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.");
        }
コード例 #3
0
 public void GetHostEntryAsync(RemoteComputer computer)
 {
     if (!bgWorker.IsBusy)
     {
         bgWorker.RunWorkerAsync(computer);
     }
 }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 private TabItem CreateTabItemForComputer(RemoteComputer computer)
 {
     return(new TabItem {
         Header = computer.hostname,
         Content = CreateTextBox(),
         ContextMenu = CreateTabItemMenu()
     });
 }
コード例 #7
0
 public void Remove(RemoteComputer computer)
 {
     try {
         tabControl.Items.Remove(GetTabItem(computer));
     } catch (Exception ex) {
         DebugLog.DebugLog.Log(ex);
     }
 }
コード例 #8
0
 /// <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();
     }
 }
コード例 #9
0
        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;
        }
コード例 #10
0
        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.
        }
コード例 #11
0
 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);
 }
コード例 #12
0
        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;
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        // 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);
        }
コード例 #16
0
 public RunningProcessesQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.Process);
 }
コード例 #17
0
 public LocalTimeQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.LocalTime);
 }
コード例 #18
0
 public EventViewerQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.EventViewer);
 }
コード例 #19
0
 public ProgramsQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.Product);
 }
コード例 #20
0
 public RenameComputerTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.ComputerSystem);
 }
コード例 #21
0
 public ScheduledJobsQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.ScheduledJob);
 }
コード例 #22
0
 public DriveInfoTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.Disk);
 }
コード例 #23
0
 public DriverQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.PnPSignedDriver);
 }
コード例 #24
0
 public NetworkQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.NetworkConfig);
 }
コード例 #25
0
 public ComputerSystemProductQueryTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.ComputerSystemProduct);
 }
コード例 #26
0
 public RemoteTaskManager(RemoteComputer computer)
 {
     remoteComputer = computer;
 }
コード例 #27
0
 public BiosVersionTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.BIOS);
 }
コード例 #28
0
 public BatteryInfoTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.Battery);
 }
コード例 #29
0
 public PowerPlanTask(RemoteComputer computer)
     : base(computer)
 {
     SetUpWmiConnection(WmiClass.PowerPlan);
 }
コード例 #30
0
 public void Update(RemoteComputer item)
 {
     Notify();
 }