Esempio n. 1
0
        public ActionResult Post([FromBody] FlightPlan flightPlan)
        {
            if (!CheckObjects.CheckFlightPlan(flightPlan))
            {
                return(BadRequest());
            }
            string idOfAddedFlightPlan = flightPlanManager.AddFlightPlan(flightPlan);

            return(CreatedAtAction(actionName: "GetFlightPlan",
                                   new { id = idOfAddedFlightPlan }, flightPlan));
        }
Esempio n. 2
0
        // Function that returns FlightPlan according to the given id.
        public async Task <FlightPlan> GetFlightPlanById(string id)
        {
            // Take the line from FlightPlanSQL which the Id equals to id.
            object[] lineFlightPlanSQL = GetLineInformationFromSQLWithCommand(
                "SELECT * FROM FlightPlanSQL WHERE Id=\"" + id + "\"");
            // If this id is not exist then return null. Otherwise, set a FlightPlan.
            if (lineFlightPlanSQL != null)
            {
                return(SetFlightPlanByListObjects(lineFlightPlanSQL, id));
            }
            List <Server> listOfExternalServers = GetExternalServers();

            if (listOfExternalServers == null)
            {
                return(null);
            }
            int i = 0;

            for (; i < listOfExternalServers.Count; ++i)
            {
                mutexOfFlightsFromServer.WaitOne();
                object[] idFlightFromExternalServer = GetLineInformationFromSQLWithCommand(
                    "SELECT IdFlight FROM FlightsFromExternalServersSQL WHERE IdFlight=\"" +
                    id + "\"");
                mutexOfFlightsFromServer.ReleaseMutex();
                if (idFlightFromExternalServer == null)
                {
                    continue;
                }
                string url = GetUrlWithoutSlashInTheEnd(listOfExternalServers[i].ServerURL);
                url += "/api/FlightPlan/" + id;
                FlightPlan flightPlanFromExternalServer =
                    await GetGenericFromAnotherServer <FlightPlan>(url);

                if (!CheckObjects.CheckFlightPlan(flightPlanFromExternalServer))
                {
                    continue;
                }
                if (flightPlanFromExternalServer != null)
                {
                    return(flightPlanFromExternalServer);
                }
            }
            return(null);
        }
Esempio n. 3
0
        // Adding flightPlan to our SQL tables, and returns the id.
        public string AddFlightPlan(FlightPlan flightPlan)
        {
            // Check if the givven flightplan is proper.
            if (!CheckObjects.CheckFlightPlan(flightPlan))
            {
                return(null);
            }
            OpenConnection();
            // Random id.
            string id = SetRandId();
            bool   succeedToAddToFlightPlanSQL, succeedToAddToSegmentSQL;
            bool   succeedToAddToInitialLocationSQL;

            // Check if add to FlightPlanSQL table succeed.
            succeedToAddToFlightPlanSQL = AddToFlightPlanTable(flightPlan, id);
            if (!succeedToAddToFlightPlanSQL)
            {
                CloseConnection();
                return(null);
            }
            // Check if add to InitialLocationSQL table succeed.
            succeedToAddToInitialLocationSQL = AddToInitialLocationTable(flightPlan, id);
            if (!succeedToAddToInitialLocationSQL)
            {
                CloseConnection();
                return(null);
            }
            // Check if add to SegmentSQL table succeed.
            succeedToAddToSegmentSQL = AddListToSegmentTable(flightPlan.Segments, id);
            if (!succeedToAddToSegmentSQL)
            {
                CloseConnection();
                return(null);
            }
            CloseConnection();
            return(id);
        }