Пример #1
0
        private async void BtnStart_Click(object sender, EventArgs e)
        {
            try
            {
                logger.Info("Scan starting");

                var beginIpAddress = TxtIPRangeBegin.Text.Replace(",", ".").Replace(" ", "");
                var endIpAddress   = TxtIPRangeEnd.Text.Replace(",", ".").Replace(" ", "");

                if (!IPAddressRange.TryParse(string.Format("{0}-{1}", beginIpAddress, endIpAddress), out IPAddressRange ipAddressRange))
                {
                    MessageBox.Show("IP Range not valid!", "Input Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

                    logger.Info("IP Range validation failed. Scan aborted");

                    return;
                }

                BtnStart.Enabled = false;

                logger.Info("Scan initializing");
                LblStatusText.Text = "Scan Initializing";

                ScanResultItems           = new List <ScanResultItem>();
                DgwScanResults.DataSource = typeof(ScanResultItem);
                DgwScanResults.DataSource = ScanResultItems;

                Scanner = new Scanner(TbParallelTaskCount.Value);

                Scanner.OnStarted            += Scanner_OnStarted;
                Scanner.OnCanceling          += Scanner_OnCanceling;
                Scanner.OnCanceled           += Scanner_OnCanceled;
                Scanner.OnFinished           += Scanner_OnFinished;
                Scanner.OnPortCheckCompleted += Scanner_OnPortCheckCompleted;

                logger.Info("Scan queue populating");

                await Scanner.AddQueueAsync(ipAddressRange.AsEnumerable());

                logger.Info("Scan start requesting");

                await Scanner.StartAsync();
            }
            catch (AggregateException)
            {
                BtnStart.Enabled = true;
                BtnStop.Enabled  = false;
            }
            catch (OperationCanceledException)
            {
                BtnStart.Enabled = true;
                BtnStop.Enabled  = false;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Пример #2
0
 public void Is_ScannerAddQueue_Run_Correctly(IPAddressRange ipAddressRange)
 {
     Assert.DoesNotThrowAsync(async() => { await _scanner.AddQueueAsync(ipAddressRange); });
     Assert.IsNotNull(_scanner.ScannerQueues);
     CollectionAssert.IsNotEmpty(_scanner.ScannerQueues);
 }