Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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);
        }