public void GetUserIDFromUserNameTest()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig.json");
            SymBotAuth botAuth = new SymBotAuth(symConfig);

            botAuth.authenticate();
            SymBotClient botClient = SymBotClient.initBot(symConfig, botAuth);

            UserClient userClient = botClient.getUsersClient();
            UserInfo   user       = userClient.getUserFromUsername("mikepreview");

            StreamClient    streamClient    = botClient.getStreamsClient();
            RoomSearchQuery roomSearchQuery = new RoomSearchQuery();

            roomSearchQuery.query     = "APITestRoom";
            roomSearchQuery.active    = true;
            roomSearchQuery.isPrivate = true;
            NumericId id = new NumericId();

            id.id = user.id;
            roomSearchQuery.member = id;
            RoomSearchResult result = streamClient.searchRooms(roomSearchQuery, 0, 0);

            Assert.IsTrue(user != null);
        }
示例#2
0
        //TODO: CHECK WHY 500
        public RoomSearchResult searchRooms(RoomSearchQuery query, int skip, int limit)
        {
            RoomSearchResult result    = null;
            SymConfig        symConfig = botClient.getConfig();

            RestRequestHandler restRequestHandler = new RestRequestHandler();
            string             url = CommonConstants.HTTPSPREFIX + symConfig.podHost + ":" + symConfig.podPort + PodConstants.SEARCHROOMS;


            if (skip > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&skip=" + skip;
                }
                else
                {
                    url = url + "?skip=" + skip;
                }
            }
            if (limit > 0)
            {
                if (url.Contains("?"))
                {
                    url = url + "&limit=" + limit;
                }
                else
                {
                    url = url + "?limit=" + limit;
                }
            }
            if (query.labels == null)
            {
                query.labels = new List <String>();
            }
            HttpWebResponse resp = restRequestHandler.executeRequest(query, url, false, WebRequestMethods.Http.Post, symConfig, true);
            string          body = restRequestHandler.ReadResponse(resp);

            result = JsonConvert.DeserializeObject <RoomSearchResult>(body);

            return(result);
        }
        public void SearchRoom()
        {
            SymConfig       symConfig       = new SymConfig();
            SymConfigLoader symConfigLoader = new SymConfigLoader();

            symConfig = symConfigLoader.loadFromFile("C:/Users/Michael/Documents/Visual Studio 2017/Projects/apiClientDotNet/apiClientDotNetTest/Resources/testConfig.json");
            SymBotAuth botAuth = new SymBotAuth(symConfig);

            botAuth.authenticate();
            SymBotClient botClient = SymBotClient.initBot(symConfig, botAuth);

            StreamClient    streamClient    = botClient.getStreamsClient();
            RoomSearchQuery roomSearchQuery = new RoomSearchQuery();

            roomSearchQuery.query     = "APITestRoom";
            roomSearchQuery.active    = true;
            roomSearchQuery.isPrivate = true;
            RoomSearchResult result = streamClient.searchRooms(roomSearchQuery, 0, 0);

            Assert.IsTrue(result != null);
        }
        public async Task <SearchResult> Search(SearchRequest request)
        {
            var roomTypes         = (await roomTypeRepository.GetAll()).ToList();
            var roomSearchResults = new List <RoomSearchResult>();

            foreach (var roomRequest in request.RoomTypeSearchRequests)
            {
                var roomSearchResult = new RoomSearchResult()
                {
                    Adults   = roomRequest.Adults,
                    Children = roomRequest.Children
                };
                var searchModel = new SearchModel()
                {
                    CheckinDate      = request.CheckInDate,
                    CheckoutDate     = request.CheckOutDate,
                    NumberofAdults   = roomRequest.Adults,
                    NumberofChildren = roomRequest.Children
                };
                var rooms = new List <RoomTypeSearchResultWithPricesList>();
                var roomTypeSearchResults = (await roomTypeRepository.Search(searchModel)).ToList();
                foreach (var roomTypeSearchResult in roomTypeSearchResults)
                {
                    var prices = new List <RoomPriceSearchResult>();
                    foreach (var date in EachDate(request.CheckInDate, request.CheckOutDate.AddDays(-1)))
                    {
                        foreach (var roomType in roomTypes)
                        {
                            if (roomType.RoomTypeId == roomTypeSearchResult.RoomTypeId)
                            {
                                float discountRates = await promotionRepository.GetAvailablePromotionForDateAndRoomId(new GetAvailablePromotionForDateAndRoomIdRequest()
                                {
                                    Date       = date,
                                    RoomTypeId = roomTypeSearchResult.RoomTypeId
                                });

                                prices.Add(new RoomPriceSearchResult()
                                {
                                    Date  = date,
                                    Price = (int)(roomType.DefaultPrice * (1 - discountRates))
                                });
                            }
                        }
                    }
                    rooms.Add(new RoomTypeSearchResultWithPricesList()
                    {
                        RoomTypeId             = roomTypeSearchResult.RoomTypeId,
                        MinRemain              = roomTypeSearchResult.MinRemain,
                        RoomPriceSearchResults = prices
                    });
                }
                roomSearchResult.RoomTypeSearchResults = rooms.OrderBy(roomType => roomType.RoomPriceSearchResults.Sum(price => price.Price));
                roomSearchResults.Add(roomSearchResult);
            }

            var result = new SearchResult()
            {
                CheckInDate       = request.CheckInDate,
                CheckOutDate      = request.CheckOutDate,
                RoomSearchResults = roomSearchResults
            };

            return(result);
        }
        public List<RoomSearchResult> Search(int siteId, int minCapacity, string[] particularities, int meetingDurationMinutes, DateTime startDate, DateTime endDate)
        {
            var conf = Configuration.Provider.Instance.Search;
            List<Room> rooms = siteId == -1 ? Room.GetAllRooms() : new List<Room>(Site.Get(new SiteIdentifier(siteId.ToString())).Rooms);
            // Preprocess the start date : minutes must be dividible by MIN_MEETING_DURATION.
            startDate = startDate.AddMinutes(-(startDate.Minute % conf.MinMeetingDuration)).AddSeconds(-startDate.Second);

            // Filter room capacity.
            if (minCapacity != -1)
                rooms = rooms.FindAll(room => room.Capacity >= minCapacity);

            // Filters particularities
            if (particularities != null)
            {
                List<Room> filteredRooms = new List<Room>();
                foreach (Room room in rooms)
                {
                    var parts = room.Particularities.ToList().ConvertAll(p => p.Identifier.Value);
                    var intersection = parts.Intersect(particularities);
                    if (intersection.Count() == particularities.Count())
                    {
                        filteredRooms.Add(room);
                    }
                }
                rooms = filteredRooms;
            }

            List<RoomSearchResult> results = new List<RoomSearchResult>();
            foreach(Room room in rooms)
            {
                RoomSearchResult result = new RoomSearchResult(room);
                List<Booking> allBookings = ObjectApiProvider.Instance.BookingsApi.GetBookings(room.Identifier, startDate, endDate).ConvertAll(id => Booking.Get(id));

                // Naive implementation : look at each 15min period to see if it is not empty.
                DateTime lastDate = endDate.AddMinutes(-meetingDurationMinutes);
                DateTime? meetingStart = null;
                for(DateTime currentDate = startDate; currentDate <= lastDate; currentDate = currentDate.AddMinutes(conf.MinMeetingDuration))
                {
                    DateTime meetingEndDate = currentDate.AddMinutes(meetingDurationMinutes);
                    var bookings = allBookings.Where(booking => booking.EndDate > currentDate && booking.StartDate <= meetingEndDate);
                    bool record = false;
                    bool dayJump = false;
                    if (bookings.Count() == 0)
                    {
                        // Here the slot from currentDate to meetingEndDate is available.
                        if(!meetingStart.HasValue)
                        {
                            // if no meeting start date is set, then sets it to the first available
                            meetingStart = currentDate;
                        }
                    }
                    else
                    {
                        // Add the contiguous reservable block if it exists.
                        record = true;
                    }

                    // If we are in the last iteration, record
                    if (currentDate >= lastDate)
                        record = true;

                    // If we get to the end of the day, start searching from the start of the next day
                    if(currentDate.Hour >= conf.DayEnd)
                    {
                        dayJump = true;
                        record = true;
                    }

                    // Records the last block
                    if (record)
                    {
                        if (meetingStart.HasValue && (currentDate - meetingStart.Value).TotalMinutes >= meetingDurationMinutes)
                        {
                            result.BookingCandidates.Add(new BookingCandidate(meetingStart.Value, currentDate));
                        }
                        meetingStart = null;
                    }

                    // Jumps to the next day
                    if(dayJump)
                        currentDate = currentDate.AddHours(24 - conf.DayEnd + conf.DayStart).AddMinutes(-conf.MinMeetingDuration);

                }

                // Add last result

                results.Add(result);
            }

            return results;
        }