private async Task<IEnumerable<IPRangeInfo>> LocateIPv6Async(IPAddress ip)
 {
     var flatIP = new FlatIPAddress(ip);
     using (var connection = new SqliteConnection(_connectionString))
     {
         connection.Open();
         return await connection.ExecuteReaderAsync(dataReader =>
         {
             return new IPRangeInfo
             {
                 IPRange = new IPRange
                 {
                     Start = new FlatIPAddress { Low = (long)dataReader["StartLow"], High = (long)dataReader["StartHigh"] }.ToIPAddress(),
                     End = new FlatIPAddress { Low = (long)dataReader["EndLow"], High = (long)dataReader["EndHigh"] }.ToIPAddress(),
                 },
                 AreaId = Convert.ToInt32(dataReader["AreaId"]),
                 ProviderId = Convert.ToInt32(dataReader["ProviderId"]),
             };
         }, @"
             SELECT * FROM IPRangeInfos 
             WHERE (StartHigh < {1} OR (StartHigh = {1} AND StartLow <= {0}))
             AND (EndHigh > {1} OR (EndHigh = {1} AND EndLow >= {0}));",
         flatIP.Low, flatIP.High);
     }
 }
예제 #2
0
        public async Task AddIPRangeLocationRangeAsync(string providerName, IEnumerable<IPRangeLocation> ipRangeLocations, IProgress<int> progress = null)
        {
            if (ipRangeLocations == null)
            {
                throw new ArgumentNullException(nameof(ipRangeLocations));
            }

            var providerId = await GetProviderId(providerName);
            var query = @"
                    INSERT INTO IPRangeInfos (AreaId, ProviderId, StartLow, StartHigh, EndLow, EndHigh) 
                    VALUES ({0}, {1}, {2}, {3}, {4}, {5});";
            var parameterSeries = ipRangeLocations.Select(item =>
            {
                var startIP = new FlatIPAddress(item.IPRange.Start);
                var endIP = new FlatIPAddress(item.IPRange.End);
                return new object[] { item.AreaId, providerId, startIP.Low, startIP.High, endIP.Low, endIP.High };
            });

            await _connection.Value.ExecuteBatchWithoutJournalAsync(query, parameterSeries, _batchLength, progress).ConfigureAwait(false);
        }