/// <summary> /// Returns a new Icao Record from given CSV /// </summary> /// <param name="js">The record as CSV line</param> private static icaoRec FromNative(string native) { // should be the CSV variant string[] e = CsvTools.Split(native, out bool qquoted, ','); // either comma separated - from example.. // 0 1 2 3 4 5 // "icao24","registration","manufacturericao","manufacturername","model","typecode", // 6 7 8 9 10 11 // "serialnumber","linenumber","icaoaircrafttype","operator","operatorcallsign","operatoricao", // 12 13 14 15 16 17 18 19 // "operatoriata","owner","testreg","registered","reguntil","status","built","firstflightdate", // 20 21 22 23 24 25 26 // "seatconfiguration","engines","modes","adsb","acars","notes","categoryDescription" if (e.Length < 6) { return(new icaoRec("", "", "")); // Must include "typecode" to create a valid record.. } var icao = e[0].Trim(WS).ToUpperInvariant( ); // icao24 var regName = e[1].Trim(WS).ToUpperInvariant( ); // registration var airctype = e[5].Trim(WS).ToUpperInvariant( ); // typecode var manufacturer = e[3].Trim(WS); // manufacturername var airctypename = e[4].Trim(WS); // model airctype = (airctype == "0000") ? "" : airctype; // fix NULL manufacturer = manufacturer.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) airctypename = airctypename.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) return(new icaoRec(icao, regName, airctype, manufacturer)); }
/// <summary> /// Translates from native to generic record format /// </summary> /// <param name="native"></param> /// <returns></returns> private static icaoRec FromNative(string native) { /* 0 1 2 3 4 5 6 7 8 9 10 * "AircraftID", "FirstCreated", "LastModified", "ModeS", "ModeSCountry", "Country", "Registration", "CurrentRegDate", "PreviousID", "FirstRegDate", "Status", * 11 12 13 14 15 16 17 18 19 20 * "DeRegDate", "Manufacturer", "ICAOTypeCode", "Type", "SerialNo", "PopularName", "GenericName", "AircraftClass", "Engines", "OwnershipStatus", * 21 22 23 24 25 26 27 28 29 30 31 * "RegisteredOwners", "MTOW", "TotalHours", "YearBuilt", "CofACategory", "CofAExpiry", "UserNotes", "Interested", "UserTag", "InfoURL", "PictureURL1", * 32 33 34 35 36 37 38 39 40 41 42 * "PictureURL2", "PictureURL3", "UserBool1", "UserBool2", "UserBool3", "UserBool4", "UserBool5", "UserString1", "UserString2", "UserString3", "UserString4", * 43 44 45 46 47 48 49 * "UserString5", "UserInt1", "UserInt2", "UserInt3", "UserInt4", "UserInt5", "OperatorFlagCode" */ // should be the CSV variant string[] e = CsvTools.Split(native, out bool qquoted, ','); if (e.Length < 14) { return(new icaoRec("", "", "")); // must read to ICAOTypeCode } var icao = e[3].Trim(WS).ToUpperInvariant( ); // ModeS var regName = e[6].Trim(WS).ToUpperInvariant( ); // Registration var airctype = e[13].Trim(WS).ToUpperInvariant( ); // ICAOTypeCode var manufacturer = e[12].Trim(WS); // Manufacturer var airctypename = e.Length > 16 ? e[16].Trim(WS) : ""; // PopularName airctype = (airctype == "0000") ? "" : airctype; // fix NULL manufacturer = manufacturer.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) airctypename = airctypename.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) return(new icaoRec(icao, regName, airctype, manufacturer)); }