示例#1
0
        public static async Task <PlanetRaw> getPlanet(string name)
        {
            System.Diagnostics.Debug.WriteLine("\n\n\n--" + name + "--\n\n\n");
            var client = new HttpClient();

            client.BaseAddress = new Uri("https://wgc2.jpl.nasa.gov:8443");

            DateTime UtcNow = DateTime.UtcNow;
            String   time   = UtcNow.Year + "-" + UtcNow.Month + "-" + UtcNow.Day + " " + UtcNow.Hour + ":" + UtcNow.Minute + ":" + UtcNow.Second + ".000000 UTC";

            string jsonData =
                @"{
                ""calculationType"": ""STATE_VECTOR"",
                ""kernels"": 
                [
                    {
                            ""type"": ""KERNEL_SET"",
                            ""id"": 1
                    }
                ],
                ""timeSystem"": ""UTC"",
                ""timeFormat"": ""CALENDAR"",
                ""intervals"": 
                [
                    {
                        ""startTime"": """ + time + @""",
                        ""endTime"": """ + time + @"""
                    }
                ],
                ""timeStep"": 30,
                ""timeStepUnits"": ""MINUTES"",
                ""targetType"": ""OBJECT"",
                ""target"": """ + name + @""",
                ""observerType"": ""OBJECT"",
                ""observer"": ""EARTH"",
                ""referenceFrame"": ""J2000"",
                ""aberrationCorrection"": ""NONE"",
                ""stateRepresentation"": ""RA_DEC""
            }";


            //richiesta POST del nuovo calcolo
            var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync("https://wgc2.jpl.nasa.gov:8443/webgeocalc/api/calculation/new", content);

            var result = await response.Content.ReadAsStringAsync();

            Results results = JsonConvert.DeserializeObject <Results>(result);

            //richiesta GET per il risultato del calcolo
            response = await client.GetAsync("https://wgc2.jpl.nasa.gov:8443/webgeocalc/api/calculation/" + results.calculationId + "/results");

            result = await response.Content.ReadAsStringAsync();

            PlanetRaw pr = JsonConvert.DeserializeObject <PlanetRaw>(result);


            return(pr);
        }
示例#2
0
        public Planet(string name, PlanetRaw pr)
        {
            this.name     = name;
            coord         = new Point(0, 0);
            RA            = (float)toDouble(pr.rows[0][1]);
            DEC           = (float)toDouble(pr.rows[0][2]);
            distanceKm    = (float)toDouble(pr.rows[0][3]);
            distanceLight = (float)toDouble(pr.rows[0][9]);

            dist2D = (float)(Math.Abs(Math.Cos(DEC / 180 * Math.PI)) * distanceKm);

            loadString();
            uselessDataBase.setUselessData(this);
        }
示例#3
0
        public async void loadStuff()
        {
            //carico i pianeti
            for (int i = 0; i < planetNames.Length; i++)
            {
                if (planetNames[i].Equals("earth"))   //se c'è la terra la metto vuota nell'array
                {
                    planets2D.Add(new Planet(planetNames[i], 0, 0, 0, 0));
                    planets3D.Add(new Planet(planetNames[i], 0, 0, 0, 0));
                    planetsSun.Add(new Planet(planetNames[i], 0, 0, 0, 0));
                    continue;
                }
                loadingLabel.Text = planetNames[i][0].ToString().ToUpper() + planetNames[i].Substring(1) + "...";
                loadingPercentage = ((float)i + 1) / planetNames.Length * 0.7f;
                await Task.Run(() =>
                {
                    PlanetRaw pr = Request.getPlanet(planetNames[i]).Result;
                    planets2D.Add(new Planet(planetNames[i], pr));
                    planets3D.Add(new Planet(planetNames[i], pr));
                    planetsSun.Add(new Planet(planetNames[i], pr));
                });
            }

            loadingPercentage = ((float)planetNames.Length + 2) / planetNames.Length * 0.7f;
            loadingLabel.Text = "Geolocation" + "...";
            //carico la geolocalizzazione
            try
            {
                var req = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(10));
                location = await Geolocation.GetLocationAsync(req);

                loadingPercentage = 1;
                //passo alla pagina con il menu
                await Navigation.PushModalAsync(new MainPage(planets2D, planets3D, planetsSun, location));
            }
            catch {
                await Navigation.PushModalAsync(new MainPage(planets2D, planets3D, planetsSun, null));
            }
        }