Permalink
Browse files

Initial revision

  • Loading branch information...
0 parents commit 800a935537097e1890a3f8b342ed1bc60126928b Thomas J Mather committed Jul 23, 2004
Showing with 873 additions and 0 deletions.
  1. +2 −0 ChangeLog
  2. +56 −0 Country.cs
  3. +96 −0 DatabaseInfo.cs
  4. +63 −0 Location.cs
  5. +542 −0 LookupService.cs
  6. +29 −0 README
  7. +24 −0 Region.cs
  8. +21 −0 cityExample.cs
  9. +13 −0 countryExample.cs
  10. +12 −0 orgExample.cs
  11. +15 −0 regionExample.cs
@@ -0,0 +1,2 @@
+1.0 July 23rd, 2004
+ Initial Release
@@ -0,0 +1,56 @@
+/**
+ * Country.cs
+ *
+ * Copyright (C) 2004 MaxMind LLC. All Rights Reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+using System;
+using System.IO;
+public class Country {
+
+ private String code;
+ private String name;
+
+ /**
+ * Creates a new Country.
+ *
+ * @param code the country code.
+ * @param name the country name.
+ */
+ public Country(String code, String name) {
+ this.code = code;
+ this.name = name;
+ }
+ /**
+ * Returns the ISO two-letter country code of this country.
+ *
+ * @return the country code.
+ */
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * Returns the name of this country.
+ *
+ * @return the country name.
+ */
+ public String getName() {
+ return name;
+ }
+}
@@ -0,0 +1,96 @@
+/**
+ * DatabaseInfo.java
+ *
+ * Copyright (C) 2004 MaxMind LLC. All Rights Reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+using System;
+using System.IO;
+
+public class DatabaseInfo {
+
+ public static int COUNTRY_EDITION = 1;
+ public static int REGION_EDITION_REV0 = 7;
+ public static int REGION_EDITION_REV1 = 3;
+ public static int CITY_EDITION_REV0 = 6;
+ public static int CITY_EDITION_REV1 = 2;
+ public static int ORG_EDITION = 5;
+ public static int ISP_EDITION = 4;
+
+ //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
+
+ private String info;
+ /**
+ * Creates a new DatabaseInfo object given the database info String.
+ * @param info
+ */
+
+ public DatabaseInfo(String info) {
+ this.info = info;
+ }
+
+ public int getType() {
+ if ((info == null) | (info == "")) {
+ return COUNTRY_EDITION;
+ }
+ else {
+ // Get the type code from the database info string and then
+ // subtract 105 from the value to preserve compatability with
+ // databases from April 2003 and earlier.
+ return Convert.ToInt32(info.Substring(4, 7)) - 105;
+ }
+ }
+
+ /**
+ * Returns true if the database is the premium version.
+ *
+ * @return true if the premium version of the database.
+ */
+ public bool isPremium() {
+ return info.IndexOf("FREE") < 0;
+ }
+
+ /**
+ * Returns the date of the database.
+ *
+ * @return the date of the database.
+ */
+ public DateTime getDate() {
+ for (int i=0; i<info.Length-9; i++) {
+ if (Char.IsWhiteSpace(info[i]) == true) {
+ String dateString = info.Substring(i+1, i+9);
+ try {
+ //synchronized (formatter) {
+ return DateTime.ParseExact(dateString,"yyyyMMdd",null);
+ //}
+ }
+ catch (Exception e) {
+ Console.Write(e.Message);
+ }
+ break;
+ }
+ }
+ return DateTime.Now;
+ }
+
+ public String toString() {
+ return info;
+ }
+}
+
+
@@ -0,0 +1,63 @@
+**
+ * Location.cs
+ *
+ * Copyright (C) 2004 MaxMind LLC. All Rights Reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+using System;
+using System.IO;
+//using System.Math;
+
+public class Location {
+ public String countryCode;
+ public String countryName;
+ public String region;
+ public String city;
+ public String postalCode;
+ public double latitude;
+ public double longitude;
+ public int dma_code;
+ public int area_code;
+
+ private static double EARTH_DIAMETER = 2 * 6378.2;
+ private static double PI = 3.14159265;
+ private static double RAD_CONVERT = PI / 180;
+
+ public double distance (Location loc) {
+ double delta_lat, delta_lon;
+ double temp;
+
+ double lat1 = latitude;
+ double lon1 = longitude;
+ double lat2 = loc.latitude;
+ double lon2 = loc.longitude;
+
+ // convert degrees to radians
+ lat1 *= RAD_CONVERT;
+ lat2 *= RAD_CONVERT;
+
+ // find the deltas
+ delta_lat = lat2 - lat1;
+ delta_lon = (lon2 - lon1) * RAD_CONVERT;
+
+ // Find the great circle distance
+ temp = Math.Pow(Math.Sin(delta_lat/2),2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(delta_lon/2),2);
+ return EARTH_DIAMETER * Math.Atan2(Math.Sqrt(temp),Math.Sqrt(1-temp));
+ }
+}
+
Oops, something went wrong.

0 comments on commit 800a935

Please sign in to comment.