Beispiel #1
0
 public void HandlePositions(List <Aircraft> aircrafts)
 {
     do
     {
         foreach (Aircraft aircraft in aircrafts)
         {
             if (aircraft.IsActive)
             {
                 System.Console.WriteLine("Handling position for " + aircraft.CarrierName + " flight " + aircraft.FlightNumber);
                 var position = _positionRepository.Search(e => e.AircraftId == aircraft.Id, 0, 1).FirstOrDefault();
                 if (position == null)
                 {
                     //No position yet exists for this aircraft and we need to create a new one
                     position            = new Position();
                     position.AircraftId = aircraft.Id;
                     //Call api for flight
                     if (UpdateFlightInformation(aircraft, position))
                     {
                         //Create position in database
                         position = _positionRepository.Create(position);
                         //Calculate the positions bounds
                         HandleBoundingBox.CalculateBoundingBox(position);
                         //Update position object in database
                         position = _positionRepository.Update(position.Id, position);
                         //Call HandleCollisions to start evaluating this position for potential collisions
                         HandleCollision(aircraft, position);
                     }
                     else
                     {
                         //There was an error from the API
                     }
                 }
                 else
                 {
                     //We found a position and need to update position from api and recalculate boundingbox
                     if (UpdateFlightInformation(aircraft, position))
                     {
                         //Calculate the positions bounds
                         HandleBoundingBox.CalculateBoundingBox(position);
                         //Update position object in database
                         position = _positionRepository.Update(position.Id, position);
                         //Call HandleCollisions to start evaluating this position for potential collisions
                         HandleCollision(aircraft, position);
                     }
                     else
                     {
                         //There was an error from the API
                     }
                 }
             }
             else
             {
                 System.Console.WriteLine("Handling inactive aircraft " + aircraft.CarrierName + " flight " + aircraft.FlightNumber);
                 HandleInActiveAircraft(aircraft);
             }
         }
         Thread.Sleep(10000);
     } while (true);
 }
Beispiel #2
0
        public async Task <PositionDto> CreateAsync(PositionDto entity)
        {
            if (entity != null)
            {
                if (entity.Grade >= 1 && entity.Grade <= 15)
                {
                    if (!string.IsNullOrEmpty(entity.Title))
                    {
                        Position position = mapper.Map <Position>(entity);
                        position = await positionRepository.Create(position);

                        return(mapper.Map <PositionDto>(position));
                    }
                }
            }
            return(null);
        }
Beispiel #3
0
 public ActionResult <Position> Post([FromBody] Position position)
 {
     try
     {
         position.PositionID = Guid.NewGuid();
         positionRepo.Create(position);
         return(CreatedAtRoute("GetPositionByID",
                               new
         {
             id = position.PositionID
         },
                               position));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Beispiel #4
0
        public async Task <IActionResult> Post([FromBody] Position position)
        {
            await _repo.Create(position);

            return(new OkObjectResult(position));
        }
Beispiel #5
0
 public void Create(Position position)
 {
     positionRepository.Create(position);
 }