Esempio n. 1
0
        private IAliceRequest CreateRequest()
        {
            RequestBuilder requestBuilder = new RequestBuilder(_command, _userMessage, AliceContext.Current.UserProfile);
            IAliceRequest  request        = requestBuilder.Build();

            return(request);
        }
        public IAliceResponse Handle(IAliceRequest request)
        {
            IAliceResponse response = new AliceResponse();

            response.Message = "Booking service could not serve this request.";

            return(response);
        }
Esempio n. 3
0
        public IAliceResponse Handle(IAliceRequest aliceRequest)
        {
            IAliceResponse response = new AliceResponse();
            IList <Room>   rooms    = _roomRepository.List();

            AliceListRoomParser parser = new AliceListRoomParser();

            response.Message = parser.Parse(rooms);

            return(response);
        }
        public IAliceResponse Handle(IAliceRequest request)
        {
            IAliceResponse response = new AliceResponse();
            DateTime       date     = DateTime.Now;

            if (request.Parameters.Count == 3)
            {
                date = Utility.ConvertToDate(request.Parameters[2].Value);
            }

            response.Message = ListBookings(date, string.Empty, request.UserProfile);

            return(response);
        }
Esempio n. 5
0
 private void AddParameters(IAliceRequest request)
 {
     if (_command.MatchingPattern == "regex")
     {
         Regex regex = new Regex(_command.UserMessage, RegexOptions.IgnoreCase);
         Match match = regex.Match(_userMessage);
         for (int i = 0; i < match.Groups.Count; i++)
         {
             AliceRequestParameter param = new AliceRequestParameter();
             param.Name  = i.ToString();
             param.Value = match.Groups[i].Value;
             request.Parameters.Add(param);
         }
     }
 }
Esempio n. 6
0
        public IAliceResponse Handle(IAliceRequest request)
        {
            string serverAction             = request.ServerAction.ToLower();
            IInternalRequestHandler handler = null;

            InternalRequestHandlerFactory factory = new InternalRequestHandlerFactory(_bookingRepository, _roomRepository);

            handler = factory.GetInternalRequestHandler(serverAction);

            IAliceResponse response;

            response = handler.Handle(request);

            return(response);
        }
        public IAliceResponse Handle(IAliceRequest request)
        {
            _aliceRequest = request;
            IAliceResponse response;
            switch (request.ServerAction)
            {
                case "AddToUnhandled":
                    response = AddToUnhandled();
                    break;

                default:
                throw new NotImplementedException("DefaultAliceRequestHandler not implemented");
            }

            return response;
        }
Esempio n. 8
0
        public IAliceResponse Process()
        {
            IAliceResponse response;

            if (string.IsNullOrEmpty(_command.ServerAction))
            {
                response = new AliceResponse();
                response.ActionToPerform = _command.ClientAction;
                response.Message         = _command.GetRandomSuccessResponse();
            }
            else
            {
                IAliceRequest request = CreateRequest();
                response = _handler.Handle(request);
            }

            return(response);
        }
Esempio n. 9
0
        public IAliceResponse Handle(IAliceRequest aliceRequest)
        {
            BookingRequestsBuilder requestsBuilder = new BookingRequestsBuilder(aliceRequest.Parameters, aliceRequest.UserProfile);
            BookingRequest         bookingRequest;

            bookingRequest = requestsBuilder.Build();

            Booking        booking;
            IAliceResponse response = new AliceResponse();

            try
            {
                booking          = _bookingRepository.Book(bookingRequest);
                response.Message = string.Format("{0} was booked by you from {1} for {2}", booking.RoomName, booking.BookRangeLocalToString(aliceRequest.UserProfile.TimeZoneInfo), booking.BookedForToString());
            }
            catch (Exception ex)
            {
                response.StatusCode = System.Net.HttpStatusCode.BadRequest;
                response.Message    = ex.Message;
            }

            return(response);
        }
        public IAliceResponse Handle(IAliceRequest aliceRequest)
        {
            CancellationRequestsBuilder requestsBuilder = new CancellationRequestsBuilder(aliceRequest.Parameters, aliceRequest.UserProfile);
            BookingRequest bookingRequest;

            bookingRequest = requestsBuilder.Build();

            Booking        booking;
            IAliceResponse response = new AliceResponse();

            try
            {
                booking          = _bookingRepository.Cancel(bookingRequest);
                response.Message = string.Format("Cancelled");
            }
            catch (Exception ex)
            {
                response.StatusCode = System.Net.HttpStatusCode.BadRequest;
                response.Message    = "Error: " + ex.Message;
            }

            return(response);
        }