Ejemplo n.º 1
0
        /// <summary>
        /// Handles the request for the server configuration JSON.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        protected override bool DoHandleRequest(IWebServer server, RequestReceivedEventArgs args)
        {
            if ("/ServerConfig.json".Equals(args.PathAndFile, StringComparison.OrdinalIgnoreCase))
            {
                ServerConfigJson json;
                lock (_ServerConfigJson) json = (ServerConfigJson)_ServerConfigJson.Clone();
                json.IsLocalAddress = !args.IsInternetRequest;
                if (json.IsLocalAddress && !_UseGoogleMapsAPIKeyWithLocalRequests)
                {
                    json.GoogleMapsApiKey = null;
                }
                Responder.SendJson(args.Request, args.Response, json, null, null);
                args.Handled = true;
            }

            return(args.Handled);
        }
Ejemplo n.º 2
0
        public void ServerConfigJson_Clone_Creates_Copy()
        {
            foreach (var property in typeof(ServerConfigJson).GetProperties())
            {
                for (var pass = 0; pass < 2; ++pass)
                {
                    var json = new ServerConfigJson();

                    object expected = null;
                    switch (property.Name)
                    {
                    case nameof(ServerConfigJson.GoogleMapsApiKey):                         expected = json.GoogleMapsApiKey = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.InitialDistanceUnit):                      expected = json.InitialDistanceUnit = pass == 0 ? "A": "B"; break;

                    case nameof(ServerConfigJson.InitialHeightUnit):                        expected = json.InitialHeightUnit = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.InitialLatitude):                          expected = json.InitialLatitude = pass == 0 ? 1.234 : 5.678; break;

                    case nameof(ServerConfigJson.InitialLongitude):                         expected = json.InitialLongitude = pass == 0 ? 1.234 : 5.678; break;

                    case nameof(ServerConfigJson.InitialMapType):                           expected = json.InitialMapType = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.InitialSettings):                          expected = json.InitialSettings = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.InitialSpeedUnit):                         expected = json.InitialSpeedUnit = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.InitialZoom):                              expected = json.InitialZoom = pass == 0 ? 1 : 2; break;

                    case nameof(ServerConfigJson.InternetClientCanRunReports):              expected = json.InternetClientCanRunReports = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientCanShowPinText):             expected = json.InternetClientCanShowPinText = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientsCanPlayAudio):              expected = json.InternetClientsCanPlayAudio = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientsCanSeeAircraftPictures):    expected = json.InternetClientsCanSeeAircraftPictures = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientsCanSeePolarPlots):          expected = json.InternetClientsCanSeePolarPlots = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientsCanSubmitRoutes):           expected = json.InternetClientsCanSubmitRoutes = pass == 0; break;

                    case nameof(ServerConfigJson.InternetClientTimeoutMinutes):             expected = json.InternetClientTimeoutMinutes = pass == 0 ? 1 : 2; break;

                    case nameof(ServerConfigJson.IsAudioEnabled):                           expected = json.IsAudioEnabled = pass == 0; break;

                    case nameof(ServerConfigJson.IsLocalAddress):                           expected = json.IsLocalAddress = pass == 0; break;

                    case nameof(ServerConfigJson.IsMono):                                   expected = json.IsMono = pass == 0; break;

                    case nameof(ServerConfigJson.MinimumRefreshSeconds):                    expected = json.MinimumRefreshSeconds = pass == 0 ? 1 : 2; break;

                    case nameof(ServerConfigJson.RefreshSeconds):                           expected = json.RefreshSeconds = pass == 0 ? 1 : 2; break;

                    case nameof(ServerConfigJson.UseMarkerLabels):                          expected = json.UseMarkerLabels = pass == 0; break;

                    case nameof(ServerConfigJson.UseSvgGraphics):                           expected = json.UseSvgGraphics = pass == 0; break;

                    case nameof(ServerConfigJson.VrsVersion):                               expected = json.VrsVersion = pass == 0 ? "A" : "B"; break;

                    case nameof(ServerConfigJson.Receivers):
                        json.Receivers.Add(new ServerReceiverJson()
                        {
                            UniqueId = pass == 0 ? 1 : 2,
                            Name     = pass == 0 ? "First" : "Second",
                        });
                        break;

                    default:
                        throw new NotImplementedException(property.Name);
                    }

                    var actual = (ServerConfigJson)json.Clone();

                    if (property.Name != nameof(ServerConfigJson.Receivers))
                    {
                        var actualValue = property.GetValue(actual, null);
                        Assert.AreEqual(expected, actualValue, "for property {0}", property.Name);
                    }
                    else
                    {
                        Assert.AreEqual(json.Receivers.Count, actual.Receivers.Count);
                        Assert.AreNotSame(json.Receivers[0], actual.Receivers[0]);
                        Assert.AreEqual(json.Receivers[0].UniqueId, actual.Receivers[0].UniqueId);
                        Assert.AreEqual(json.Receivers[0].Name, actual.Receivers[0].Name);
                    }
                }
            }
        }