protected virtual void OnFlightHappend(object sender, FlightEventArgs args)
 {
     LastFlightPassengersCount = args.FlightInfo.PassengerCount;
     TotalPassengersCount     += LastFlightPassengersCount;
     if (IsNewDay(args))
     {
         DayPassengersCount = LastFlightPassengersCount;
     }
     else
     {
         DayPassengersCount += LastFlightPassengersCount;
     }
     _lastFlightTime = args.FlightInfo.Time;
 }
示例#2
0
        private void OnFlightMoveEvent()
        {
            FlightEventArgs arg;

            if (IsLastStation)
            {
                arg = new FlightEventArgs(Flight, null);
            }
            else
            {
                arg = new FlightEventArgs(Flight, StationID);
            }
            _flightEvent.Invoke(arg);
        }
示例#3
0
        private void FlightHappend(Flight flight)
        {
            var flightInfo = new FlightInfo(flight)
            {
                PassengerCount = _random.Next(0, _planeCapacityProvider.GetPlaneCapacity(flight.PlaneType) + 1)
            };
            var eventArgs = new FlightEventArgs {
                FlightInfo = flightInfo
            };

            if (flight.FlightType == FlightType.Arrival)
            {
                OnPlaneArrived(eventArgs);
            }
            else
            {
                OnPlaneDepartured(eventArgs);
            }
        }
        private void FlightsProcessorOnApproachingBadWeather(object sender, FlightEventArgs e)
        {
            //throw new NotImplementedException();
            //TODO Send the data to interface
            switch (e.WarningLevel)
            {
            case WarningLevel.Normal:
                //DO nothing we will try to process this one
                break;

            case WarningLevel.High:
                RealTimeUpdateHub.InvokeGlobalMessageForBadWeather(e.Flights[0], e.WarningLevel);
                break;

            case WarningLevel.Critical:
                RealTimeUpdateHub.InvokeGlobalMessageForBadWeather(e.Flights[0], e.WarningLevel);
                break;

            default:
                RealTimeUpdateHub.InvokeGlobalMessageForBadWeather(e.Flights[0], e.WarningLevel);
                break;
            }
        }
        public void NotifyFlightChanges(FlightEventArgs e)
        {
            if (e is null)
            {
                throw new ArgumentNullException(nameof(e), "The event args are required");
            }
            Flight flight = e.Flight;

            FlightDTO  flightDto = FlightDTO.FromDBModel(flight);
            StationDTO fromDto = null, toDto = null;
            Station    from = e.StationFrom;

            if (from is not null)
            {
                fromDto = StationDTO.FromDBModel(from);
            }
            Station to = e.StationTo;

            if (to is not null)
            {
                toDto = StationDTO.FromDBModel(to);
            }
            hubContext.Clients.Group($"CT-{e.Flight.ControlTower.Name}").SendAsync("FlightMoved", flightDto, fromDto, toDto);
        }
示例#6
0
 private void OnFlightEnterEvent(FlightEventArgs args)
 {
     UpdateFlightsManager(args.Flight);
     //notify client
     //updating repository
 }
 public Task FlightMoved(FlightEventArgs flightEvent)
 {
     FlightEventFromNotification = flightEvent;
     return(null);
 }
        public async Task FlightMoved(FlightEventArgs flightEvent)
        {
            Flight  flight      = flightEvent.Flight;
            Station stationFrom = flightEvent.StationFrom;

            if (stationFrom is not null)
            {
                stationFrom.CurrentFlightId = null;
            }
            Station stationTo = flightEvent.StationTo;

            if (stationTo is not null)
            {
                stationTo.CurrentFlightId = flight.Id;
            }
            if (flightEvent.IsStationSelfInvoke)
            {
                return;
            }
            if (flightEvent.IsFromControlTowerToFirstStation)
            {
                OpenFlightHistoryRow(flight, flightEvent.StationTo);
            }
            else if (flightEvent.IsFromLastStationToEnd)
            {
                CloseFlighHistoryRow(flight, flightEvent.StationFrom);
            }
            else
            {
                CloseFlighHistoryRowAndOpenNewOne(flight, flightEvent.StationFrom, flightEvent.StationTo);
            }
            flight.StationId          = flightEvent.StationTo?.Id;
            using IServiceScope scope = serviceScopeFactory.CreateScope();
            try
            {
                IRepository <Flight>  flightRepo  = scope.ServiceProvider.GetRequiredService <IRepository <Flight> >();
                IRepository <Station> stationRepo = scope.ServiceProvider.GetRequiredService <IRepository <Station> >();
                List <Task>           tasks       = new() { flightRepo.UpdateAsync(flight) };
                if (stationFrom is not null)
                {
                    tasks.Add(stationRepo.UpdateAsync(stationFrom));
                }
                if (stationTo is not null)
                {
                    tasks.Add(stationRepo.UpdateAsync(stationTo));
                }
                Task.WaitAll(tasks.ToArray());
                await flightRepo.UpdateAsync(flight);
            }
            catch (InvalidOperationException e)
            {
                logger.LogError(e, "Error getting flight repository.");
            }
            catch (DbUpdateException e)
            {
                logger.LogError(e, "Error updating flight in repository.");
            }
            catch (Exception e)
            {
                logger.LogError(e, "Unknown exception while updating repository.");
            }
        }
示例#9
0
 public void NotifyFlightChanges(FlightEventArgs flightEvent)
 {
     FlightEventFromNotification = flightEvent;
 }
示例#10
0
 //    private void HasShot(object sender, EventArgs arguments) {
 //        if (state != State.SHOOT) return;
 //        Debug.Log ("Shots: " + hits);
 //        hits++;
 //        if (hits >= 3) understoodShooting = true;
 //    }
 private void HasFlown(object sender, FlightEventArgs arguments)
 {
     currentTargetSpeed = arguments.TargetSpeed;
     if (state == State.ACCELERATE) {
         //Debug.Log ("Target Speed: " + arguments.TargetSpeed + " Accelerations: " + arguments.TargetSpeed);
         if (waitForHighAcceleration) {
             if (arguments.TargetSpeed > arguments.MaxSpeed * 0.8f) {
                 accelerations++;
                 if(accelerations < iterations) playSound(againAudio);
                 waitForHighAcceleration = false;
             }
         } else {
             if (arguments.TargetSpeed < arguments.MaxSpeed / 4)	waitForHighAcceleration = true;
         }
         if (accelerations >= iterations)	understoodFlying = true;
     } else if (state == State.TURN_HORIZONTAL) {
         //Debug.Log (arguments.Rotation);
         if (waitForCompleteRotation) {
             if (Mathf.Abs (arguments.Rotation) < 15) understoodTurnHorizontal = true;
         } else {
             if (arguments.Rotation > 90 || arguments.Rotation < -90) {
                 waitForCompleteRotation = true;
             }
         }
     }
 }
示例#11
0
 protected virtual void OnPlaneDepartured(FlightEventArgs e)
 {
     PlaneDepartured?.Invoke(this, e);
 }
示例#12
0
 /// <summary>
 /// Konstruktor som "omvandlar" en FlightEventArgs-instans till en ny
 /// FlightEventItem-instans.
 /// </summary>
 public FlightEventItem(FlightEventArgs args)
 {
     FlightNr = args.flightNr;
     Action   = args.message;
     Time     = args.timestamp.ToLongTimeString();
 }
示例#13
0
 /// <summary>
 /// Denna metod har samma signatur som FlightEventDelegate och anropas av
 /// de "publishers" som vi lyssnar på, dvs. av FlightWindow.
 /// Metoden skapar ett nytt FlightEventItem och lägger till det i vår ListView.
 /// </summary>
 public void OnFlightEvent(FlightEventArgs args)
 {
     flightList.Items.Add(new FlightEventItem(args));
 }
示例#14
0
        private void OnFlightHappend(object sender, FlightEventArgs flightEventArgs)
        {
            var pattern = flightEventArgs.FlightInfo.FlightType == FlightType.Arrival ? Resources.LastArrivedPattern : Resources.LastDeparturedPattern;

            LastFlightInfo = string.Format(pattern, flightEventArgs.FlightInfo.City, flightEventArgs.FlightInfo.PlaneType.ToString(), flightEventArgs.FlightInfo.Time, flightEventArgs.FlightInfo.PassengerCount);
        }
 private void OnFlightEvent(FlightEventArgs args)
 {
     FlightEnterEvent.Invoke(args);
 }
示例#16
0
 private bool IsNewDay(FlightEventArgs args)
 {
     return(_lastFlightTime > args.FlightInfo.Time);
 }