private async void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // get free plane generate flight and send to airport
            if (_rnd.Next() % 6 == 0)
            {
                bool destinationOut = _rnd.Next() % 2 == 0;
                var  plane          = await _factory.GetFreePlane(destinationOut);

                if (plane != null)
                {
                    var newFlight = new Fligth
                    {
                        FlightPlane = plane,
                        Id          = Guid.NewGuid(),
                        TotalTime   = TimeSpan.FromMilliseconds(0)
                    };


                    //if (!(await _sender.SendFlight(newFlight)))
                    if (SendFlightEvent != null)
                    {
                        SendFlightEvent?.Invoke(newFlight);
                    }
                    else
                    {
                        _factory.ReturnPlane(plane);
                    }
                }
            }
        }
        public async void AddFlight(Fligth newFlight)
        {
            // Add new plane to airport, request in server
            if (newFlight != null && newFlight.FlightPlane != null)
            {
                var webPlane = newFlight.FlightPlane;
                var newPlane = new FlightPlane(webPlane);
                LogMessage($"Star new flight plane {newPlane.Id}, destinatio out {newPlane.DestinationOut}");
                _dataService.AddNewPlane(newPlane);
                _clientHtttpSocketService.UpadatePlane(newPlane);

                newPlane.OnEmergency += OnPlaneEmergency;

                if (newPlane.DestinationOut)
                {
                    // if destination out add to terminal
                    _inTermialPlanes.Add(newPlane);
                    EnterPlaneInLeg(newPlane, GetNextLeg(newPlane.State, true));
                }
                else
                {
                    // if destination out add to the inAirPlanesrminal
                    _inAirPlanes.Add(newPlane);
                    EnterPlaneInLeg(newPlane, GetNextLeg(newPlane.State, false));
                }
            }
        }
Beispiel #3
0
 internal async Task <bool> SendFlight(Fligth newFlight)
 {
     if (!_invalid)
     {
         try
         {
             var conten   = JsonConvert.SerializeObject(newFlight);
             var response = Client.PostAsJsonAsync("api/Flight", newFlight).Result;
             return(response.IsSuccessStatusCode);
         }
         catch (Exception ex)
         {
             _invalid = true;
             Debug.WriteLine(ex);
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
        internal async Task <bool> SendFlight(Fligth newFlight)
        {
            if (!_invalid)
            {
                try
                {
                    var response = await Client.PostAsJsonAsync("api/Flight", newFlight);

                    return(response.IsSuccessStatusCode);
                }
                catch (Exception ex)
                {
                    _invalid = true;
                    Debug.WriteLine(ex);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
 public void Post([FromBody] Fligth newFligth)
 {
     //WebApiApplication.Locator.Tower.AddFlight(newFligth);
     GlobalHost.ConnectionManager.GetHubContext <ClientHub>().Clients.All.onFlightCome(newFligth);
 }
Beispiel #6
0
 public void SendFlight(Fligth newFlight)
 {
     Clients.Others.flightCome(newFlight);
 }