Example #1
0
        public async Task <IEnumerable <AstroObject> > GetObjectsInRegion(EquitorialCoords minCoords, EquitorialCoords maxCoords)
        {
            // If max coords wrap around 360degrees and are less than min coords,
            // extend them above 360
            bool extendRA          = minCoords.RightAscension > maxCoords.RightAscension;
            bool extendDec         = minCoords.Declination > maxCoords.Declination;
            var  extendedMaxCoords = maxCoords with
            {
                RightAscension = maxCoords.RightAscension + (extendRA ? 360d : 0d),
                Declination    = maxCoords.Declination + (extendDec ? 360d : 0d)
            };

            // Fetch objects
            var json = JsonSerializer.Serialize(
                new GetInRegionBody(minCoords, extendedMaxCoords),
                new JsonSerializerOptions
            {
                WriteIndented = true,
                PropertyNameCaseInsensitive = true,
            });
            var res = await _httpClient.PostAsync("getinregion", new StringContent(
                                                      json, Encoding.UTF8, "application/json"));

            res.EnsureSuccessStatusCode();

            return(await ReadHttpContent <IEnumerable <AstroObject> >(res.Content));
        }
Example #2
0
 private record GetInRegionBody(EquitorialCoords minCoords, EquitorialCoords maxCoords);