예제 #1
0
        /// <summary>
        /// New departure/arrival planed
        /// </summary>
        /// <param name="plane">The new plane</param>
        private async void DepartureOrArrival(Common.Plane plane)
        {
            await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
            {
                FutureFlights.Add(new Models.Plane(plane.Name, plane.ActionDate, plane.waitingTime, plane.flightState));
                var sortedFlights = FutureFlights.OrderBy(f => f.ActionDate).ToList();
                FutureFlights.Clear();

                foreach (var flight in sortedFlights)
                {
                    FutureFlights.Add(flight);
                }
            });
        }
예제 #2
0
        /// <summary>
        /// Plane is moving
        /// </summary>
        /// <param name="plane"></param>
        private async void Moved(Common.Plane plane)
        {
            await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
            {
                //If it's not his last station
                if (plane.StationNumber != 0)
                {
                    var pl = Planes.Where(p => p.Name == plane.Name).FirstOrDefault();
                    if (pl == null)
                    {
                        Planes.Add(new Models.Plane(plane.Name, plane.ActionDate, plane.waitingTime, plane.flightState)
                        {
                            StationNumber = plane.StationNumber
                        });
                    }
                    else
                    {
                        pl.StationNumber = plane.StationNumber;
                    }
                }
                else
                {
                    Planes.Remove(Planes.Where(p => p.Name == plane.Name).First());
                }


                var previous = Stations.Where(s => s.Number == plane.PreviousStationNumber).FirstOrDefault();
                if (previous != null && previous.Plane != null)
                {
                    previous.Plane = null;
                }

                var nextstation = Stations.Where(s => s.Number == plane.StationNumber).FirstOrDefault();
                if (nextstation != null)
                {
                    nextstation.Plane = plane.Name;
                }

                //if it's his first station
                if (plane.PreviousStationNumber == 0)
                {
                    var flight = FutureFlights.Where(f => f.Name == plane.Name).FirstOrDefault();
                    if (flight != null)
                    {
                        FutureFlights.Remove(flight);
                    }
                }
            });
        }
예제 #3
0
        /// <summary>
        /// A plane is moving
        /// </summary>
        /// <param name="Plane">The plane that moves</param>
        public void MoveRequest(Common.Plane Plane)
        {
            using (AirportDataModel context = new AirportDataModel())
            {
                Station previous = null;
                //If it's not his first station
                if (Plane.PreviousStationNumber != 0)
                {
                    previous = context.Stations.Where(s => s.Number == Plane.PreviousStationNumber).FirstOrDefault();

                    if (previous != null)
                    {
                        previous.PlaneId = null;
                        previous.Plane   = null;
                        context.Histories.Add(new History()
                        {
                            StationNumber = previous.Number, DateOut = DateTime.Now, DateIn = null, PlaneId = Plane.Name
                        });
                    }
                }

                var next = context.Stations.Where(s => s.Number == Plane.StationNumber).FirstOrDefault();

                if (next != null)
                {
                    DAL.Plane DalPlane = context.Planes.Where(p => p.Name == Plane.Name).FirstOrDefault();
                    if (DalPlane == null)
                    {
                        DalPlane = new Plane()
                        {
                            Name = Plane.Name, ActionDate = Plane.ActionDate, flightState = Plane.flightState, PreviousStationNumber = Plane.PreviousStationNumber, StationNumber = Plane.StationNumber, waitingTime = Plane.waitingTime
                        };
                        context.Planes.Add(DalPlane);
                    }

                    DalPlane.PreviousStationNumber = Plane.StationNumber;
                    DalPlane.StationNumber         = Plane.StationNumber;

                    next.PlaneId = DalPlane.Id;
                    next.Plane   = DalPlane;
                    context.Histories.Add(new History()
                    {
                        StationNumber = next.Number, DateIn = DateTime.Now, DateOut = null, PlaneId = Plane.Name
                    });
                }

                context.SaveChanges();
            }
        }
예제 #4
0
        protected override void ApplyImpl(Common.Plane plane)
        {
            RocketGun gun = RocketGun.CreateDefault();

            gun.Info = "Homing rockets gun";

            // ToDo: Make flexible mechanism to give the plane possibility manage new equipments relative info
            // so concrete plane instance should decide where new equipment should be placed

            // but now only weird workaround to XWingPlane only
            plane.AddEquipment(gun, new PlaneWeaponRelativeInfo()
            {
                RelativeToOriginPosition = new Vector(0, 6),
                WeaponPosition           = WeaponPosition.CenterFront
            });
        }
예제 #5
0
        /// <summary>
        /// New future departure or arrival to add
        /// </summary>
        /// <param name="plane">The new plane</param>
        public void DepartureOrArrival(Common.Plane plane)
        {
            using (AirportDataModel context = new AirportDataModel())
            {
                if (plane.flightState == Common.Enums.FlightState.Departure)
                {
                    context.Departures.Add(new Departure()
                    {
                        PlaneId = plane.Name, DatePlanned = plane.ActionDate, waitingTime = plane.waitingTime
                    });
                }
                else
                {
                    context.Arrivals.Add(new Arrival()
                    {
                        PlaneId = plane.Name, DatePlanned = plane.ActionDate, waitingTime = plane.waitingTime
                    });
                }

                context.SaveChanges();
            }
        }
예제 #6
0
 protected override void ApplyImpl(Common.Plane plane)
 {
     throw new NotImplementedException();
 }