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);
        }
Beispiel #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();
            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);
        }
Beispiel #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);
        }
Beispiel #4
0
        private void FillQueue(long start, long end)
        {
            for (long i = start; i <= end; i++)
            {
                _cancelTokenSource.Token.ThrowIfCancellationRequested();

                var item = new CheckingResult {
                    Ip = IpConverter.LongToString(i)
                };
                _result.Add(item);
            }
        }
Beispiel #5
0
        private void FillQueue(long start, long end, CancellationToken cancellationToken)
        {
            for (long i = start; i <= end; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                _availabilityQueue.Add(new CheckingResult
                {
                    Ip = IpConverter.LongToString(i)
                });
            }
        }
        private void CreateCheckingResult(long ip)
        {
            _cancelTokenSource.Token.ThrowIfCancellationRequested();

            var item = new CheckingResult {
                Ip = IpConverter.LongToString(ip)
            };

            lock (_result)
            {
                _result.Add(item);
            }
        }