Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="values"></param>
        public ADIFDataSet(List <Dictionary <string, string> > values)
        {
            if (values != null)
            {
                Header = new ADIFHeader();
                QSOs   = new ADIFQSOCollection();

                foreach (var value in values)
                {
                    var qso = new ADIFQSO();
                    foreach (var key in value.Keys)
                    {
                        var tag = TagFactory.TagFromName(key);

                        if (tag != null)
                        {
                            if (value[key] != null)
                            {
                                tag.SetValue(value[key]);
                            }

                            if (tag.Header)
                            {
                                Header.Add(tag);
                            }
                            else
                            {
                                qso.Add(tag);
                            }
                        }
                    }

                    if (qso.Count > 0)
                    {
                        QSOs.Add(qso);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public ADIFDataSet Parse()
        {
            this.headers           = new Dictionary <string, string>();
            this.body              = new Dictionary <int, Dictionary <string, string> >();
            this.userDefinedFields = new List <UserDefTag>();
            this.appDefinedFields  = new List <AppDefTag>();
            headerInternal         = new ADIFHeader();

            if (string.IsNullOrWhiteSpace(this.data))
            {
                throw new InvalidOperationException("No ADIF data found.");
            }

            Initialize();
            var qsoCount = -1;

            while (this.i < this.data.Length)
            {
                var qso = GetQSO();

                if (qso != null && qso.Count > 0)
                {
                    body.Add(++qsoCount, qso);
                }
            }

            var result = new ADIFDataSet
            {
                Header = headerInternal,
                QSOs   = new ADIFQSOCollection()
            };

            foreach (var key in body.Keys)
            {
                var currentQso = body[key];
                var qso        = new ADIFQSO();
                foreach (var entry in currentQso)
                {
                    // get the tag name and build it
                    var tag = TagFactory.TagFromName(entry.Key);

                    if (tag == null)
                    {
                        if (IsUserDefinedField(entry.Key, out UserDefTag userTag))
                        {
                            tag = new UserDefValueTag(userTag);
                        }
                        else if (IsAppDefinedField(entry.Key, out AppDefTag appTag))
                        {
                            tag = appTag;
                        }
                    }

                    if (tag != null)
                    {
                        tag.SetValue(entry.Value);
                        qso.Add(tag);
                    }
                }

                result.QSOs.Add(qso);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public string ToADIF(EmitFlags flags = EmitFlags.None)
        {
            var formatString = (flags & EmitFlags.LowercaseTagNames) == EmitFlags.LowercaseTagNames ? "a" : "A";

            if ((flags & EmitFlags.MirrorOperatorAndStationCallSign) == EmitFlags.MirrorOperatorAndStationCallSign)
            {
                if (QSOs != null)
                {
                    for (var q = 0; q < QSOs.Count; q++)
                    {
                        if (QSOs[q] != null)
                        {
                            var qso = QSOs[q];

                            if (qso.Contains(TagNames.Operator) && !qso.Contains(TagNames.StationCallSign))
                            {
                                var stationCallSignTag = TagFactory.TagFromName(TagNames.StationCallSign);
                                var operatorTag        = qso[qso.IndexOf(TagNames.Operator)];
                                stationCallSignTag.SetValue(operatorTag.Value);
                                QSOs[q].Insert(QSOs[q].IndexOf(TagNames.Operator), stationCallSignTag);
                            }
                            else if (!qso.Contains(TagNames.Operator) && qso.Contains(TagNames.StationCallSign))
                            {
                                var operatorTag        = TagFactory.TagFromName(TagNames.Operator);
                                var stationCallSignTag = qso[qso.IndexOf(TagNames.StationCallSign)];
                                operatorTag.SetValue(stationCallSignTag.Value);
                                QSOs[q].Insert(QSOs[q].IndexOf(TagNames.StationCallSign), operatorTag);
                            }
                        }
                    }
                }

                if ((flags & EmitFlags.AddCreatedTimestampIfNotPresent) == EmitFlags.AddCreatedTimestampIfNotPresent)
                {
                    if (Header == null)
                    {
                        Header = new ADIFHeader();
                    }

                    if (!Header.Contains(TagNames.CreatedTimestamp))
                    {
                        Header.Add(new CreatedTimestampTag(DateTime.UtcNow));
                    }
                }

                if ((flags & EmitFlags.AddProgramIdIfNotPresent) == EmitFlags.AddProgramIdIfNotPresent)
                {
                    if (Header == null)
                    {
                        Header = new ADIFHeader();
                    }

                    if (!Header.Contains(TagNames.ProgramId))
                    {
                        Header.Add(new ProgramIdTag(Values.DEFAULT_PROGRAM_ID));
                    }
                }
            }

            return(ToString(formatString, CultureInfo.CurrentCulture));
        }