Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.Orienteering/HeuristicLab.GeoIP/1.12/DatabaseInfo.cs @ 11136

Last change on this file since 11136 was 8040, checked in by ascheibe, 12 years ago

#1648 integrated server parts of the access service into trunk

File size: 2.7 KB
Line 
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
22using System;
23
24public class DatabaseInfo {
25
26  public static int COUNTRY_EDITION = 1;
27  public static int REGION_EDITION_REV0 = 7;
28  public static int REGION_EDITION_REV1 = 3;
29  public static int CITY_EDITION_REV0 = 6;
30  public static int CITY_EDITION_REV1 = 2;
31  public static int ORG_EDITION = 5;
32  public static int ISP_EDITION = 4;
33  public static int PROXY_EDITION = 8;
34  public static int ASNUM_EDITION = 9;
35  public static int NETSPEED_EDITION = 10;
36
37  //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
38
39  private String info;
40  /**
41    * Creates a new DatabaseInfo object given the database info String.
42    * @param info
43    */
44
45  public DatabaseInfo(String info) {
46    this.info = info;
47  }
48
49  public int getType() {
50    if ((info == null) | (info == "")) {
51      return COUNTRY_EDITION;
52    } else {
53      // Get the type code from the database info string and then
54      // subtract 105 from the value to preserve compatability with
55      // databases from April 2003 and earlier.
56      return Convert.ToInt32(info.Substring(4, 7)) - 105;
57    }
58  }
59
60  /**
61   * Returns true if the database is the premium version.
62   *
63   * @return true if the premium version of the database.
64   */
65  public bool isPremium() {
66    return info.IndexOf("FREE") < 0;
67  }
68
69  /**
70   * Returns the date of the database.
71   *
72   * @return the date of the database.
73   */
74  public DateTime getDate() {
75    for (int i = 0; i < info.Length - 9; i++) {
76      if (Char.IsWhiteSpace(info[i]) == true) {
77        String dateString = info.Substring(i + 1, i + 9);
78        try {
79          //synchronized (formatter) {
80          return DateTime.ParseExact(dateString, "yyyyMMdd", null);
81          //}
82        }
83        catch (Exception e) {
84          Console.Write(e.Message);
85        }
86        break;
87      }
88    }
89    return DateTime.Now;
90  }
91
92  public String toString() {
93    return info;
94  }
95}
96
97
Note: See TracBrowser for help on using the repository browser.