Ejemplo n.º 1
0
        public string ToJSONArray()
        {
            JSONArrayCallsigns     a        = new JSONArrayCallsigns(this);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            settings.FloatFormatHandling  = FloatFormatHandling.String;
            settings.Formatting           = Formatting.Indented;
            string json = JsonConvert.SerializeObject(a, settings);

            return(json);
        }
Ejemplo n.º 2
0
 public DataTable FromJSONArray(string filename)
 {
     if (!File.Exists(filename))
     {
         return(new DataTableCallsigns());
     }
     try
     {
         using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
         {
             string             json = sr.ReadToEnd();
             JSONArrayCallsigns a    = JsonConvert.DeserializeObject <JSONArrayCallsigns>(json);
             // check version
             if (String.Compare(Version, a.version) != 0)
             {
                 // do upgrade/downgrade stuff here
             }
             foreach (List <string> l in a.calls)
             {
                 string    call   = l[0];
                 double    lat    = System.Convert.ToDouble(l[1], CultureInfo.InvariantCulture);
                 double    lon    = System.Convert.ToDouble(l[2], CultureInfo.InvariantCulture);
                 GEOSOURCE source = GEOSOURCE.UNKONWN;
                 try
                 {
                     source = (GEOSOURCE)Enum.Parse(typeof(GEOSOURCE), l[3]);
                 }
                 catch
                 {
                 }
                 DateTime lastupdated = DateTime.UtcNow;
                 try
                 {
                     lastupdated = System.Convert.ToDateTime(l[4]);
                 }
                 catch
                 {
                 }
                 Update(new CallsignDesignator(call, lat, lon, source, lastupdated));
             }
         }
         return(ToTable());
     }
     catch (Exception ex)
     {
     }
     return(new DataTableCallsigns());
 }