Ejemplo n.º 1
0
        /// <summary>
        /// Client reservation request handler.
        /// Delegate the requeset to the appropriate seller and return the result
        /// if request or seller doesn't exist throw an exception
        /// </summary>
        /// <param name="seller">Seller to delegate this request</param>
        /// <param name="request">reservetaion request parameters from user</param>
        /// <returns>reservation id from seller</returns>
        public int MakeReservation(string seller, ReservationRequest request)
        {
            int reservationID = 0;

            try
            {
                reservationID = FlightSearchLogic.Instance.MakeReservation(seller, request);
            }
            catch (FlightSearchServerException e)
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode        = e.StatusCode; //e.StatusCode; // System.Net.HttpStatusCode.NotFound;
                WebOperationContext.Current.OutgoingResponse.StatusDescription = e.StatusDescription;
            }
            catch (Exception e)
            {
                WebOperationContext.Current.OutgoingResponse.SetStatusAsNotFound(e.Message);
            }

            return(reservationID);
        }
Ejemplo n.º 2
0
        void reserve(string[] input)
        {
            if (input.Length != 4)
            {
                Console.WriteLine("Invalid parameters");
                Console.WriteLine("reserve <seller> <flight> <dd/MM/yyyy>");
            }
            else
            {
                FlightSearchServerCA.ReservationRequest reservationRequest =
                    new FlightSearchServerCA.ReservationRequest();

                string   seller = input[1];
                string   flight = input[2];
                DateTime date   = GetDate(input[3]);


                reservationRequest.date         = date;
                reservationRequest.flightNumber = flight;

                int reservationId = channel.MakeReservation(seller, reservationRequest);
                Console.WriteLine("OK, reservation ID: {0}", reservationId);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delegate function to make reservation.
        /// this function will make a reservation with the requested seller
        /// if seller doesn't exist or ReservationRequest is invalid on seller's
        /// server an excetion will be throwed.
        /// </summary>
        /// <param name="seller">Seller to order from</param>
        /// <param name="request">Request parameters to the sellers</param>
        /// <returns>sucessfull reservation ID</returns>
        public int MakeReservation(string seller, ReservationRequest request)
        {
            if (!sellers.ContainsKey(seller))
            {
                throw new FlightSearchServerSellerNotFound();
            }

            FlightSearchReservationRequest fsrr =
                new FlightSearchReservationRequest();

            // Prepare data
            fsrr.date         = request.date;
            fsrr.flightNumber = request.flightNumber;

            int reservationID = 0;

            try
            {
                reservationID = sellers[seller].MakeReservation(fsrr);
            }
            catch (FaultException e)
            {
                //throw new FlightSearchServerException(e.Reason.ToString());

                /* We should differentiate between two types of error:
                 * 1. Request wasn't found (no such flight exists) - 404
                 * 2. Flight is fully booked - 403 ("The server understood the request, but is refusing to fulfill it")
                 * - Using strings here was worng
                 */
                if (e.Reason.ToString().Equals("no such flight"))
                {
                    throw new FlightSearchServerFlightNotFound();
                }
                else if (e.Reason.ToString().Equals("no seats available"))
                {
                    throw new FlightSearchServerNoSeats();
                }
                else
                {
                    throw new FlightSearchServerException(e.Reason.ToString()); // Legacy
                }
            }
            catch (CommunicationException e) /* This MIGHT look redundant but its NOT, these are different kinds of errors */
            {
                Console.WriteLine("==================== Make reservation - BEGIN =====================");
                Console.WriteLine("Seller {0} Communication error, dropping him from FlightSearch.", seller);
                Console.WriteLine(e.Message.ToString());
                Console.WriteLine("==================== Make reservation - END =======================");
                ITicketSellingQueryService victim;
                sellers.TryRemove(seller, out victim);
                throw new FlightSearchServerSellerDropped();
            }
            catch (Exception e)
            {
                Console.WriteLine("Seller {0} {1} malfunction: \n{2}", seller, "Make reservation", e.Message.ToString());
                ITicketSellingQueryService victim;
                sellers.TryRemove(seller, out victim);
                throw new FlightSearchServerSellerDropped();
            }
            return(reservationID);
        }