Exemplo n.º 1
0
        public ArneTreeLoadTest()
        {
            //using (var reader = new StreamReader(@"TestsData\IP-COUNTRY-REGION-CITY.CSV"))
            using (var reader = new StreamReader(@"TestsData\IP-COUNTRY.CSV"))
            {
                var rangesCounter = 0;

                String line;

                var startTime = DateTime.Now;

                while ((line = reader.ReadLine()) != null)
                {
                    rangesCounter++;

                    var row = line.Split(',');

                    var parsedInt = 0u;

                    var addressRangeBegin = UInt32.TryParse(row[0].Replace('"', ' '), out parsedInt) ? parsedInt : 0u;

                    var addressRangeEnd = UInt32.TryParse(row[1].Replace('"', ' '), out parsedInt) ? parsedInt : 0u;

                    var addressRange = new Range <UInt32>(addressRangeBegin, addressRangeEnd);

                    // Skip
                    if (row[2] == @"""-""")
                    {
                        invalidAddressRanges.Add(addressRange);
                    }
                    else
                    {
                        var ip2Loc = new Ip2GeoLocation
                        {
                            addressRange = addressRange,
                            Country      = row[3]
                        };

                        geolocationTree.Add(ip2Loc);
                    }
                }

                var stopTime = DateTime.Now;

                Trace.TraceInformation("Start reading data file at {0}", startTime);

                Trace.TraceInformation("Finished reading data file at {0}", stopTime);

                Trace.TraceInformation("Time taken to read is {0} seconds", (stopTime - startTime).TotalSeconds);

                Trace.TraceInformation("Processed ranges count {0}. Valid: {1}. Invalid {2}", rangesCounter, geolocationTree.Count, invalidAddressRanges.Count);
            }
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            intArneTree = new ArneTree <Int32, Int32>();

            for (var index = 0; index < intValidArray.Length;)
            {
                var value = random.Next(intValidArray.Length * 2);

                if (intValidArray.Contains(value))
                {
                    continue;
                }

                intValidArray[index] = value;

                index++;
            }

            // Add data
            foreach (var t in intValidArray)
            {
                intArneTree.Add(t);
            }

            for (var index = 0; index < intInvalidArray.Length;)
            {
                var value = random.Next(intValidArray.Length * 2, intValidArray.Length * 4);

                if (intInvalidArray.Contains(value))
                {
                    continue;
                }

                intInvalidArray[index] = value;

                index++;
            }
        }