コード例 #1
0
ファイル: ScannersCommon.cs プロジェクト: Jarczyslaw/JToolbox
        public static async Task <List <PortResult> > IsPortOpen(PortInput input, IPortClient portClient)
        {
            var result = new List <PortResult>();

            foreach (var port in input.Ports)
            {
                var       isOpen    = false;
                Exception exception = null;
                for (int i = 0; i < input.Retries; i++)
                {
                    try
                    {
                        isOpen = await portClient.Check(input.Address, port, input.Timeout);

                        if (isOpen)
                        {
                            break;
                        }
                    }
                    catch (Exception exc)
                    {
                        exception = exc;
                    }
                }

                result.Add(new PortResult
                {
                    IsOpen        = isOpen,
                    Port          = port,
                    LastException = exception
                });
            }
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceDataClientRepository" /> class.
 /// </summary>
 /// <param name="applicationSettings">The application settings.</param>
 public ReferenceDataClientRepository(IApplicationSettings applicationSettings)
 {
     if (applicationSettings != null)
     {
         this.countryClient = DIContainer.Instance.Resolve<ICountryClient>(new ResolverOverride[] { new ParameterOverride(BaseAddressParameterName, applicationSettings.ReferenceDataServiceBaseAddress) });
         this.personTypeClient = DIContainer.Instance.Resolve<IPersonTypeClient>(new ResolverOverride[] { new ParameterOverride(BaseAddressParameterName, applicationSettings.ReferenceDataServiceBaseAddress) });
         this.documentTypeClient = DIContainer.Instance.Resolve<IDocumentTypeClient>(new ResolverOverride[] { new ParameterOverride(BaseAddressParameterName, applicationSettings.ReferenceDataServiceBaseAddress) });
         this.loyaltyLevelTypeClient = DIContainer.Instance.Resolve<ILoyaltyLevelTypeClient>(new ResolverOverride[] { new ParameterOverride(BaseAddressParameterName, applicationSettings.ReferenceDataServiceBaseAddress) });
         this.portClient = DIContainer.Instance.Resolve<IPortClient>(new ResolverOverride[] { new ParameterOverride(BaseAddressParameterName, applicationSettings.ReferenceDataServiceBaseAddress) });
     }
 }
コード例 #3
0
        public Task <List <ProcessingQueueItem <ServiceInput, bool> > > ServiceScan(ServiceScanInput serviceScanInput, IPortClient portClient, CancellationToken cancellationToken = default)
        {
            this.portClient = portClient;
            var input = serviceScanInput.Addresses.Select(s => new ServiceInput
            {
                Endpoint = new IPEndPoint(s, serviceScanInput.Port),
                Retries  = serviceScanInput.Retries,
                Timeout  = serviceScanInput.Timeout
            }).ToList();

            return(Run(input, cancellationToken));
        }
コード例 #4
0
ファイル: PortScanner.cs プロジェクト: Jarczyslaw/JToolbox
        public Task <List <ProcessingQueueItem <PortInput, List <PortResult> > > > PortScan(PortScanInput portScanInput, IPortClient portClient, CancellationToken cancellationToken = default)
        {
            this.portClient = portClient;
            var input = portScanInput.Addresses.Select(s => new PortInput
            {
                Address = s,
                Ports   = portScanInput.Ports,
                Retries = portScanInput.Retries,
                Timeout = portScanInput.Timeout
            }).ToList();

            return(Run(input, cancellationToken));
        }
コード例 #5
0
ファイル: PortScanner.cs プロジェクト: Jarczyslaw/JToolbox
 public Task <List <PortResult> > CheckPort(PortInput item, IPortClient portClient)
 {
     this.portClient = portClient;
     return(ProcessItem(item));
 }
コード例 #6
0
 public Task <bool> CheckService(ServiceInput item, IPortClient portClient)
 {
     this.portClient = portClient;
     return(ProcessItem(item));
 }
コード例 #7
0
        public async Task <List <PortScanResult> > PortScan(PortScanInput portScanInput, IPortClient portClient)
        {
            var result           = new BlockingCollection <PortScanResult>();
            var mergedInput      = MergePortScanInput(portScanInput);
            var addressPortPairs = mergedInput.ChunkInto(portScanInput.Workers);

            await AsyncHelper.ForEach(addressPortPairs, async (addressPortPair, token) =>
            {
                foreach (var pair in addressPortPair)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    var portResultEntry = await IsPortOpen(new PortInput
                    {
                        Address = pair.Address,
                        Retries = portScanInput.Retries,
                        Timeout = portScanInput.Timeout,
                        Port    = pair.Port
                    }, portClient);

                    var addressResult = result.FirstOrDefault(r => r.Address == pair.Address);
                    if (addressResult == null)
                    {
                        var portResult = new PortScanResult
                        {
                            Address = pair.Address,
                        };
                        portResult.Results.Add(portResultEntry);
                        result.Add(portResult);
                    }
                    else
                    {
                        addressResult.Results.Add(portResultEntry);
                    }
                    OnPortScanned(pair.Address, portResultEntry);
                }
            }, portScanInput.CancellationToken);

            var finalResult = result.ToList();

            OnPortsScanComplete(finalResult);
            return(finalResult);
        }