public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var building = context.GetBuilding(); if (null != building) { context.Done(building); return; } await context.Forward(new ChooseBuildingDialog(_requestUri, null), GotBuilding, context.Activity, new CancellationToken()); }
public async Task GetFloorName(IDialogContext context, IAwaitable <IMessageActivity> argument) { var buildingId = context.GetBuilding()?.BuildingId; if (string.IsNullOrEmpty(buildingId)) { await context.PostAsync(context.CreateMessage($"Set your building first with the 'set building' command", InputHints.AcceptingInput)); context.Done <FloorChoice>(null); return; } _floorName = (await argument).Text; if (null == _floorName) { context.Done <FloorChoice>(null); return; } await context.Forward(new RoomNinjaGetRoomsStatusForBuildingCallDialog(_requestUri, buildingId), GotRooms, context.Activity, new CancellationToken()); }
private async Task GotRoomStatus(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback) { var rooms = await callback; var room = rooms.MatchName(_criteria.Room); // TODO: do we need to use api.GetRoomsStatus(room.Id) ? if (null == room) { await context.PostAsync(context.CreateMessage($"Can't find room {_criteria.Room}", InputHints.AcceptingInput)); } else { var tz = GetTimezone(context.GetBuilding()?.BuildingId); var now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tz); // ok, now we just have rooms that meet the criteria - let's see what's free when asked var meetings = room.Status.NearTermMeetings.Where(i => i.End > (_criteria.StartTime ?? now)).OrderBy(i => i.Start).ToList(); var firstMeeting = meetings.FirstOrDefault(); var result = (null == firstMeeting) ? new { busy = false, room = room, Until = (DateTimeOffset?)null } : (firstMeeting.Start > (_criteria.EndTime ?? _criteria.StartTime ?? now) && !firstMeeting.IsStarted) ? new { busy = false, room = room, Until = (DateTimeOffset?)TimeZoneInfo.ConvertTime(firstMeeting.Start, tz) } : new { busy = true, room = room, Until = (DateTimeOffset?)TimeZoneInfo.ConvertTime(GetNextFree(meetings), tz) }; var until = result.Until.HasValue ? $"{result.Until.ToSimpleTime()}" : ""; var start = _criteria.StartTime.HasValue ? $" at {_criteria.StartTime.ToSimpleTime()}" : ""; var reason = firstMeeting == null ? "" : !string.IsNullOrEmpty(firstMeeting.Organizer) && firstMeeting.Organizer != room.Info.DisplayName ? $" by {firstMeeting.Organizer}" : !string.IsNullOrEmpty(firstMeeting.Subject) ? $" for {firstMeeting.Subject}" : ""; if (!string.IsNullOrEmpty(reason) && null != firstMeeting && _criteria.StartTime.HasValue) { reason = $"{reason} from {TimeZoneInfo.ConvertTime(firstMeeting.Start, tz):h:mm tt}"; } if (!string.IsNullOrEmpty(reason) && null != firstMeeting && (result.Until != firstMeeting.End || _criteria.StartTime.HasValue)) { reason = $"{reason} until {TimeZoneInfo.ConvertTime(firstMeeting.End, tz).ToSimpleTime()}"; } var displayName = room?.Info?.SpeakableName ?? _criteria.Room; if (result.busy) { if (!string.IsNullOrEmpty(reason)) { if (_criteria.StartTime.HasValue) { reason = $" and will be used{reason}"; } else { reason = $" and is currently used{reason}"; } } if (result.Until.HasValue) { await context.PostAsync(context.CreateMessage($"{displayName} is busy{start} until {until}{reason}", InputHints.AcceptingInput)); } else { await context.PostAsync(context.CreateMessage($"{displayName} is busy{start}{reason}", InputHints.AcceptingInput)); } } else { if (result.Until.HasValue) { if (!string.IsNullOrEmpty(reason)) { reason = $" when it's reserved{reason}"; } await context.PostAsync(context.CreateMessage($"{displayName} is free{start} until {until}{reason}", InputHints.AcceptingInput)); } else { await context.PostAsync(context.CreateMessage($"{displayName} is free{start}", InputHints.AcceptingInput)); } } } context.Done(string.Empty); }
public static TimeZoneInfo GetTimezone(this IDialogContext context) { var tzId = context.GetBuilding()?.TimezoneId; return(string.IsNullOrEmpty(tzId) ? TimeZoneInfo.Utc : TimeZoneInfo.FindSystemTimeZoneById(tzId)); }
private async Task GotRoomStatus(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback) { var rooms = await callback; var tz = GetTimezone(context.GetBuilding()?.BuildingId); var now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tz); if (_criteria.NumberOfPeople.HasValue) { if (rooms.Any(r => r.Info.Size > 0)) { rooms = rooms.Where(r => r.Info.Size >= _criteria.NumberOfPeople).ToArray(); } else { await context.PostAsync(context.CreateMessage($"Not checking room size - data not available for that building", InputHints.IgnoringInput)); } } var equiValues = (_criteria.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Where(i => i != RoomSearchCriteria.EquipmentOptions.None).ToArray(); if (equiValues.Any()) { if (rooms.Any(r => (r.Info.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Any())) { rooms = rooms.Where(r => equiValues.All(e => (r.Info.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Contains(e))).ToArray(); } else { await context.PostAsync(context.CreateMessage($"Not checking room equipment - data not available for that building", InputHints.IgnoringInput)); } } var preferredFloorId = context.GetPreferredFloor()?.FloorId; // ok, now we just have rooms that meet the criteria - let's see what's free when asked _allRooms = rooms.ToList(); _roomResults = rooms.Select(r => { var meetings = r.Status.NearTermMeetings.Where(i => i.End > _criteria.StartTime).OrderBy(i => i.Start).ToList(); var firstMeeting = meetings.FirstOrDefault(); if (null == firstMeeting) { return(new { busy = false, room = r }); } else if (firstMeeting.Start > _criteria.EndTime && !firstMeeting.IsStarted) { return(new { busy = false, room = r }); } else { return(new { busy = true, room = r }); } }) .Where(i => !i.busy) .Select(i => i.room) .OrderBy(i => i.Info.FloorId == preferredFloorId ? 0 : 1) .ThenBy(i => i.Info.Size) .ThenBy(i => i.Info.Equipment?.Count) .ToList(); if (_roomResults.Count == 0) { await context.PostAsync(context.CreateMessage($"Sorry, no free rooms meet that criteria", InputHints.AcceptingInput)); context.Done(string.Empty); } else if (_roomResults.Count == 1) { await context.PostAsync(context.CreateMessage($"{_roomResults[0].Info.SpeakableName} is free - would you like to reserve it?", InputHints.ExpectingInput)); context.Wait(ConfirmBookOneRoom); } else { await PromptForMultipleRooms(context); } }