1 | /** |
---|
2 | * DatabaseInfo.java |
---|
3 | * |
---|
4 | * Copyright (C) 2008 MaxMind Inc. All Rights Reserved. |
---|
5 | * |
---|
6 | * This library is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Lesser General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2.1 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with this library; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | using System; |
---|
23 | using System.IO; |
---|
24 | |
---|
25 | public class DatabaseInfo { |
---|
26 | |
---|
27 | public static int COUNTRY_EDITION = 1; |
---|
28 | public static int REGION_EDITION_REV0 = 7; |
---|
29 | public static int REGION_EDITION_REV1 = 3; |
---|
30 | public static int CITY_EDITION_REV0 = 6; |
---|
31 | public static int CITY_EDITION_REV1 = 2; |
---|
32 | public static int ORG_EDITION = 5; |
---|
33 | public static int ISP_EDITION = 4; |
---|
34 | public static int PROXY_EDITION = 8; |
---|
35 | public static int ASNUM_EDITION = 9; |
---|
36 | public static int NETSPEED_EDITION = 10; |
---|
37 | |
---|
38 | //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); |
---|
39 | |
---|
40 | private String info; |
---|
41 | /** |
---|
42 | * Creates a new DatabaseInfo object given the database info String. |
---|
43 | * @param info |
---|
44 | */ |
---|
45 | |
---|
46 | public DatabaseInfo(String info) { |
---|
47 | this.info = info; |
---|
48 | } |
---|
49 | |
---|
50 | public int getType() { |
---|
51 | if ((info == null) | (info == "")) { |
---|
52 | return COUNTRY_EDITION; |
---|
53 | } |
---|
54 | else { |
---|
55 | // Get the type code from the database info string and then |
---|
56 | // subtract 105 from the value to preserve compatability with |
---|
57 | // databases from April 2003 and earlier. |
---|
58 | return Convert.ToInt32(info.Substring(4, 7)) - 105; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Returns true if the database is the premium version. |
---|
64 | * |
---|
65 | * @return true if the premium version of the database. |
---|
66 | */ |
---|
67 | public bool isPremium() { |
---|
68 | return info.IndexOf("FREE") < 0; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Returns the date of the database. |
---|
73 | * |
---|
74 | * @return the date of the database. |
---|
75 | */ |
---|
76 | public DateTime getDate() { |
---|
77 | for (int i=0; i<info.Length-9; i++) { |
---|
78 | if (Char.IsWhiteSpace(info[i]) == true) { |
---|
79 | String dateString = info.Substring(i+1, i+9); |
---|
80 | try { |
---|
81 | //synchronized (formatter) { |
---|
82 | return DateTime.ParseExact(dateString,"yyyyMMdd",null); |
---|
83 | //} |
---|
84 | } |
---|
85 | catch (Exception e) { |
---|
86 | Console.Write(e.Message); |
---|
87 | } |
---|
88 | break; |
---|
89 | } |
---|
90 | } |
---|
91 | return DateTime.Now; |
---|
92 | } |
---|
93 | |
---|
94 | public String toString() { |
---|
95 | return info; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | |
---|