Click here to Skip to main content
15,886,091 members
Articles / Hosted Services / Azure

GPS Runner Maps: My First Windows Azure Application

Rate me:
Please Sign up or sign in to vote.
4.90/5 (12 votes)
20 Dec 2009CPOL3 min read 55.2K   3.1K   63  
It is "cloud" Web application to display GPS tracks on Google or Bing maps
/*
 * GameWatch - Server Browser for online games
 * Copyright (C) 2002 Rodrigo Reyes <reyes@charabia.net>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 */

using System;
using System.Reflection;
using System.Collections;
using System.IO;
using GameWatch.Utils;
using GameWatch.Utils.Net;

namespace GameWatch
{
  public class ITCTest
  {
    public IPToCountry Ip2Country = new IPToCountry();

    public void LoadIpCountryTable(string name)
    {
      StreamReader sr = new StreamReader(Ip2Country.GetStream(name));
      Ip2Country.Load(sr);
      sr.Close();
    }

    public ArrayList LoadIpList(string name)
    {
      ArrayList result = new ArrayList();

      FileStream fs = new FileStream(name, FileMode.Open);
      StreamReader sr = new StreamReader(fs);

      string line;

      while ((line = sr.ReadLine()) != null)
      {
        result.Add(line);
      }

      sr.Close();
      fs.Close();

      return result;
    }

    [STAThread]
    public static void Main(string[] args)
    {

      ITCTest m = new ITCTest();
      long initialmemory = GC.GetTotalMemory(true);
      DateTime loadstart = DateTime.Now;
      m.LoadIpCountryTable(@"resources\apnic.latest");
      m.LoadIpCountryTable(@"resources\arin.latest");
      m.LoadIpCountryTable(@"resources\lacnic.latest");
      m.LoadIpCountryTable(@"resources\ripencc.latest");
      DateTime loadend = DateTime.Now;
      GC.Collect();
      GC.WaitForPendingFinalizers();
      long afterloadmemory = GC.GetTotalMemory(true);

      DateTime iploadstart = DateTime.Now;
      ArrayList ips = m.LoadIpList("iplist.txt");
      DateTime iploadend = DateTime.Now;

      Console.WriteLine("Max memory taken by the tables: {0}KB", (afterloadmemory - initialmemory) / 1024);
      Console.WriteLine("IP tables loaded in {0} ({1} networks)", (loadend - loadstart), IPToCountry.NetworkCodeCount);
      Console.WriteLine("IP list loaded in {0} ({1} ip addresses)",
            (iploadend - iploadstart),
            ips.Count);

      Console.WriteLine("Testing ip look-up speed...");

      DateTime teststart = DateTime.Now;
      foreach (String ip in ips)
      {
        m.Ip2Country.GetCountry(ip);
      }
      DateTime testend = DateTime.Now;

      TimeSpan diff = testend - teststart;
      Console.WriteLine("{0} addresses were translated in {1} ({2} ip/s)",
            ips.Count, diff,
            (int)(ips.Count / diff.TotalMilliseconds * 1000));

      Console.WriteLine("Country code for 195.149.21.72: {0}", m.Ip2Country.GetCountry("195.149.21.72"));
      Console.WriteLine("Country code for 81.3.59.134: {0}", m.Ip2Country.GetCountry("81.3.59.134"));
      Console.WriteLine("Country code for 195.200.92.42: {0}", m.Ip2Country.GetCountry("195.200.92.42"));
    }
  }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Forthnet
Greece Greece
Software developer and Microsoft Trainer, Athens, Greece (MCT, MCSD.net, MCSE 2003, MCDBA 2000,MCTS, MCITP, MCIPD).

Comments and Discussions