public void FixAdifDates() { List<Contact> adifContacts = AdifHandler.ImportAdif(File.ReadAllText(@"C:\temp\test.adi"), string.Empty, 0, "M0VFC"); ContactStore store = new ContactStore("localhost", "fp2011", "root", "aopen"); foreach (Contact adifContact in adifContacts) { // Find the matching one in the DB List<Contact> existingContacts = store.GetPreviousContacts(adifContact.Callsign); List<Contact> probableMatches = existingContacts.FindAll(c => c.StartTime.TimeOfDay == adifContact.StartTime.TimeOfDay && c.Band == adifContact.Band); if (probableMatches.Count == 1) { probableMatches[0].StartTime = probableMatches[0].EndTime = adifContact.StartTime; store.SaveContact(probableMatches[0]); } else { Assert.Fail("Failed to find single matching QSO: " + adifContact); } } }
private void RunMixWSync() { DateTime lastQsoThisRun = m_LastQsoSeen; using (ContactStore cs = new ContactStore(m_Server, m_Database, m_Username, m_Password)) { Exception storedEx = null; string[] logLines = File.ReadAllLines(m_ConnString); foreach (string line in logLines) { string[] lineBits = line.Split(';'); Contact c = new Contact(); long freq = long.Parse(lineBits[6]) / 1000 * 1000; string dateString = lineBits[2]; c.Band = BandHelper.FromFrequency(freq); c.Callsign = lineBits[1].Trim().ToUpperInvariant(); c.EndTime = c.StartTime = new DateTime( int.Parse(dateString.Substring(0, 4)), int.Parse(dateString.Substring(4, 2)), int.Parse(dateString.Substring(6, 2)), int.Parse(dateString.Substring(8, 2)), int.Parse(dateString.Substring(10, 2)), int.Parse(dateString.Substring(12, 2))); c.Frequency = freq; c.Mode = ModeHelper.Parse(lineBits[9]); c.Operator = m_DefaultOperator.Text; c.ReportReceived = lineBits[10]; c.ReportSent = lineBits[11]; c.Station = m_Station; // If we've already uploaded something more recent, don't bother hitting the DB... if (m_LastQsoSeen >= c.StartTime) { continue; } if (c.StartTime > lastQsoThisRun) lastQsoThisRun = c.StartTime; Contact previousQso = cs.GetPreviousContacts(c.Callsign).Find(previousContact => previousContact.StartTime == c.StartTime); if (previousQso == null) { cs.SaveContact(c); Invoke(new MethodInvoker(() => m_LastQsoLabel.Text = c.Callsign)); } } m_LastQsoSeen = lastQsoThisRun; if (storedEx != null) throw storedEx; } }