Ejemplo n.º 1
0
        public Task <List <CheckingResult> > CheckIpRange(IPAddress from, IPAddress to, int port)
        {
            long start = IpConverter.IPAddressToLong(from);
            long end   = IpConverter.IPAddressToLong(to);

            _port = port;

            if (start > end)
            {
                throw new InvalidOperationException("Start > End");
            }

            _cancelTokenSource = new CancellationTokenSource();
            var cancelToken = _cancelTokenSource.Token;

            _task = Task.Factory.StartNew(() =>
            {
                FillQueue(start, end);

                var availabilityTask = Task.Factory.StartNew(() => CheckAvailability(cancelToken), cancelToken);
                var httpTask         = Task.Factory.StartNew(() => CheckHttp(cancelToken), cancelToken);

                Task.WaitAll(availabilityTask, httpTask);

                return(_result);
            }, cancelToken);

            return(_task);
        }
Ejemplo n.º 2
0
        public Task <List <CheckingResult> > CheckIpRange(IPAddress from, IPAddress to, int port)
        {
            long start = IpConverter.IPAddressToLong(from);
            long end   = IpConverter.IPAddressToLong(to);

            _port = port;

            if (start > end)
            {
                throw new InvalidOperationException("Start > End");
            }

            _cancelTokenSource = new CancellationTokenSource();

            _task = Task.Factory.StartNew(() =>
            {
                var parallelOptions = new ParallelOptions {
                    CancellationToken = _cancelTokenSource.Token
                };

                Parallel.For(start, end + 1, parallelOptions, CreateCheckingResult);

                Parallel.ForEach(_result, parallelOptions, CheckAvailability);

                Parallel.ForEach(_httpList, parallelOptions, CheckHttp);

                return(_result);
            }, _cancelTokenSource.Token);

            return(_task);
        }
Ejemplo n.º 3
0
        public Task <List <CheckingResult> > CheckIpRange(IPAddress from, IPAddress to, int port)
        {
            long start = IpConverter.IPAddressToLong(from);
            long end   = IpConverter.IPAddressToLong(to);

            _port = port;

            if (start > end)
            {
                throw new InvalidOperationException("Start > End");
            }

            _cancelTokenSource = new CancellationTokenSource();

            _task = Task.Factory.StartNew(() =>
            {
                FillQueue(start, end, _cancelTokenSource.Token);

                ProcessAvailability(_cancelTokenSource.Token);

                ProcessHttp(_cancelTokenSource.Token);

                return(_availabilityQueue);
            }, _cancelTokenSource.Token);

            return(_task);
        }