예제 #1
0
        /// <summary>
        /// Loop through all of the prefix nodes and expand the masks for each prefix.
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="prefixData"></param>
        private void BuildPrefixData(XElement prefix, PrefixData prefixData)
        {
            var primaryMaskList          = new List <string[]>();
            IEnumerable <XElement> masks = prefix.Elements().Where(x => x.Name == "masks");

            switch (prefixData)
            {
            case PrefixData _ when prefixData.Kind == PrefixKind.DXCC:
                Adifs.Add(Convert.ToInt32(prefixData.DXCC), prefixData);
                break;

            case PrefixData _ when prefixData.Kind == PrefixKind.InvalidPrefix:
                Adifs.Add(0, prefixData);
                break;

            case PrefixData _ when prefixData.Kind == PrefixKind.Province && !string.IsNullOrEmpty(prefixData.Admin1):
                if (Admins.TryGetValue(prefixData.Admin1, out var list))
                {
                    list.Add(prefixData);
                }
                else
                {
                    Admins.Add(prefixData.Admin1, new List <PrefixData> {
                        prefixData
                    });
                }
                break;
            }

            if (prefixData.WAE != 0)
            {
                Adifs.Add(prefixData.WAE, prefixData);
            }

            foreach (var element in masks.Descendants())
            {
                if (element.Value != "") // empty is usually a DXCC node
                {
                    // NEED TO TEST FOR DXCC 180 - Mt. Athos - has @@../@ pattern
                    // ALSO [xxx][.xxx]
                    // expand the mask if it exists
                    primaryMaskList = ExpandMask(element.Value);
                    // add for future lookups
                    prefixData.SetPrimaryMaskList(primaryMaskList);

                    // if pattern contains "?" then need two patterns
                    // one with # and one with @
                    List <string> patternList = BuildMaskPattern(primaryMaskList);

                    // AX9[ABD-KOPQS-VYZ][.ABD-KOPQS-VYZ]
                    SavePatternList(prefixData, patternList);
                }
                primaryMaskList = new List <string[]>();
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="prefixData"></param>
        /// <param name="patternList"></param>
        private void SavePatternList(PrefixData prefixData, List <string> patternList)
        {
            foreach (var pattern in patternList)
            {
                switch (pattern)
                {
                case string _ when pattern.Last().ToString().Contains("/"):
                    if (PortablePrefixes.TryGetValue(pattern, out var list))
                    {
                        // add to an existing list
                        // VK9/ has multiple DXCC numbers - 35, 150...
                        list.Add(prefixData);     //prefixData.DXCC
                    }

                    else
                    {
                        PortablePrefixes.TryAdd(pattern, new List <PrefixData> {
                            prefixData
                        });
                    }
                    break;

                case string _ when prefixData.Kind != PrefixKind.InvalidPrefix:
                    if (CallSignPatterns.TryGetValue(pattern, out var list2))
                    {
                        // VK9/ has multiple DXCC numbers - 35, 150...
                        list2.Add(prefixData);
                    }
                    else
                    {
                        CallSignPatterns.TryAdd(pattern, new List <PrefixData> {
                            prefixData
                        });
                    }
                    break;

                default:
                    break;
                }
            }
        }
예제 #3
0
파일: Hit.cs 프로젝트: W6OP/CallParser
        /// <summary>
        /// Using the PrefixData object populate this Hit.
        /// </summary>
        /// <param name="prefixData">PrefixData</param>
        private void PopulateHit(PrefixData prefixData)
        {
            WAE           = prefixData.WAE;
            WAP           = prefixData.WAP;
            Iota          = prefixData.Iota;
            IsIota        = prefixData.IsIota;
            CQ            = prefixData.CQ;
            ITU           = prefixData.ITU;
            Admin1        = prefixData.Admin1;
            Admin2        = prefixData.Admin2;
            Latitude      = prefixData.Latitude;
            Longitude     = prefixData.Longitude;
            Continent     = prefixData.Continent;
            TimeZone      = prefixData.TimeZone;
            Name          = prefixData.Name;
            QTH           = prefixData.QTH;
            CallbookEntry = prefixData.CallbookEntry;
            Kind          = prefixData.Kind;
            Country       = prefixData.Country;
            Province      = prefixData.Province;
            DXCC          = prefixData.DXCC;
            StartDate     = prefixData.StartDate;
            EndDate       = prefixData.EndDate;
            CallSign      = prefixData.CallSign;
            MainPrefix    = prefixData.MainPrefix;

            Comment          = prefixData.Comment;
            CallSignFlags    = prefixData.CallSignFlags;
            IsQRZInformation = prefixData.IsQRZInformation;

            if (IsQRZInformation)
            {
                FirstName = prefixData.FirstName;
                LastName  = prefixData.LastName;
                County    = prefixData.County;
                Grid      = prefixData.Grid;
                LotW      = prefixData.LotW;
            }
        }
예제 #4
0
파일: Hit.cs 프로젝트: W6OP/CallParser
 public Hit(PrefixData prefixData)
 {
     PopulateHit(prefixData);
     DXCCMerged = new HashSet <int>();
 }
예제 #5
0
        /// <summary>
        /// Read the prefix fle. If a file path is passed in then read that file.
        /// Otherwise use the embedded resource file for the prefix list. I use an
        /// XMLReader so the file is not actually loaded into memory, only the
        /// elements I am currently working with.
        /// </summary>
        /// <param name="prefixFilePath"></param>
        public void ParsePrefixFile(string prefixFilePath)
        {
            // cleanup if running more than once
            CallSignPatterns = new ConcurrentDictionary <string, List <PrefixData> >(); //1000000
            Adifs            = new SortedDictionary <int, PrefixData>();
            Admins           = new SortedDictionary <string, List <PrefixData> >();
            PortablePrefixes = new ConcurrentDictionary <string, List <PrefixData> >(); //200000

            Assembly assembly = Assembly.GetExecutingAssembly();

            if (File.Exists(prefixFilePath))
            {
                try
                {
                    using XmlReader reader = XmlReader.Create(prefixFilePath);
                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            if (reader.Name == "prefix")
                            {
                                XElement   prefix     = XNode.ReadFrom(reader) as XElement;
                                PrefixData prefixData = new PrefixData(prefix);
                                BuildPrefixData(prefix, prefixData);
                                prefixData.SortMaskList();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Unable to parse the prefix file: " + new { prefixFilePath }, ex);
                }
            }
            else
            {
                using StreamReader stream = new StreamReader(assembly.GetManifestResourceStream("W6OP.CallParser.PrefixList.xml"));
                using XmlReader reader    = XmlReader.Create(stream);
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        if (reader.Name == "prefix")
                        {
                            XElement   prefix     = XNode.ReadFrom(reader) as XElement;
                            PrefixData prefixData = new PrefixData(prefix);
                            BuildPrefixData(prefix, prefixData);
                            prefixData.SortMaskList();
                        }
                    }
                }
            }

            // DEBUGGING CODE
            //foreach (KeyValuePair<string, List<prefixData>> kvp in PortablePrefixes)
            //{
            //    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value.Count);
            //}

            //Console.WriteLine("CallSignDictionary = {0},", CallSignDictionary.Count);
            //Console.WriteLine("PortablePrefixes = {0},", PortablePrefixes.Count);
        }