public void PolarPlotsJson_ToModel_Converts_Values_From_PolarPlotter()
        {
            var slices       = new List <PolarPlotSlice>();
            var polarPlotter = TestUtilities.CreateMockInstance <IPolarPlotter>();

            polarPlotter.Setup(r => r.TakeSnapshot()).Returns(slices);

            slices.Add(new PolarPlotSlice()
            {
                AltitudeLower  = 111,
                AltitudeHigher = 222,
                PolarPlots     =
                {
                    { 7, new PolarPlot()
                        {
                            Angle = 7, Altitude = 150, Distance = 4, Latitude = 5, Longitude = 6,
                        } }
                }
            });

            var model = PolarPlotsJson.ToModel(44, polarPlotter.Object);

            Assert.AreEqual(44, model.FeedId);
            Assert.AreEqual(1, model.Slices.Count);
            Assert.AreEqual(111, model.Slices[0].StartAltitude);
            Assert.AreEqual(222, model.Slices[0].FinishAltitude);
            Assert.AreEqual(1, model.Slices[0].Plots.Count);
            Assert.AreEqual(5F, model.Slices[0].Plots[0].Latitude);
            Assert.AreEqual(6F, model.Slices[0].Plots[0].Longitude);
        }
Exemple #2
0
        protected override bool DoHandleRequest(IWebServer server, RequestReceivedEventArgs args)
        {
            var result = false;

            if (args.PathAndFile.Equals("/PolarPlot.json", StringComparison.OrdinalIgnoreCase))
            {
                result = true;

                var allowRequest = _InternetClientCanShowPolarPlot || !args.IsInternetRequest;
                var feedId       = allowRequest ? QueryInt(args, "feedId", -1) : -1;
                var json         = new PolarPlotsJson()
                {
                    FeedId = feedId,
                };

                if (allowRequest)
                {
                    var feed         = _FeedManager.GetByUniqueId(feedId, ignoreInvisibleFeeds: true);
                    var polarPlotter = feed == null || feed.AircraftList == null ? null : feed.AircraftList.PolarPlotter;
                    if (polarPlotter != null)
                    {
                        foreach (var slice in polarPlotter.TakeSnapshot())
                        {
                            var jsonSlice = new PolarPlotsSliceJson()
                            {
                                StartAltitude  = slice.AltitudeLower,
                                FinishAltitude = slice.AltitudeHigher,
                            };
                            json.Slices.Add(jsonSlice);

                            foreach (var kvp in slice.PolarPlots.OrderBy(r => r.Key))
                            {
                                var plot = kvp.Value;
                                jsonSlice.Plots.Add(new PolarPlotJson()
                                {
                                    Latitude  = (float)plot.Latitude,
                                    Longitude = (float)plot.Longitude,
                                });
                            }
                        }
                    }
                }

                Responder.SendJson(args.Request, args.Response, json, null, null);
            }

            return(result);
        }
Exemple #3
0
        [Route("PolarPlot.json")]                       // pre-version 3 route
        public PolarPlotsJson GetPolarPlot(int feedId = -1)
        {
            var feedManager = Factory.ResolveSingleton<IFeedManager>();
            var feed = feedManager.GetByUniqueId(feedId, ignoreInvisibleFeeds: true);
            var plotter = feed?.AircraftList?.PolarPlotter;

            if(plotter != null && PipelineRequest.IsInternet) {
                var configuration = Factory.ResolveSingleton<ISharedConfiguration>().Get();
                if(!configuration.InternetClientSettings.CanShowPolarPlots) {
                    plotter = null;
                }
            }

            var result = plotter != null ? PolarPlotsJson.ToModel(feed.UniqueId, plotter) : new PolarPlotsJson() { FeedId = feedId, };

            return result;
        }
 public void PolarPlotsJson_ToModel_Returns_Null_If_Passed_Null()
 {
     Assert.IsNull(PolarPlotsJson.ToModel(1, null));
 }
 public void TestInitialise()
 {
     _Json = new PolarPlotsJson();
 }