Ejemplo n.º 1
0
        public async Task <ActionResult <FlightPlan> > AddFlightPlan(FlightPlanDto flightPlanDto)
        {
            string flightId   = CreateId(flightPlanDto.CompanyName);
            var    flightPlan = new FlightPlan
            {
                FlightId        = flightId,
                Passengers      = flightPlanDto.Passengers,
                CompanyName     = flightPlanDto.CompanyName,
                InitialLocation = new InitialLocation
                {
                    Id        = flightId,
                    Longitude = flightPlanDto.InitialLocation.Longitude,
                    Latitude  = flightPlanDto.InitialLocation.Latitude,
                    DateTime  = flightPlanDto.InitialLocation.DateTime
                }
            };

            FromSegmentsDtoToSegments(flightPlanDto.Segments, flightPlan.Segments, flightId);

            await _context.FlightsPlans.AddAsync(flightPlan);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(flightPlan);
        }
        protected static FlightPlan FromDto(FlightPlanDto flightPlanDto)
        {
            List <Segment> segments = new List <Segment>();

            foreach (SegmentDto s in flightPlanDto.Segments)
            {
                segments.Add(new Segment
                {
                    Id              = 1,
                    Longitude       = s.Longitude,
                    Latitude        = s.Latitude,
                    TimeSpanSeconds = s.TimeSpanSeconds,
                    FlightId        = "AA00000"
                });
            }
            return(new FlightPlan
            {
                FlightId = "AA00000",
                Passengers = flightPlanDto.Passengers,
                CompanyName = flightPlanDto.CompanyName,
                InitialLocation = new InitialLocation
                {
                    Id = "AA00000",
                    Longitude = flightPlanDto.InitialLocation.Longitude,
                    Latitude = flightPlanDto.InitialLocation.Latitude,
                    DateTime = flightPlanDto.InitialLocation.DateTime
                },
                Segments = segments,
            });
        }
        public async Task PostInValidFlightPlanReturnStatusCode()
        {
            //arrange
            FlightPlanDto flightPlanDto = FlightPlanGenerator.testFlightPlan;

            flightPlanDto.InitialLocation.Latitude = 200;
            var flightPlanController = new FlightPlanController(new Mock <IRepository>().Object);
            //act
            var result = await flightPlanController.PostFlightPlan(flightPlanDto);

            //assert
            Assert.AreEqual(StatusCodes.Status400BadRequest, ((ContentResult)result.Result).StatusCode);
        }
        public async Task PostFlightPlanFailedReturnStatusCode()
        {
            //arrange
            var           repositoryMock = new Mock <IRepository>();
            FlightPlanDto flightPlanDto  = null;

            repositoryMock.Setup(r => r.AddFlightPlan(null)).Throws(new System.Exception());
            var flightPlanController = new FlightPlanController(repositoryMock.Object);
            //act
            var result = await flightPlanController.PostFlightPlan(flightPlanDto);

            //assert
            Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ContentResult)result.Result).StatusCode);
        }
        public async Task PostFlightPlanSucceedsReturnFlightPlanDto()
        {
            //arrange
            var           repositoryMock = new Mock <IRepository>();
            FlightPlanDto flightPlanDto  = FlightPlanGenerator.testFlightPlan;
            var           flightPlan     = FromDto(flightPlanDto);

            repositoryMock.Setup(r => r.AddFlightPlan(flightPlanDto)).ReturnsAsync(flightPlan);
            var flightPlanController = new FlightPlanController(repositoryMock.Object);
            //act
            var result = await flightPlanController.PostFlightPlan(flightPlanDto);

            //assert
            Assert.AreEqual(flightPlanDto, ((CreatedAtActionResult)result.Result).Value);
        }
Ejemplo n.º 6
0
 private static FlightPlan FillFlightPlanFromDto(FlightPlanDto dto)
 {
     return(new FlightPlan
     {
         FlightRules = dto.Type,
         Aircraft = dto.Aircraft,
         AircraftFaa = AircraftFaa(dto.Aircraft),
         AircraftShort = AircraftShort(dto.Aircraft),
         Departure = dto.DepartureAirport,
         Arrival = dto.DestinationAirport,
         Alternate = dto.AlternateAirport,
         CruiseTas = dto.CruiseSpeed,
         Altitude = dto.Altitude,
         Deptime = int.Parse(dto.EstimatedDepartureTime).ToString("0000"),
         EnrouteTime = FormatFsdTime(dto.HoursEnroute, dto.MinutesEnroute),
         FuelTime = FormatFsdTime(dto.HoursFuel, dto.MinutesFuel),
         Remarks = dto.Remarks.ToUpper(),
         Route = dto.Route.ToUpper()
     });
 }
Ejemplo n.º 7
0
        private async Task <ActionResult <FlightPlanDto> > GetInternalFlightPlan(string id)
        {
            var flightPlan = await _context.FlightsPlans.FindAsync(id);

            var initialLocation = await _context.InitialLocation.FindAsync(id);

            var segments      = _context.Segments.Where(s => s.FlightId == id).ToList();
            var flightPlanDto = new FlightPlanDto
            {
                Passengers      = flightPlan.Passengers,
                CompanyName     = flightPlan.CompanyName,
                InitialLocation = new InitialLocationDto
                {
                    Longitude = initialLocation.Longitude,
                    Latitude  = initialLocation.Latitude,
                    DateTime  = initialLocation.DateTime
                }
            };

            FromSegmentsToSegmentsDto(segments, flightPlanDto.Segments);

            return(flightPlanDto);
        }
 private bool IsValid(FlightPlanDto flightPlanDto)
 {
     //check for null values in flightPlanDto entities
     if (flightPlanDto.CompanyName == null || flightPlanDto.InitialLocation == null ||
         flightPlanDto.Segments == null)
     {
         return(false);
     }
     //check for out of range values
     if (flightPlanDto.InitialLocation.Longitude > 180 || flightPlanDto.InitialLocation.Longitude < -180 ||
         flightPlanDto.InitialLocation.Latitude > 90 || flightPlanDto.InitialLocation.Latitude < -90)
     {
         return(false);
     }
     foreach (SegmentDto s in flightPlanDto.Segments)
     {
         if (s.Longitude > 180 || s.Longitude < -180 ||
             s.Latitude > 90 || s.Latitude < -90)
         {
             return(false);
         }
     }
     return(true);
 }
        public async Task <ActionResult <FlightPlanDto> > PostFlightPlan([FromBody] FlightPlanDto flightPlanDto)
        {
            var result = new ContentResult();

            try
            {
                if (!(IsValid(flightPlanDto)))
                {
                    result.StatusCode = 400;
                    result.Content    = "flight plan is invalid";
                }
                else
                {
                    var flightPlan = await _context.AddFlightPlan(flightPlanDto);

                    return(CreatedAtAction("GetFlightPlan", new { id = flightPlan.Value.FlightId }, flightPlanDto));
                }
            }
            catch
            {
                result.StatusCode = 500;
            }
            return(result);
        }
Ejemplo n.º 10
0
        private void client_DelimiterDataReceived(object sender, Message packet)
        {
            try
            {
                string[] fields = packet.MessageString.Replace("\r", "").Split(":");
                switch (fields[0])
                {
                case "ADDCLIENT":
                    AddClientDto addClientDto = AddClientDto.Deserialize(fields);
                    OnAddClientDtoReceived(new DtoReceivedEventArgs <AddClientDto>(addClientDto));
                    break;

                case "RMCLIENT":
                    RemoveClientDto removeClientDto = RemoveClientDto.Deserialize(fields);
                    OnRemoveClientDtoReceived(new DtoReceivedEventArgs <RemoveClientDto>(removeClientDto));
                    break;

                case "PD":
                    PilotDataDto pilotDataDto = PilotDataDto.Deserialize(fields);
                    OnPilotDataDtoReceived(new DtoReceivedEventArgs <PilotDataDto>(pilotDataDto));
                    break;

                case "AD":
                    AtcDataDto atcDataDto = AtcDataDto.Deserialize(fields);
                    OnAtcDataDtoReceived(new DtoReceivedEventArgs <AtcDataDto>(atcDataDto));
                    break;

                case "PLAN":
                    FlightPlanDto flightPlanDto = FlightPlanDto.Deserialize(fields);
                    OnFlightPlanDtoReceived(new DtoReceivedEventArgs <FlightPlanDto>(flightPlanDto));
                    break;

                case "PING":
                    PingDto pingDto = PingDto.Deserialize(fields);
                    OnPingDtoReceived(new DtoReceivedEventArgs <PingDto>(pingDto));
                    break;

                case "MC":
                    if (fields[5] == "25")
                    {
                        AtisDataDto atisDataDto = AtisDataDto.Deserialize(fields);
                        OnAtisDataDtoReceived(new DtoReceivedEventArgs <AtisDataDto>(atisDataDto));
                    }

                    break;

                case "NOTIFY":
                    NotifyDto notifyDto = NotifyDto.Deserialize(fields);
                    OnNotifyDtoReceived(new DtoReceivedEventArgs <NotifyDto>(notifyDto));
                    break;

                default:
                    // Not a DTO we need to handle...
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 11
0
        private void Client_DelimiterDataReceived(object sender, Message packet)
        {
            try
            {
                string[] fields = packet.MessageString.Replace("\r", "").Split(":", 2);
                switch (fields[0])
                {
                case AddClientDto.Packet:
                    AddClientDto addClientDto = AddClientDto.Deserialize(fields[1]);
                    OnAddClientDtoReceived(new DtoReceivedEventArgs <AddClientDto>(addClientDto));
                    break;

                case RemoveClientDto.Packet:
                    RemoveClientDto removeClientDto = RemoveClientDto.Deserialize(fields[1]);
                    OnRemoveClientDtoReceived(new DtoReceivedEventArgs <RemoveClientDto>(removeClientDto));
                    break;

                case PilotDataDto.Packet:
                    PilotDataDto pilotDataDto = PilotDataDto.Deserialize(fields[1]);
                    OnPilotDataDtoReceived(new DtoReceivedEventArgs <PilotDataDto>(pilotDataDto));
                    break;

                case AtcDataDto.Packet:
                    AtcDataDto atcDataDto = AtcDataDto.Deserialize(fields[1]);
                    OnAtcDataDtoReceived(new DtoReceivedEventArgs <AtcDataDto>(atcDataDto));
                    break;

                case FlightPlanDto.Packet:
                    FlightPlanDto flightPlanDto = FlightPlanDto.Deserialize(fields[1]);
                    OnFlightPlanDtoReceived(new DtoReceivedEventArgs <FlightPlanDto>(flightPlanDto));
                    break;

                case PingDto.Packet:
                    PingDto pingDto = PingDto.Deserialize(fields[1]);
                    OnPingDtoReceived(new DtoReceivedEventArgs <PingDto>(pingDto));
                    break;

                case FlightPlanCancelDto.Packet:
                    FlightPlanCancelDto flighplanCancelDto = FlightPlanCancelDto.Deserialize(fields[1]);
                    OnFlightPlanCancelDtoReceived(new DtoReceivedEventArgs <FlightPlanCancelDto>(flighplanCancelDto));
                    break;

                case NotifyDto.Packet:
                    NotifyDto notifyDto = NotifyDto.Deserialize(fields[1]);
                    OnNotifyDtoReceived(new DtoReceivedEventArgs <NotifyDto>(notifyDto));
                    break;

                case "MC":
                    fields = packet.MessageString.Replace("\r", "").Split(":");
                    switch (fields[5])
                    {
                    case "25":
                    {
                        AtisDataDto atisDataDto = AtisDataDto.Deserialize(fields);
                        OnAtisDataDtoReceived(new DtoReceivedEventArgs <AtisDataDto>(atisDataDto));
                        break;
                    }

                    case "5" when fields[1] == "*S":
                    {
                        WallopDto wallopDto = WallopDto.Deserialize(fields);
                        OnWallopDtoReceived(new DtoReceivedEventArgs <WallopDto>(wallopDto));
                        break;
                    }

                    case "5" when fields[1] == "*":