コード例 #1
0
        /// <summary>
        /// Read a data file downloaded from the FCC Univeral License System advanced search and fill the collection with its data.
        /// </summary>
        /// <param name="filename">Path to downloaded file.</param>
        public void ReadFile(String filename)
        {
            var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (!String.IsNullOrEmpty(line))
                    {
                        string[] tokens = line.Split(new char[] { '|' }, StringSplitOptions.None);
                        if (tokens != null && tokens.Length > 4)
                        {
                            string typeToken = tokens[0];
                            string callSign  = "";
                            if (!String.IsNullOrEmpty(typeToken))
                            {
                                if (typeToken.Equals("HD"))
                                {
                                    callSign = tokens[4];
                                    if (!HD.ContainsKey(callSign))
                                    {
                                        HD.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("EN"))
                                {
                                    callSign = tokens[4];
                                    if (!EN.ContainsKey(callSign))
                                    {
                                        EN.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("HS"))
                                {
                                    callSign = tokens[3];
                                    Tuple <HistoryRecordAction, String> actionType = GetHistoryActionType(tokens[5]);
                                    HistoryRecord rec = new HistoryRecord()
                                    {
                                        CallSign          = callSign,
                                        LicenseKey        = tokens[1],
                                        Date              = DateTime.ParseExact(tokens[4], "MM/dd/yyyy", CultureInfo.InvariantCulture),
                                        Action            = actionType.Item1,
                                        ActionDescription = actionType.Item2
                                    };
                                    if (!HS.ContainsKey(callSign))
                                    {
                                        List <HistoryRecord> recList = new List <HistoryRecord>();
                                        recList.Add(rec);
                                        HS.Add(callSign, recList);
                                    }
                                    else
                                    {
                                        HS[callSign].Add(rec);
                                    }
                                }
                                else if (typeToken.Equals("AM"))
                                {
                                    callSign = tokens[4];
                                    if (!AM.ContainsKey(callSign))
                                    {
                                        AM.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("SC"))
                                {
                                    callSign = tokens[4];
                                    if (!SC.ContainsKey(callSign))
                                    {
                                        SC.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("CO"))
                                {
                                    callSign = tokens[4];
                                    if (!CO.ContainsKey(callSign))
                                    {
                                        CO.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                                else if (typeToken.Equals("LM"))
                                {
                                    callSign = tokens[4];
                                    if (!LM.ContainsKey(callSign))
                                    {
                                        LM.Add(callSign, new TokenCollection(tokens));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ExtractOperatorRecords();
        }