Пример #1
0
        public async void Check()
        {
            UzContext uzContext = await _uzClient.GetUZContextAsync();

            Request[] requests = GetRequests();
            Console.WriteLine($"Checking requests: {requests.Length}");
            foreach (Request request in requests)
            {
                TicketCheckResult checkResult = await CheckTicket(uzContext, request);

                switch (checkResult.RequestState)
                {
                case RequestState.Expired: {
                    NotifyExpired(request);
                    break;
                }

                case RequestState.Found: {
                    BookPlacesResponse bookingResult = await _ticketBooker.BookPlacesAsync(uzContext, checkResult, request);

                    if (!bookingResult.IsError)
                    {
                        NotifyFoundAsync(bookingResult, request);
                    }
                    Console.WriteLine(checkResult);
                    break;
                }
                }
            }
        }
Пример #2
0
        private Tuple <Train, Wagon> GetCheapestTrainAndWagon(TicketCheckResult checkResult)
        {
            IEnumerable <Tuple <Train, Wagon> > allTrainWagonPairs =
                from train in checkResult.Trains
                from wagon in train.Wagons
                select new Tuple <Train, Wagon>(train, wagon);

            return(allTrainWagonPairs.OrderBy(pair => pair.Item2.Price).First());
        }
Пример #3
0
        public async Task <BookPlacesResponse> BookPlacesAsync(UzContext uzContext, TicketCheckResult checkResult, Request request)
        {
            var uzClient = new UzClient();

            Tuple <Train, Wagon> cheapestTrainAndWagon = GetCheapestTrainAndWagon(checkResult);
            Train train = cheapestTrainAndWagon.Item1;
            Wagon wagon = cheapestTrainAndWagon.Item2;

            BookPlacesResponse bookingResult =
                await uzClient.BookPlaceAsync(uzContext, train.StationFrom.Id, train.StationTo.Id,
                                              train.StationFrom.DateTime,
                                              train.TrainNumber, wagon.Number, wagon.CoachClass, wagon.TypeCode,
                                              wagon.Places.First(), wagon.PlaceType, request.PassangerName,
                                              request.PassangerSurname);

            return(bookingResult);
        }