public void WriteDataTableCallsigns(DataTableCallsigns dt) { if (dt != null) { db.ClearTable(dt.TableName); db.InsertOrReplaceTable(dt); } }
public DataTableCallsigns ReadDataTableCallsigns() { DataTableCallsigns dtc = new DataTableCallsigns(); DataTable dt = db.Select("SELECT * FROM " + dtc.TableName); lock (dt) { foreach (DataRow row in dt.Rows) { dtc.ImportRow(row); } } return(dtc); }
public DataTable ToTable() { DataTableCallsigns dt = new DataTableCallsigns(); foreach (KeyValuePair <string, CallsignDesignator> call in Calls) { DataRow row = dt.NewRow(); row["Call"] = call.Value.Call; row["Lat"] = call.Value.Lat; row["Lon"] = call.Value.Lon; row["Source"] = call.Value.Source.ToString(); row["LastUpdated"] = call.Value.LastUpdated.ToString("u"); dt.Rows.Add(row); } return(dt); }
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); }
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); }
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); }
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); }