示例#1
0
        private void ReadAircraftTable(CSVReader reader)
        {
            int iColAircraft = -1;
            int iColTypeCode = -1;
            int iColModel    = -1;

            // Find the start of the aircraft table
            string[] rgRow = null;
            while ((rgRow = reader.GetCSVLine()) != null)
            {
                if (rgRow != null && rgRow.Length > 0 && rgRow[0].CompareCurrentCultureIgnoreCase("Aircraft Table") == 0)
                {
                    break;
                }
            }

            string[] rgHeaders     = reader.GetCSVLine();
            int      cColumnHeader = int.MaxValue;

            if (rgHeaders != null)
            {
                cColumnHeader = rgHeaders.Length;
                for (int i = 0; i < rgHeaders.Length; i++)
                {
                    if (rgHeaders[i].CompareCurrentCultureIgnoreCase("AircraftID") == 0)
                    {
                        iColAircraft = i;
                    }
                    else if (rgHeaders[i].CompareCurrentCultureIgnoreCase("TypeCode") == 0)
                    {
                        iColTypeCode = i;
                    }
                    else if (rgHeaders[i].CompareCurrentCultureIgnoreCase("Model") == 0)
                    {
                        iColModel = i;
                    }
                }
            }

            while ((rgRow = reader.GetCSVLine()) != null)
            {
                if (rgRow.Length == 0)
                {
                    break;
                }

                if (iColAircraft < 0 || iColAircraft >= rgRow.Length)
                {
                    break;
                }

                string szAircraft = rgRow[iColAircraft];
                if (String.IsNullOrWhiteSpace(szAircraft))
                {
                    break;
                }

                string szModel    = (iColModel >= 0) ? rgRow[iColModel] : string.Empty;
                string szTypeCode = (iColTypeCode >= 0) ? rgRow[iColTypeCode] : string.Empty;
                ForeFlightAircraftDescriptor ad = new ForeFlightAircraftDescriptor()
                {
                    AircraftID = szAircraft, Model = szModel, TypeCode = szTypeCode
                };
                dictAircraft[ad.AircraftID] = ad;
            }
        }
示例#2
0
        private void ReadAircraftTable(CSVReader reader)
        {
            int iColAircraft = -1;
            int iColTypeCode = -1;
            int iColModel    = -1;

            // Find the start of the aircraft table
            string[] rgHeaders;
            while ((rgHeaders = reader.GetCSVLine()) != null)
            {
                if (rgHeaders != null && rgHeaders.Length > 0 && rgHeaders[0].CompareCurrentCultureIgnoreCase("Aircraft Table") == 0)
                {
                    break;
                }
            }

            // Now find the next line that isn't generic data types
            // Look for "Text", "hhmm", "Decimal", "Boolean" - if any of these, skip ahead.
            while ((rgHeaders = reader.GetCSVLine()) != null)
            {
                if (Array.Find(rgHeaders, sz => rDataTypes.IsMatch(sz)) == null)
                {
                    break;
                }
            }

            if (rgHeaders != null)
            {
                for (int i = 0; i < rgHeaders.Length; i++)
                {
                    if (rgHeaders[i].CompareCurrentCultureIgnoreCase("AircraftID") == 0)
                    {
                        iColAircraft = i;
                    }
                    else if (rgHeaders[i].CompareCurrentCultureIgnoreCase("TypeCode") == 0)
                    {
                        iColTypeCode = i;
                    }
                    else if (rgHeaders[i].CompareCurrentCultureIgnoreCase("Model") == 0)
                    {
                        iColModel = i;
                    }
                }
            }

            string[] rgRow;

            while ((rgRow = reader.GetCSVLine()) != null)
            {
                if (rgRow.Length == 0)
                {
                    break;
                }

                if (iColAircraft < 0 || iColAircraft >= rgRow.Length)
                {
                    break;
                }

                string szAircraft = rgRow[iColAircraft];
                if (String.IsNullOrWhiteSpace(szAircraft))
                {
                    break;
                }

                string szModel    = (iColModel >= 0) ? rgRow[iColModel] : string.Empty;
                string szTypeCode = (iColTypeCode >= 0) ? rgRow[iColTypeCode] : string.Empty;
                ForeFlightAircraftDescriptor ad = new ForeFlightAircraftDescriptor()
                {
                    AircraftID = szAircraft, Model = szModel, TypeCode = szTypeCode
                };
                dictAircraft[ad.AircraftID] = ad;
            }
        }