Esempio n. 1
0
 public void SetAddressInfo(DatabaseInfoObject AddressInfo)
 {
     City      = AddressInfo.City;
     Country   = AddressInfo.Country;
     ZipCode   = AddressInfo.ZipCode;
     Province  = AddressInfo.Province;
     Latitude  = AddressInfo.Latitude;
     Longitude = AddressInfo.Longitude;
 }
Esempio n. 2
0
        // Binary search because I just don't have 1.5GB of free RAM
        public ClientInfoObject ResolveLocation(ClientInfoObject client)
        {
            int floor   = 0;
            int ceiling = this.DatabaseLineCount - 1;

            if (ceiling > floor)
            {
                int DecimalAddress = IPStringToDecimal(client.address);
                while (true)
                {
                    int    middle       = (int)Math.Floor((float)(floor + ceiling) / 2);
                    String DatabaseLine = String.Empty;
                    using (var FileHandle = File.OpenRead(DatabasePath))
                    {
                        // Use the index cache to avoid repeatedly iterating the entire database
                        FileHandle.Position = LineIndices[middle];
                        using (StreamReader LineReader = new StreamReader(FileHandle))
                        {
                            DatabaseLine = LineReader.ReadLine();
                        }
                    }
                    DatabaseInfoObject AddressInfo = new DatabaseInfoObject(DatabaseLine);
                    if (DecimalAddress > AddressInfo.AddressFloor && DecimalAddress < AddressInfo.AddressCeiling)
                    {
                        // Search succeeded
                        client.SetAddressInfo(AddressInfo);
                        break;
                    }
                    // Continue searching
                    else if (DecimalAddress > AddressInfo.AddressCeiling)
                    {
                        floor = middle + 1;
                    }
                    else if (DecimalAddress < AddressInfo.AddressFloor)
                    {
                        ceiling = middle - 1;
                    }
                    else
                    {
                        // Search failed
                        break;
                    }
                }
            }
            return(client);
        }