/// <summary> /// Sends the aircraft list to the connection passed across. /// </summary> /// <param name="connection">Null the established connection should be used, otherwise the new connection /// that the connector has created.</param> private void SendAircraftList(IConnection connection) { var feed = RebroadcastServer.Feed; var aircraftList = feed == null ? null : feed.AircraftList; var connector = RebroadcastServer.Connector; var isNewConnection = connection != null; if (aircraftList != null && RebroadcastServer.Online && connector != null && (connector.HasConnection || isNewConnection)) { long timestamp, dataVersion; var snapshot = aircraftList.TakeSnapshot(out timestamp, out dataVersion); var args = new AircraftListJsonBuilderArgs() { AlwaysShowIcao = true, FeedsNotRequired = true, IgnoreUnchanged = true, OnlyIncludeMessageFields = true, SourceFeedId = feed.UniqueId, PreviousDataVersion = isNewConnection ? -1 : _PreviousDataVersion, }; if (!isNewConnection) { if (_PreviousAircraftList != null) { args.PreviousAircraft.AddRange(_PreviousAircraftList); } _PreviousAircraftList = snapshot.Select(r => r.UniqueId).ToArray(); _PreviousDataVersion = dataVersion; } var json = _AircraftListJsonBuilder.Build(args, ignoreInvisibleFeeds: false, fallbackToDefaultFeed: false); if (json.Aircraft.Count > 0) { var jsonText = JsonConvert.SerializeObject(json, _AircraftListJsonSerialiserSettings); // The json text can include some entries that have ICAO codes and nothing else. When I // first wrote this I was taking them out at this point... but that is a mistake, if the // aircraft is sending messages between refreshes but not changing any message values (e.g. // test beacons that transmit a constant callsign, altitude etc. then by removing their // entry here we make the receiving end think that they've gone off the radar. We need to // send ICAOs for aircraft that aren't changing message values. var bytes = Encoding.UTF8.GetBytes(jsonText); if (connection != null) { connection.Write(bytes); } else { connector.Write(bytes); } } } }
/// <summary> /// Sends the appropriate AircraftList.json content in response to the request passed across. /// </summary> /// <param name="args"></param> /// <param name="feedId"></param> /// <param name="aircraftList"></param> /// <param name="isFlightSimulator"></param> /// <returns>Always returns true - this just helps to make the caller's code a little more compact.</returns> private bool HandleAircraftListJson(RequestReceivedEventArgs args, int feedId, IAircraftList aircraftList, bool isFlightSimulator) { if (_Builder == null) { _Builder = Factory.Singleton.Resolve <IAircraftListJsonBuilder>(); _Builder.Initialise(Provider); } var buildArgs = ConstructBuildArgs(args, feedId, aircraftList, isFlightSimulator); var json = _Builder.Build(buildArgs); if (buildArgs.ServerTimeTicks > -1 && buildArgs.ServerTimeTicks <= _ConfigurationChangedTick) { json.ServerConfigChanged = true; } Responder.SendJson(args.Request, args.Response, json, args.QueryString["callback"], null); args.Classification = ContentClassification.Json; return(true); }