Exemplo n.º 1
0
 public CallsignDesignator(string call, double lat, double lon, GEOSOURCE source, DateTime lastupdated)
 {
     Call        = call;
     Lat         = lat;
     Lon         = lon;
     Source      = source;
     LastUpdated = lastupdated;
 }
Exemplo n.º 2
0
 public OldLocationDesignator()
 {
     Call        = "";
     Lat         = 0;
     Lon         = 0;
     Source      = GEOSOURCE.UNKONWN;
     LastUpdated = DateTime.MinValue;
 }
Exemplo n.º 3
0
 public LocationDesignator(string call, string loc, double lat, double lon, GEOSOURCE source, int hits, DateTime lastupdated) : this()
 {
     Call              = call.ToUpper().Trim();
     Loc               = loc;
     Lat               = lat;
     Lon               = lon;
     Source            = source;
     Hits              = hits;
     Elevation         = 0;
     BestCaseElevation = false;
     LastUpdated       = lastupdated;
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
0
 public void FromTable(DataTable dt)
 {
     if (dt == null)
     {
         return;
     }
     foreach (DataRow row in dt.Rows)
     {
         string    call   = row[0].ToString();
         double    lat    = (double)row[1];
         double    lon    = (double)row[2];
         GEOSOURCE source = GEOSOURCE.UNKONWN;
         try
         {
             source = (GEOSOURCE)Enum.Parse(typeof(GEOSOURCE), row["Source"].ToString());
         }
         catch
         {
         }
         DateTime lastupdated = DateTime.UtcNow;
         try
         {
             try
             {
                 lastupdated = DateTime.ParseExact(row["LastUpdated"].ToString(), "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture);
                 lastupdated = lastupdated.ToUniversalTime();
             }
             catch
             {
             }
             Update(new CallsignDesignator(call, lat, lon, source, lastupdated));
         }
         catch
         {
         }
     }
 }
Exemplo n.º 6
0
 public CallsignDesignator(string calll, double lat, double lon, GEOSOURCE source)
     : this(calll, lat, lon, source, DateTime.UtcNow)
 {
 }
Exemplo n.º 7
0
        public DataTableCallsigns FromUSR(string filename)
        {
            // imports a USR with AirScout user data format
            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(';');
                            // store array values in DataTable
                            DataRow   row         = dt.NewRow();
                            string    call        = a[0];
                            double    lat         = System.Convert.ToDouble(a[1], CultureInfo.InvariantCulture);
                            double    lon         = System.Convert.ToDouble(a[2], CultureInfo.InvariantCulture);
                            GEOSOURCE source      = (MaidenheadLocator.IsPrecise(lat, lon, 3) ? GEOSOURCE.FROMUSER : GEOSOURCE.FROMLOC);
                            string    lastupdated = a[6];
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(dt);
        }
Exemplo n.º 8
0
        public DataTableCallsigns FromCSV(string filename)
        {
            // imports a variable csv format with autodetect of callsign, loc and timestamp
            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(';');
                            if (a.Length < 2)
                            {
                                a = s.Split(',');
                            }
                            string    call   = "";
                            double    lat    = double.NaN;
                            double    lon    = double.NaN;
                            string    loc    = "";
                            GEOSOURCE source = GEOSOURCE.FROMLOC;
                            // set lastupdated to filetime if no timestamp is found on file
                            string filetime    = File.GetCreationTimeUtc(filename).ToString("u");
                            string lastupdated = filetime;
                            foreach (string entry in a)
                            {
                                // search for 1st locator in line
                                if (MaidenheadLocator.Check(entry) && (entry.Length == 6) && String.IsNullOrEmpty(loc))
                                {
                                    MaidenheadLocator.LatLonFromLoc(entry, PositionInRectangle.MiddleMiddle, out lat, out lon);
                                    break;
                                }
                                // search for 1st callsign in line
                                if (Callsign.Check(entry) && String.IsNullOrEmpty(call))
                                {
                                    call = entry.Trim().ToUpper();
                                }
                                DateTime timestamp;
                                if (DateTime.TryParseExact(entry, "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out timestamp))
                                {
                                    lastupdated = timestamp.ToString("u");
                                }
                            }
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                // store array values in DataTable
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(dt);
        }
Exemplo n.º 9
0
        public DataTableCallsigns FromDTB(string filename)
        {
            // imports DTB database from Win-Test

            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        char[] buffer = new char[26];
                        sr.ReadBlock(buffer, 0, 14);
                        sr.ReadBlock(buffer, 14, 12);
                        if (!sr.EndOfStream)
                        {
                            string call        = "";
                            string loc         = "";
                            string lastupdated = "";
                            double lat         = double.NaN;
                            double lon         = double.NaN;
                            int    i           = 0;
                            while ((buffer[i] != 0) && (i < 14))
                            {
                                call += (char)buffer[i];
                                i++;
                            }
                            i = 14;
                            while ((i < 21) && (buffer[i] != 0))
                            {
                                loc += (char)buffer[i];
                                i++;
                            }
                            i = 21;
                            while ((i < 26) && (buffer[i] != 0))
                            {
                                lastupdated += (char)buffer[i];
                                i++;
                            }

                            call = call.Trim().ToUpper();
                            loc  = loc.Trim().ToUpper();
                            try
                            {
                                if (lastupdated[2] < '5')
                                {
                                    lastupdated = "20" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z";
                                }
                                else
                                {
                                    lastupdated = "19" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z";
                                }
                            }
                            catch
                            {
                            }
                            if (MaidenheadLocator.Check(loc))
                            {
                                MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon);
                            }
                            GEOSOURCE source = GEOSOURCE.FROMLOC;
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated;
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dt);
        }
Exemplo n.º 10
0
        public DataTableCallsigns FromCALL3(string filename)
        {
            // imports CALL3.TXT as used by WSJT
            // fields are
            // CALLSIGN, LOCATOR, EME FLAG, (these first three fields are used by WSJT)
            // plus optional fields:
            // STATE, FIRST NAME, EMAIL ADDRESS, NOTES, REVISION DATE

            DataTableCallsigns dt = new DataTableCallsigns();

            if (!File.Exists(filename))
            {
                return(dt);
            }
            try
            {
                string s = "";
                using (StreamReader sr = new StreamReader(File.OpenRead(filename)))
                {
                    while (!sr.EndOfStream)
                    {
                        s = sr.ReadLine();
                        if (!String.IsNullOrEmpty(s) && !s.StartsWith("//"))
                        {
                            string[] a = s.Split(',');
                            // store array values in DataTable
                            string call = a[0];
                            string loc  = a[1];
                            double lat  = double.NaN;
                            double lon  = double.NaN;
                            if (MaidenheadLocator.Check(loc))
                            {
                                MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon);
                            }
                            GEOSOURCE source      = GEOSOURCE.FROMLOC;
                            DateTime  lastupdated = DateTime.MinValue.ToUniversalTime();
                            if (a.Length >= 7)
                            {
                                // try to get an revision date maybe in various formats
                                // MMMonVHF
                                try
                                {
                                    lastupdated = DateTime.ParseExact(a[7], "MM/yy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            if (GeographicalPoint.Check(lat, lon))
                            {
                                DataRow row = dt.NewRow();
                                row["Call"]        = call;
                                row["Lat"]         = lat;
                                row["Lon"]         = lon;
                                row["Source"]      = source.ToString();
                                row["LastUpdated"] = lastupdated.ToString("u");
                                DataRow oldrow = dt.Rows.Find(row["Call"].ToString());
                                if (oldrow != null)
                                {
                                    // call found --> check for update
                                    if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0)
                                    {
                                        oldrow["Lat"]         = row["Lat"];
                                        oldrow["Lon"]         = row["Lon"];
                                        oldrow["Source"]      = row["Source"];
                                        oldrow["LastUpdated"] = row["LastUpdated"];
                                    }
                                }
                                else
                                {
                                    // add new row
                                    dt.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(dt);
        }
Exemplo n.º 11
0
 public LocationDesignator(string call, double lat, double lon, GEOSOURCE source) : this(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3), lat, lon, source, 0, DateTime.UtcNow)
 {
 }
Exemplo n.º 12
0
 public LocationDesignator(string call, string loc, GEOSOURCE source) : this(call, loc, MaidenheadLocator.LatFromLoc(loc), MaidenheadLocator.LonFromLoc(loc), source, 0, DateTime.UtcNow)
 {
 }