Пример #1
0
        /// <summary>
        /// Get a flight plan from the database and return it.
        /// </summary>
        /// <param name="id"> The id of the flight plan. </param>
        /// <returns> The flight plan. </returns>
        public async Task <FlightPlan> GetFlightPlan(string id)
        {
            // Try get the flight plan from the local data base.
            FlightPlan local = await flightsDB.GetFlightPlan(id);

            if (local != null)
            {
                return(local);
            }

            /* If flight plan not in local data base, try to retrieve it from an
             * external server.
             * Get the server in which the flight plan is located. */
            FlightServer relevantServer = await flightsServersDB.GetFlightServer(id);

            if (relevantServer != null)
            {
                // Ask the external server for the flight plan.
                Server server = await serversDB.GetServer(relevantServer.ServerId);

                IHTTPClient client = new HTTPClient(server);

                return(await client.GetFlightPlan(id));
            }

            return(null);
        }
Пример #2
0
        public async Task AddFlightServer(FlightServer fs)
        {
            FlightServer exists = await this.GetFlightServer(fs.FlightId);

            if (exists != null)
            {
                return;
            }

            // Opening the connection
            using SQLiteConnection con = new SQLiteConnection(connectionString);
            await con.OpenAsync();

            // Creating the query to insert
            using var command = new SQLiteCommand(
                      "INSERT into FlightsServers (flightid, serverid) VALUES (@FId, @SId)", con);
            // Inserting the parameters with value
            command.Parameters.AddWithValue("@FId", fs.FlightId);
            command.Parameters.AddWithValue("@SId", fs.ServerId);
            try
            {
                // Writing that to DB
                var res = await command.ExecuteNonQueryAsync();

                // Failed
                if (res == 0)
                {
                    throw new ArgumentException("Failed post serverflight.");
                }
            }
            // The id is already there so failed
            catch (Exception)
            {
                throw new ArgumentException("Serverflight already in data base.");
            }
        }
Пример #3
0
        public async IAsyncEnumerable <FlightServer> GetServerIterator(string serverid)
        {
            // Opening the connection
            using SQLiteConnection con = new SQLiteConnection(connectionString);
            await con.OpenAsync();

            // Get all the flightservers with that serverid
            using var command = new SQLiteCommand("SELECT * FROM FlightsServers WHERE serverid = '"
                                                  + serverid + "'", con);
            using SQLiteDataReader rdr = (SQLiteDataReader) await command.ExecuteReaderAsync();

            // Reading and returning them one by one
            while (await rdr.ReadAsync())
            {
                // Getting
                string fid = rdr.GetString(0);
                string sid = rdr.GetString(1);

                // Returning
                FlightServer fs = new FlightServer(fid, sid);
                yield return(fs);
            }
            yield break;
        }
 public FlightServerImplementation(FlightServer flightServer)
 {
     _flightServer = flightServer;
 }