private void SearchComputers(string domainNames) { string query = "WinNT://" + domainNames; DirectoryEntry container = null; using (container = new DirectoryEntry(query)) { DirectoryEntries computers = container.Children; computers.SchemaFilter.Add("Computer"); foreach (DirectoryEntry computer in computers) { try { logger.Debug("Machine found: " + computer.Name); if (MachineFound != null) { string _message = string.Empty; logger.Debug("Raising machine found event"); MachineDetailsArgs objMachineArgs = new MachineDetailsArgs(); objMachineArgs.DomainName = container.Name; objMachineArgs.MachineName = computer.Name; objMachineArgs.IPAddress = GetMachineIPAddress(computer.Name); objMachineArgs.CredentialID = GetAssociatedCredential(computer.Name, ref _message); if ( objMachineArgs.CredentialID == -1) { objMachineArgs.Discovered = false; } else { objMachineArgs.Discovered = true; } objMachineArgs.StatusMessage = _message; MachineFound(this, objMachineArgs); } } catch (Exception) { } } } }
private void AddMachineMyName(object param) { string machineName = (string)param; logger.Debug("Machine found: " + machineName); if (MachineFound != null) { string _message = string.Empty; logger.Debug("Raising machine found event"); MachineDetailsArgs objMachineArgs = new MachineDetailsArgs(); objMachineArgs.DomainName = ""; objMachineArgs.MachineName = machineName; objMachineArgs.IPAddress = GetMachineIPAddress(machineName); objMachineArgs.CredentialID = GetAssociatedCredential(machineName, ref _message); objMachineArgs.StatusMessage = _message; MachineFound(this, objMachineArgs); if (MachineDiscoveryComplete != null) { MachineDiscoveryComplete(this, null); } } }
/// <summary> /// function called when the Machine found event is raised by the nethelper /// </summary> /// <param name="sender">Nethelper object</param> /// <param name="args">MachineDetailsArgs class contains machine details</param> private void netHelper_MachineFound(object sender, MachineDetailsArgs args) { _logger.Info("Found machine "+args.MachineName); EntDiscover objDbMachine = new EntDiscover(); objDbMachine.DomainName = args.DomainName; objDbMachine.MachineName = args.MachineName; objDbMachine.IPAddr = args.IPAddress; objDbMachine.CredentialID = args.CredentialID; objDbMachine.StatusMessage = args.StatusMessage; objDbMachine.Discovered = args.Discovered; FireStatusMessage("Found machine: " + args.MachineName); if (disDB.InsertDiscover(objDbMachine) == DBCode.Ok) { if (MachineFound != null) { MachineFound(this, args); } } objDbMachine = null; }
public void DiscoverMachinesByFileName(string fileName) { if (MachineDiscoveryStart != null) { logger.Info("DiscoveryStart event raised"); MachineDiscoveryStart(this, null); } logger.Info("Starting scanning machines from filename"); if (File.Exists(fileName) == true) { int counter = 0; string machineName; StreamReader file = new StreamReader(fileName); while ((machineName = file.ReadLine()) != null) { logger.Debug("Machine found: " + machineName); if (MachineFound != null) { string _message = string.Empty; logger.Debug("Raising machine found event"); MachineDetailsArgs objMachineArgs = new MachineDetailsArgs(); objMachineArgs.DomainName = ""; objMachineArgs.MachineName = machineName; objMachineArgs.IPAddress = GetMachineIPAddress(machineName); //objMachineArgs.CredentialID = GetAssociatedCredential(machineName, ref _message); objMachineArgs.StatusMessage = _message; if (MachineFound != null) { MachineFound(this, objMachineArgs); } //System.Windows.Forms.Application.DoEvents; System.Windows.Forms.Application.DoEvents(); } counter++; } file.Close(); } if (MachineDiscoveryComplete != null) { MachineDiscoveryComplete(this, null); } logger.Info("Scanning machines from filename complete"); }
void Instance_MachineFound(object sender, MachineDetailsArgs args) { RefreshMachineList(Controller.Instance.UpdateFromDatabase(args.MachineName)); }