Пример #1
0
        public void ReportRouteJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var json = new ReportRouteJson();

            TestUtilities.TestProperty(json, "FromIndex", 0, 1);
            TestUtilities.TestProperty(json, "ToIndex", 0, 1);

            Assert.AreEqual(0, json.StopoversIndex.Count);
        }
        private void TranscribeDatabaseRecordsToJson(List <BaseStationFlight> dbFlights, List <ReportFlightJson> jsonFlights, List <ReportAircraftJson> jsonAircraft, List <ReportAirportJson> jsonAirports, List <ReportRouteJson> jsonRoutes, RequestReceivedEventArgs args, Parameters parameters)
        {
            var aircraftIdMap = new Dictionary <int, int>();
            var airportMap    = new Dictionary <string, int>();
            var routeMap      = new Dictionary <string, int>();

            int rowNumber = parameters.FromRow < 1 ? 1 : parameters.FromRow;

            foreach (var dbFlight in dbFlights)
            {
                var jsonFlight = AddReportFlightJson(dbFlight, jsonFlights, ref rowNumber);

                if (jsonAircraft != null)
                {
                    var dbAircraft = dbFlight.Aircraft;
                    if (dbAircraft == null)
                    {
                        jsonFlight.AircraftIndex = jsonAircraft.Count;
                        jsonAircraft.Add(new ReportAircraftJson()
                        {
                            IsUnknown = true
                        });
                    }
                    else
                    {
                        int aircraftIndex;
                        if (!aircraftIdMap.TryGetValue(dbAircraft.AircraftID, out aircraftIndex))
                        {
                            aircraftIndex = jsonAircraft.Count;
                            aircraftIdMap.Add(dbAircraft.AircraftID, aircraftIndex);
                            jsonAircraft.Add(CreateReportAircraftJson(dbAircraft, args));
                        }
                        jsonFlight.AircraftIndex = aircraftIndex;
                    }
                }

                int routeIndex = -1;
                if (!String.IsNullOrEmpty(dbFlight.Callsign) && !routeMap.TryGetValue(dbFlight.Callsign, out routeIndex))
                {
                    var sdmRoute = StandingDataManager.FindRoute(dbFlight.Callsign);
                    if (sdmRoute == null)
                    {
                        routeIndex = -1;
                    }
                    else
                    {
                        var jsonRoute = new ReportRouteJson()
                        {
                            FromIndex = BuildAirportJson(sdmRoute.From, airportMap, jsonAirports),
                            ToIndex   = BuildAirportJson(sdmRoute.To, airportMap, jsonAirports),
                        };
                        foreach (var stopover in sdmRoute.Stopovers)
                        {
                            int index = BuildAirportJson(stopover, airportMap, jsonAirports);
                            if (index != -1)
                            {
                                jsonRoute.StopoversIndex.Add(index);
                            }
                        }

                        routeIndex = jsonRoutes.Count;
                        jsonRoutes.Add(jsonRoute);
                        routeMap.Add(dbFlight.Callsign, routeIndex);
                    }
                }
                jsonFlight.RouteIndex = routeIndex;
            }
        }
Пример #3
0
        private void TranscribeDatabaseRecordsToJson(List <BaseStationFlight> dbFlights, List <ReportFlightJson> jsonFlights, List <ReportAircraftJson> jsonAircraft, List <ReportAirportJson> jsonAirports, List <ReportRouteJson> jsonRoutes, ReportParameters parameters, Configuration config)
        {
            var aircraftIdMap = new Dictionary <int, int>();
            var airportMap    = new Dictionary <string, int>();
            var routeMap      = new Dictionary <string, int>();

            var rowNumber = parameters.FromRow < 1 ? 1 : parameters.FromRow + 1;

            foreach (var dbFlight in dbFlights)
            {
                var jsonFlight = AddReportFlightJson(dbFlight, jsonFlights, ref rowNumber);

                if (jsonAircraft != null)
                {
                    var dbAircraft = dbFlight.Aircraft;
                    if (dbAircraft == null)
                    {
                        jsonFlight.AircraftIndex = jsonAircraft.Count;
                        jsonAircraft.Add(new ReportAircraftJson()
                        {
                            IsUnknown = true
                        });
                    }
                    else
                    {
                        if (!aircraftIdMap.TryGetValue(dbAircraft.AircraftID, out int aircraftIndex))
                        {
                            aircraftIndex = jsonAircraft.Count;
                            aircraftIdMap.Add(dbAircraft.AircraftID, aircraftIndex);
                            jsonAircraft.Add(CreateReportAircraftJson(dbAircraft, config));
                        }
                        jsonFlight.AircraftIndex = aircraftIndex;
                    }
                }

                var routeIndex = -1;
                if (!String.IsNullOrEmpty(dbFlight.Callsign) && !routeMap.TryGetValue(dbFlight.Callsign, out routeIndex))
                {
                    var operatorCode = dbFlight.Aircraft?.OperatorFlagCode;
                    foreach (var routeCallsign in SharedState.CallsignParser.GetAllRouteCallsigns(dbFlight.Callsign, operatorCode))
                    {
                        var sdmRoute = SharedState.StandingDataManager.FindRoute(routeCallsign);
                        if (sdmRoute == null)
                        {
                            routeIndex = -1;
                        }
                        else
                        {
                            var jsonRoute = new ReportRouteJson()
                            {
                                FromIndex = BuildAirportJson(sdmRoute.From, airportMap, jsonAirports, config.GoogleMapSettings.PreferIataAirportCodes),
                                ToIndex   = BuildAirportJson(sdmRoute.To, airportMap, jsonAirports, config.GoogleMapSettings.PreferIataAirportCodes),
                            };
                            foreach (var stopover in sdmRoute.Stopovers)
                            {
                                int index = BuildAirportJson(stopover, airportMap, jsonAirports, config.GoogleMapSettings.PreferIataAirportCodes);
                                if (index != -1)
                                {
                                    jsonRoute.StopoversIndex.Add(index);
                                }
                            }

                            routeIndex = jsonRoutes.Count;
                            jsonRoutes.Add(jsonRoute);
                            routeMap.Add(dbFlight.Callsign, routeIndex);

                            break;
                        }
                    }
                }
                jsonFlight.RouteIndex = routeIndex;
            }
        }