Example #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            _bindingList.Clear();

            IPAddress minimum;
            IPAddress maximum;

            if (!IPAddress.TryParse(_txtMimimum.Text, out minimum))
            {
                MessageBox.Show(
                    this,
                    @"Неправильно указан минимальный адрес.",
                    @"Scan Service",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }

            if (!IPAddress.TryParse(_txtMaximum.Text, out maximum))
            {
                MessageBox.Show(
                    this,
                    @"Неправильно указан максимальный адрес.",
                    @"Scan Service",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }

            _scanServiceConfigration.Minimum = minimum;
            _scanServiceConfigration.Maximum = maximum;

            using (var scanner = new ScanService(_scanServiceConfigration))
            {
                var list = await scanner.ScanNetworkAsync();

                if (list == null || list.Count == 0)
                {
                    MessageBox.Show(
                        this,
                        @"Видеокамеры не найдены.",
                        @"Scan Service",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                    return;
                }

                foreach (var ipAddressData in list)
                {
                    if (ipAddressData == null)
                    {
                        return;
                    }

                    _bindingList.Add(ipAddressData);
                }
            }
        }