예제 #1
0
        public override Task <Response> AddBooking(Request request, ServerCallContext context)
        {
            Logger.Info("add booking");
            Response response = null;

            try
            {
                tripsGrpc.Booking booking = request.Booking;
                Trip    trip         = ProtoUtils.ConvertToTrip(booking.Trip);
                Account account      = ProtoUtils.ConvertToAccount(booking.Account);
                Booking savedBooking = tripServices.AddBooking(booking.Client, booking.Phone, booking.NumTickets, trip, account);
                response = ProtoUtils.CreateOkResponse();

                Logger.Info("notifying observers");
                Response responseBookingAdded = new Response()
                {
                    Booking = new tripsGrpc.Booking()
                    {
                        Id         = savedBooking.Id,
                        Account    = booking.Account,
                        Trip       = booking.Trip,
                        Client     = savedBooking.ClientName,
                        Phone      = savedBooking.PhoneNumber,
                        NumTickets = savedBooking.NumTickets
                    }
                };
                buffer.Post(responseBookingAdded);
            }
            catch (Exception e)
            {
                response = ProtoUtils.CreateErrorResponse(e);
            }
            Logger.InfoFormat("add booking response {0}", response);
            return(Task.FromResult(response));
        }
예제 #2
0
        public override Task <Response> Logout(Request request, ServerCallContext context)
        {
            tripsGrpc.Account account        = request.Account;
            IServerStreamWriter <Response> o = null;

            observers.Remove(account.Id, out o);
            Logger.InfoFormat("removing observer {0}", account.Id);
            return(Task.FromResult(ProtoUtils.CreateOkResponse()));
        }