Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/11 17:16:42 (13 years ago)
Author:
ascheibe
Message:

#1648 worked on webservice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientUserManagement/HeuristicLab.GeoIP/1.12/DatabaseInfo.cs

    r6826 r6852  
    2121
    2222using System;
    23 using System.IO;
    2423
    2524public class DatabaseInfo {
    2625
    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;
     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;
    3736
    38     //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
     37  //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    3938
    40     private String info;
    41    /**
    42      * Creates a new DatabaseInfo object given the database info String.
    43      * @param info
    44      */
     39  private String info;
     40  /**
     41    * Creates a new DatabaseInfo object given the database info String.
     42    * @param info
     43    */
    4544
    46     public DatabaseInfo(String info) {
    47         this.info = info;
     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;
    4857    }
     58  }
    4959
    50     public int getType() {
    51         if ((info == null) | (info == "")) {
    52             return COUNTRY_EDITION;
     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          //}
    5382        }
    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;
     83        catch (Exception e) {
     84          Console.Write(e.Message);
    5985        }
     86        break;
     87      }
    6088    }
     89    return DateTime.Now;
     90  }
    6191
    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     }
     92  public String toString() {
     93    return info;
     94  }
    9795}
    9896
Note: See TracChangeset for help on using the changeset viewer.