Esempio n. 1
0
        /// <summary>
        /// Caches the departures according to departure board request.
        /// </summary>
        public static async Task <bool> CacheDepartureBoardAsync(DepartureBoardRequest dbRequest)
        {
            if (dbRequest.GetType() == typeof(StationInfoRequest))
            {
                return(await CacheDepartureBoardAsync((StationInfoRequest)dbRequest));
            }

            else
            {
                return(await CacheDepartureBoardAsync((LineInfoRequest)dbRequest));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Processes the request async.
        /// </summary>
        public async override Task ProcessAsync()
        {
            try
            {
                DepartureBoardRequest dbRequest = await Receive <DepartureBoardRequest>();

                Logging.Log($"Received departure board request from { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() }. Data: { dbRequest.ToString() }");

                DepartureBoardResponse dbRes = null;

                await Task.Run(() =>
                {
                    if (dbRequest is StationInfoRequest)
                    {
                        using (var dbProcessing = new Interop.DepartureBoardManaged(DataFeed.Full, (StationInfoRequest)dbRequest))
                        {
                            dbProcessing.ObtainDepartureBoard();
                            dbRes = dbProcessing.ShowDepartureBoard();
                        }
                    }
                    else if (dbRequest is LineInfoRequest)
                    {
                        using (var dbProcessing = new Interop.DepartureBoardManaged(DataFeed.Full, (LineInfoRequest)dbRequest))
                        {
                            dbProcessing.ObtainDepartureBoard();
                            dbRes = dbProcessing.ShowDepartureBoard();
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                });

                Send(dbRes);

                Logging.Log($"Departure board response to { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() } was successfully send.");
            }
            catch (Exception ex)
            {
                Logging.Log($"Departure board request from { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() } could not be processed. { Logging.LogException(ex) }");
            }
            Dispose();
        }
Esempio n. 3
0
        public static async Task <DepartureBoardResponse> SendDepartureBoardRequestAsync(DepartureBoardRequest dbRequest)
        {
            // This cannot be done better since in each of the method we need information about specialized classes (caching, algorithm).
            // Actually, it could be done better (without code copies), but then the code would be unreadable and less efficient, too.

            if (dbRequest.GetType() == typeof(StationInfoRequest))
            {
                return(await SendDepartureBoardRequestAsync((StationInfoRequest)dbRequest));
            }

            else
            {
                return(await SendDepartureBoardRequestAsync((LineInfoRequest)dbRequest));
            }
        }
Esempio n. 4
0
 private DepartureBoardResponse Get(DepartureBoardRequest request)
 {
     return(AsyncHelpers.RunSync(() => ControllerBase.ProcessAsync <DepartureBoardRequest, DepartureBoardProcessing, DepartureBoardResponse>(request)) ?? new DepartureBoardResponse());
 }