public HeaderControl()
 {
     InitializeComponent();
     timeObserver = new TimeObserver(LevelTime);
     DataContext  = GeneralObject._gameViewModel;
     borders      = new List <Border>();
     borders.Add(border1);
     borders.Add(border2);
     borders.Add(border3);
 }
Exemplo n.º 2
0
 public void unregisterTimeObserver(TimeObserver observer)
 {
     timeObservers.Remove(observer);
 }
Exemplo n.º 3
0
 public void registerTimeObserver(TimeObserver observer)
 {
     timeObservers.Add(observer);
 }
Exemplo n.º 4
0
        public async Task <Result <Booking> > Execute(Data.Bookings.Booking booking, AgentContext agent, string languageCode)
        {
            Baggage.AddBookingReferenceCode(booking.ReferenceCode);

            var requestInfoResult = await _requestStorage.Get(booking.ReferenceCode);

            if (requestInfoResult.IsFailure)
            {
                return(Result.Failure <Booking>(requestInfoResult.Error));
            }

            var(bookingRequest, availabilityInfo) = requestInfoResult.Value;
            var creditCardResult = await GetCreditCard(booking, availabilityInfo);

            if (creditCardResult.IsFailure)
            {
                return(Result.Failure <Booking>(creditCardResult.Error));
            }

            var bookingRequestResult = await SendSupplierRequest(bookingRequest, availabilityInfo.AvailabilityId, booking, creditCardResult.Value, languageCode);

            if (bookingRequestResult.IsSuccess)
            {
                _bookingAnalyticsService.LogBookingOccured(bookingRequest, booking, agent);
            }

            await ProcessRequestResult(bookingRequestResult);

            return(bookingRequestResult);

            async Task <Result <Booking> > SendSupplierRequest(AccommodationBookingRequest bookingRequest, string availabilityId,
                                                               Data.Bookings.Booking booking, CreditCardInfo creditCard, string languageCode)
            {
                var features = new List <Feature>();

                var roomDetails = bookingRequest.RoomDetails
                                  .Select(d => new SlimRoomOccupation(d.Type, d.Passengers, string.Empty, d.IsExtraBedNeeded))
                                  .ToList();

                var creditCardInfo = creditCard is not null
                    ? new CreditCard(creditCard.Number, creditCard.ExpiryDate, creditCard.HolderName, creditCard.SecurityCode, CardVendor.AmericanExpress)
                    : (CreditCard?)null;

                var innerRequest = new BookingRequest(availabilityId: availabilityId,
                                                      roomContractSetId: bookingRequest.RoomContractSetId,
                                                      referenceCode: booking.ReferenceCode,
                                                      rooms: roomDetails,
                                                      features: features,
                                                      creditCard: creditCardInfo,
                                                      rejectIfUnavailable: bookingRequest.RejectIfUnavailable);

                try
                {
                    var(isSuccess, _, bookingResult, error) = await TimeObserver.Execute(observedFunc : () => _supplierConnectorManager
                                                                                         .Get((Suppliers)booking.Supplier)
                                                                                         .Book(innerRequest, languageCode),
                                                                                         notifyFunc : Notify,
                                                                                         notifyAfter : TimeSpan.FromSeconds(BookExecutionTimeLimitInSeconds));

                    if (isSuccess)
                    {
                        return(bookingResult);
                    }

                    var message = error.Detail;
                    // If result is failed this does not mean that booking failed. All known cases are listed below
                    _logger.LogBookingFinalizationFailure(booking.ReferenceCode, message);

                    if (!error.Extensions.TryGetBookingFailureCode(out var failureCode))
                    {
                        // We do not know whether booking was registered on supplier
                        return(GetStubDetails(booking));
                    }

                    return(failureCode switch
                    {
                        // We are sure that booking was not done
                        BookingFailureCodes.ConnectorValidationFailed => Result.Failure <Booking>(message),
                        BookingFailureCodes.ValuationResultNotFound => Result.Failure <Booking>(message),
                        BookingFailureCodes.PreBookingFailed => Result.Failure <Booking>(message),
                        BookingFailureCodes.SupplierValidationFailed => Result.Failure <Booking>(message),
                        BookingFailureCodes.SupplierRejected => Result.Failure <Booking>(message),

                        // We do not know whether booking was registered on supplier
                        _ => GetStubDetails(booking)
                    });


                    Task Notify()
                    {
                        _logger.LogBookingExceededTimeLimit(innerRequest.ReferenceCode);
                        return(Task.CompletedTask);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogBookingFinalizationException(ex);
                    return(GetStubDetails(booking));
                }