public void FullRangeResultCheck() { _results.Clear(); SubnetFinder finder = new SubnetFinder("192.168.21.254-192.168.22.1"); finder.SearchFinished += new EventHandler(SearchFinished); finder.ComputerFound += new EventHandler<FinderEventArgs>(ComputerFound); finder.StartSearch(); if (!synchronization.WaitOne(2000, false)) { finder.StopSearch(); Assert.Fail("Search timeout"); } Assert.AreEqual(new string[] { "192.168.21.254", "192.168.21.255", "192.168.22.0", "192.168.22.1" }, GetNames(_results).ToArray(), "Wrong result for \"192.168.21.254-192.168.22.1\""); }
public void SingleAddressWithMask() { _results.Clear(); SubnetFinder finder = new SubnetFinder("192.168.2.2/32"); finder.SearchFinished += new EventHandler(SearchFinished); finder.ComputerFound += new EventHandler<FinderEventArgs>(ComputerFound); finder.StartSearch(); if (!synchronization.WaitOne(2000, false)) { finder.StopSearch(); Assert.Fail("Search timeout"); } Assert.AreEqual(new string[] { "192.168.2.2" }, GetNames(_results).ToArray(), "Wrong result for \"192.168.2.2/32\""); }
private void StartSearch() { if (_isSearching) return; string text = searchBox.Text; if(text == "") text = "*"; _finders.Clear(); // Разбиваем строку поиска на подстроки. string[] queries = text.Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries ); foreach (string query in queries) { try { SubnetFinder finder = new SubnetFinder(query); _finders.Add(finder); } catch (FormatException) { } catch (ArgumentException) { } try { WorkgroupFinder finder = new WorkgroupFinder(query); _finders.Add(finder); } catch (FormatException) { } catch (ArgumentException) { } try { DomainFinder finder = new DomainFinder(query); _finders.Add(finder); } catch (FormatException) { } catch (ArgumentException) { } } if (_finders.Count == 0) { searchBox.BackColor = Color.FromKnownColor(KnownColor.Pink); return; } if ((searchBox.Items.Count == 0) || (searchBox.Items[searchBox.Items.Count - 1] as string != searchBox.Text)) { searchBox.Items.Add(searchBox.Text); } tableModel.Rows.Clear(); searchBox.Enabled = false; findButton.Text = Properties.Resources.findButtonStopText; foreach (IFinder finder in _finders) { finder.ComputerFound += new EventHandler<FinderEventArgs>(finder_ComputerFound); finder.SearchFinished += new EventHandler(finder_SearchFinished); finder.StartSearch(); } _isSearching = true; }