Example #1
0
        /// <summary>
        /// Search for Location
        /// </summary>
        /// <param name="ipAddress">IP Address</param>
        /// <returns>Location</returns>
        public async Task <ILocation> Search(string ipAddress)
        {
            if (string.IsNullOrWhiteSpace(ipAddress))
            {
                throw new ArgumentException("ipAddress");
            }

            var octets = ipAddress.Split('.');

            long ipValue = 16777216 * long.Parse(octets[0]);

            ipValue += 65536 * long.Parse(octets[1]);
            ipValue += 256 * long.Parse(octets[2]);
            ipValue += long.Parse(octets[3]);

            var floored = this.Floor(ipValue);

            var container = new BinaryContainer(spatialIpContainer);
            var data      = container.Get(string.Format(spatialIpFileFormat, floored));

            if (null != data)
            {
                var locations = data.Deserialize <List <SearchLocationIp> >();

                return(locations.Where(l => l.StartIp <= ipValue && l.EndIp >= ipValue).FirstOrDefault());
            }

            return(null);
        }
Example #2
0
        public void RoundTrip()
        {
            var data   = new byte[64];
            var random = new Random();

            random.NextBytes(data);
            var objId     = "a" + Guid.NewGuid().ToString();
            var container = new BinaryContainer("test");

            container.Create().Wait();

            container.Save(objId, data);

            var result = container.Get(objId);

            Assert.IsNotNull(result);
            Assert.AreEqual <int>(data.Length, result.Length);
            for (var i = 0; i < data.Length; i++)
            {
                Assert.AreEqual <byte>(data[i], result[i]);
            }
        }