Пример #1
0
        public IPRangesGroup GetRangesGroup()
        {
            var amazonRegionMapper = new AmazonRegionMapper();

            var prefixes       = new AmazonIpRangeSource().LoadPrefixes();
            var rangesByRegion =
                prefixes.Select(
                    prefix =>
            {
                var regionInformation = amazonRegionMapper.GetIPRangesRegion(prefix.Region);
                return(new
                {
                    regionInformation.Id,
                    regionInformation.Name,
                    regionInformation.Description,
                    prefix.IpPrefix
                });
            })
                .ToLookup(x => x.Id);

            var regionIds = rangesByRegion.Select(x => x.Key).Distinct().OrderBy(x => x);

            var ipRangesGroup = new IPRangesGroup {
                Name = "AmazonAWS"
            };

            foreach (var regionId in regionIds)
            {
                IPRangesRegion ipRangesRegion = null;

                foreach (var range in rangesByRegion[regionId].Distinct())
                {
                    if (ipRangesRegion == null)
                    {
                        ipRangesRegion = new IPRangesRegion
                        {
                            Id          = range.Id,
                            Name        = range.Name,
                            Description = range.Description
                        };
                        ipRangesGroup.Regions.Add(ipRangesRegion);
                    }

                    var ipRange = IPRange.Parse(range.IpPrefix);
                    ipRangesRegion.Ranges.Add(ipRange);
                }
            }

            return(ipRangesGroup);
        }
Пример #2
0
        public IPRangesGroup GetRangesGroup()
        {
            var amazonRegionMapper = new AmazonRegionMapper();

            var prefixes = new AmazonIpRangeSource().LoadPrefixes();
            var rangesByRegion =
                prefixes.Select(
                    prefix =>
                    {
                        var regionInformation = amazonRegionMapper.GetIPRangesRegion(prefix.Region);
                        return new
                        {
                            regionInformation.Id,
                            regionInformation.Name,
                            regionInformation.Description,
                            prefix.IpPrefix
                        };
                    })
                    .ToLookup(x => x.Id);

            var regionIds = rangesByRegion.Select(x => x.Key).Distinct().OrderBy(x => x);

            var ipRangesGroup = new IPRangesGroup { Name = "AmazonAWS" };

            foreach (var regionId in regionIds)
            {
                IPRangesRegion ipRangesRegion = null;

                foreach (var range in rangesByRegion[regionId].Distinct())
                {
                    if (ipRangesRegion == null)
                    {
                        ipRangesRegion = new IPRangesRegion
                        {
                            Id = range.Id,
                            Name = range.Name,
                            Description = range.Description
                        };
                        ipRangesGroup.Regions.Add(ipRangesRegion);
                    }

                    var ipRange = IPRange.Parse(range.IpPrefix);
                    ipRangesRegion.Ranges.Add(ipRange);
                }
            }

            return ipRangesGroup;
        }