Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        private void RunHrdSync()
        {
            using (ContactStore cs = new ContactStore(m_Server, m_Database, m_Username, m_Password))
            {
                Exception storedEx = null;

                using (OdbcConnection localConn = new OdbcConnection(m_ConnString))
                {
                    localConn.Open();
                    List<int> keysToMarkUploaded = new List<int>();
                    using (OdbcCommand localCmd = localConn.CreateCommand())
                    {
                        try
                        {
                            localCmd.CommandText = @"SELECT * FROM TABLE_HRD_CONTACTS_V01 WHERE COL_USER_DEFINED_1 IS NULL OR COL_USER_DEFINED_1 <> 'CamLogUploadDone'";
                            using (OdbcDataReader reader = localCmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    Contact c = new Contact();
                                    c.SourceId = cs.SourceId;
                                    c.Callsign = (string)reader["COL_CALL"];
                                    c.StartTime = (DateTime)reader["COL_TIME_ON"];
                                    c.EndTime = (DateTime)reader["COL_TIME_OFF"];
                                    c.Band = BandHelper.Parse(reader["COL_BAND"] as string);
                                    c.Frequency = GetFrequency(reader.GetInt32(reader.GetOrdinal("COL_FREQ")).ToString());
                                    c.Mode = ModeHelper.Parse(reader["COL_MODE"] as string);
                                    c.Operator = (reader["COL_OPERATOR"] as string) ?? m_DefaultOperator.Text;
                                    c.Station = m_Station;
                                    c.LocatorReceived = new Locator(0, 0);
                                    c.ReportReceived = c.ReportSent = "599";
                                    cs.SaveContact(c);
                                    Invoke(new MethodInvoker(() => m_LastQsoLabel.Text = c.Callsign));
                                    keysToMarkUploaded.Add(reader.GetInt32(reader.GetOrdinal("COL_PRIMARY_KEY")));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            storedEx = ex;
                        }
                    }

                    using (OdbcCommand updateCommand = localConn.CreateCommand())
                    {
                        foreach (int key in keysToMarkUploaded)
                        {
                            updateCommand.CommandText =
                                "UPDATE TABLE_HRD_CONTACTS_V01 SET COL_USER_DEFINED_1='CamLogUploadDone' WHERE COL_PRIMARY_KEY=" + key;
                            updateCommand.ExecuteNonQuery();
                        }
                    }

                    if (storedEx != null)
                        throw storedEx;
                }
            }
        }
Exemplo n.º 3
0
        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;
            }
        }