Пример #1
0
        public static string GenerateCSV(IEnumerable <QSO> qso_list)
        {
            StringBuilder  csv = new StringBuilder(200);
            EntityResolver rem = new EntityResolver();

            int index = 1;

            csv.AppendFormat("{0},", "No");
            csv.AppendFormat("{0},", "Date");
            csv.AppendFormat("{0},", "UTC Start");
            csv.AppendFormat("{0},", "Callsign");
            csv.AppendFormat("{0},", "Country");
            csv.AppendFormat("{0},", "Name");
            csv.AppendFormat("{0},", "QTH");
            csv.AppendFormat("{0},", "Band");
            csv.AppendFormat("{0},", "Mode");
            csv.AppendFormat("{0},", "Rcvd");
            csv.AppendFormat("{0},", "Sent");
            csv.AppendFormat("{0},", "UTC End");
            csv.AppendFormat("{0}\r\n", "Exchange");

            foreach (QSO qso in qso_list)
            {
                string date = qso.Date;
                string time = qso.Time;

                csv.AppendFormat("{0},", index++);
                csv.AppendFormat("{0},", date);
                csv.AppendFormat("{0},", time);
                csv.AppendFormat("{0},", qso.DXCall);
                csv.AppendFormat("{0},", rem.GetDXCC(qso.DXCall));
                csv.AppendFormat("{0},", qso.Name);
                csv.AppendFormat("{0},", "");
                csv.AppendFormat("{0},", qso.Band);
                csv.AppendFormat("{0},", qso.Mode);
                csv.AppendFormat("{0},", qso.RST_RCVD);
                csv.AppendFormat("{0},", qso.RST_SENT);
                csv.AppendFormat("{0},", time);
                csv.AppendFormat("{0}\r\n", qso.SRX);
            }
            return(csv.ToString());
        }
Пример #2
0
        private void PopulateQSOList()
        {
            EntityResolver rem = new EntityResolver();


            m_qsoList.Clear();
            //Remove Line breakers
            string oneLiner = Regex.Replace(m_fileText, "\r\n", "");

            oneLiner = Regex.Replace(oneLiner, "\r", "");
            oneLiner = Regex.Replace(oneLiner, "\n", "");

            //Splite the Header
            string[] spliteHeader = Regex.Split(oneLiner, "<EOH>", RegexOptions.IgnoreCase);

            //Get the body
            string body = spliteHeader[1];

            //Splite body to lines
            string[] rows = Regex.Split(body, "<EOR>", RegexOptions.IgnoreCase);

            foreach (string row in rows)
            {
                //skip empty rows
                if (string.IsNullOrWhiteSpace(row))
                {
                    continue;
                }

                QSO qso_row = new QSO();
                qso_row.IsAllowWARC = IsParseWARC;

                Regex regex = new Regex(band_pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Band = Regex.Split(row, band_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value)).Trim().ToUpper();
                }

                regex = new Regex(dxcall_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.DXCall  = Regex.Split(row, dxcall_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value)).ToUpper();
                    ER_Dxcc         = rem.GetDXCC(qso_row.DXCall);
                    qso_row.Country = ER_Dxcc.Name;
                    qso_row.DXCC    = ER_Dxcc.Entity;
                }

                regex = new Regex(mycall_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.MyCall = Regex.Split(row, mycall_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value)).ToUpper();
                }
                else
                {
                    regex = new Regex(operator_call_pattern, RegexOptions.IgnoreCase);
                    match = regex.Match(row);
                    if (match.Success)
                    {
                        qso_row.MyCall = Regex.Split(row, operator_call_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value)).ToUpper();
                    }
                }

                regex = new Regex(rst_rcvd_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.RST_RCVD = Regex.Split(row, rst_rcvd_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                regex = new Regex(rst_sent_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.RST_SENT = Regex.Split(row, rst_sent_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }
                if (string.IsNullOrWhiteSpace(qso_row.RST_RCVD) && !string.IsNullOrWhiteSpace(qso_row.RST_SENT))
                {
                    qso_row.RST_RCVD = qso_row.RST_SENT;
                }
                if (string.IsNullOrWhiteSpace(qso_row.RST_SENT) && !string.IsNullOrWhiteSpace(qso_row.RST_RCVD))
                {
                    qso_row.RST_SENT = qso_row.RST_RCVD;
                }


                regex = new Regex(date_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Date = Regex.Split(row, date_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                regex = new Regex(mode_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Mode = mr.GetValidMode(Regex.Split(row, mode_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value)));
                }

                regex = new Regex(time_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Time = Regex.Split(row, time_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                regex = new Regex(commant_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Comment = Regex.Split(row, commant_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }
                else
                {
                    qso_row.Comment = "";
                }

                //if the file contains dxcc, prefer it over the EntityResolver
                regex = new Regex(dxcc_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.DXCC = Regex.Split(row, dxcc_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                regex = new Regex(srx_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.SRX = Regex.Split(row, srx_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                    if (string.IsNullOrWhiteSpace(qso_row.SRX))
                    {
                        qso_row.SRX = "000";
                    }
                }
                else
                {
                    regex = new Regex(srx_short_pattern, RegexOptions.IgnoreCase);
                    match = regex.Match(row);
                    if (match.Success)
                    {
                        qso_row.SRX = Regex.Split(row, srx_short_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                        if (string.IsNullOrWhiteSpace(qso_row.SRX))
                        {
                            qso_row.SRX = "000";
                        }
                    }
                    else
                    {
                        qso_row.SRX = "000";
                    }
                }

                regex = new Regex(stx_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.STX = Regex.Split(row, stx_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }
                else
                {
                    regex = new Regex(stx_short_pattern, RegexOptions.IgnoreCase);
                    match = regex.Match(row);
                    if (match.Success)
                    {
                        qso_row.STX = Regex.Split(row, stx_short_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                    }
                    else
                    {
                        qso_row.STX = "XXXXX";
                    }
                }

                regex = new Regex(freq_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Freq = Regex.Split(row, freq_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                regex = new Regex(name_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Name = Regex.Split(row, name_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }
                else
                {
                    qso_row.Name = "";
                }

                //if the file contains country, prefer it over the EntityResolver
                regex = new Regex(country_pattern, RegexOptions.IgnoreCase);
                match = regex.Match(row);
                if (match.Success)
                {
                    qso_row.Country = Regex.Split(row, country_pattern, RegexOptions.IgnoreCase)[2].Substring(0, int.Parse(match.Groups[1].Value));
                }

                qso_row.StandartizeQSO();
                if (IsParseDuplicates)
                {
                    m_qsoList.Add(qso_row);
                }
                else if (!IsParseDuplicates && !m_qsoList.Contains(qso_row))
                {
                    m_qsoList.Add(qso_row);
                }
            }
            m_qsoList = m_qsoList.OrderBy(p => p.Date).ThenBy(p => p.Time).ToList();
        }