Beispiel #1
0
        // This method uses the Telnet class to pull down a specific celestial body from NASA's Horizons server based on NASA's unique object ID system.
        // It then adds the SolarObject object to the database, as a new record in both the InitialValues and the Object tables.
        public static bool AddObject(int nasaID)
        {
            var t   = new Telnet().Run(nasaID);
            var cmd = new SQLiteCommand($"SELECT count(*) FROM Object;", DBConnection);

            int countObjectView = Convert.ToInt32(cmd.ExecuteScalar());

            string addString = $"insert into Object (ObjectID, Name, Mass, Radius, Obliquity, OrbitalSpeed) " +
                               $"values('{countObjectView}', '{t.Name}', '{t.Mass}', '{t.Radius}', 0, 0);";

            var add = new SQLiteCommand(addString, DBConnection);

            add.ExecuteNonQuery();
            var    position            = t.GetPosition();
            var    velocity            = t.GetVelocity();
            string addinitvaluesString = $"insert into InitialValues (ObjectID, PlanetarySystemID, PositionX, PositionY, PositionZ, " +
                                         $"VelocityX, VelocityY, VelocityZ) values('{countObjectView}', '0', '{position.X}', '{position.Y}', '{position.Z}', '{velocity.X}', '{velocity.Y}', '{velocity.Z}');";

            var addinitValues = new SQLiteCommand(addinitvaluesString, DBConnection);

            addinitValues.ExecuteNonQuery();

            return(true);
        }