Esempio n. 1
0
		public Task<bool> ReserveRoom(RoomInfo room, TimeSpan duration)
		{
			Appointment appointment = new Appointment(_service);

			// Set the properties on the appointment object to create the appointment.
			appointment.Subject = "Room reservation";
			appointment.Body = $"Automatically created by FindMeRoomOSS on {DateTime.Now}";
			appointment.Start = DateTime.Now;
			appointment.End = appointment.Start + duration;
			appointment.Location = room.RoomId;
			appointment.RequiredAttendees.Add(room.RoomId);

			// Save the appointment to your calendar.
			appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

			PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);

			// Verify that the appointment was created by using the appointment's item ID.
			appointment = Item.Bind(_service, appointment.Id, psPropSet) as Appointment;
			if (appointment == null)
			{
				return Task.FromResult(false);
			}
			return Task.Run(async () =>
				{
					var finishTime = DateTime.Now + CreationTimeout;
					Attendee roomAttendee;
					// wait till the room accepts
					do
					{
						Debug.WriteLine("Waiting for response...");
						await Task.Delay(1000);

						// refresh appointment data
						appointment = Item.Bind(_service, appointment.Id, psPropSet) as Appointment;
						if (appointment == null)
						{
							Debug.WriteLine("Appointment has been deleted");
							return false;
						}
						roomAttendee = appointment.RequiredAttendees.FirstOrDefault(att => att.Address == room.RoomId);
						if (roomAttendee == null)
						{
							Debug.WriteLine("Someone is messing with our appointment");
							return false;
						}
					} while (DateTime.Now < finishTime && (
							!roomAttendee.ResponseType.HasValue ||
							roomAttendee.ResponseType == MeetingResponseType.Unknown ||
							roomAttendee.ResponseType == MeetingResponseType.NoResponseReceived
						));
					Debug.WriteLine($"Response is {roomAttendee.ResponseType}...");
					return roomAttendee.ResponseType.HasValue && roomAttendee.ResponseType.Value == MeetingResponseType.Accept;
				});
		}
Esempio n. 2
0
		public RoomAvailabilityInfo(TimeInterval availability, RoomInfo room)
		{
			Availability = availability;
			Room = room;
		}