/// <summary> /// checks for changes in start/end values as well as title (subject) /// </summary> /// <param name="sessionId"></param> /// <param name="request"></param> /// <returns></returns> public async Task UpdateSessionAsync(string sessionId, SessionRequest request) { var @event = await GetMeetingByExternalIdAsync(sessionId); if (@event == null) { throw new SessionNotFoundException($"no session found for session Id: {sessionId}"); } var newBegin = DateTimeTimeZone.FromDateTimeOffset(DateTimeOffset.Parse(request.DateBegin)); var newEnd = DateTimeTimeZone.FromDateTimeOffset(DateTimeOffset.Parse(request.DateEnd)); if (newBegin != @event.Start) { @event.Start = newBegin; } if (newEnd != @event.End) { @event.End = newEnd; } if (@event.Subject != request.Title) { @event.Subject = request.Title; } //ToDo: consider appending new message to top of body if diferent? await confClient.Users[ServiceAccountEmail].Events[@event.Id] .Request().UpdateAsync(@event); return; }
/// <summary> /// Creates Teams online meeting enabled Calendar event /// </summary> /// <param name="request">The Out-of-the-box vILT SessionRequest class</param> /// <returns>Graph.Event (https://docs.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0) </returns> public async Task CreateSessionAsync(SessionRequest request) { var newEvent = new Event { IsOnlineMeeting = true, IsReminderOn = _meetingConfig.IsReminderOn, ResponseRequested = _meetingConfig.ResponseRequested, OnlineMeetingProvider = _meetingConfig.ProviderType(), Start = DateTimeTimeZone.FromDateTimeOffset(DateTimeOffset.Parse(request.DateBegin)), End = DateTimeTimeZone.FromDateTimeOffset(DateTimeOffset.Parse(request.DateEnd)), Subject = request.Title, Body = new ItemBody { ContentType = _meetingConfig.BodyType(), Content = request.Description }, Organizer = new Recipient { EmailAddress = new EmailAddress { Address = ServiceAccountEmail } }, Location = new Location { //ToDo: consider a SchemaExtension (https://docs.microsoft.com/en-us/graph/extensibility-overview) DisplayName = request.SessionId }, }; if (_meetingConfig.CreatorIsAttendee) { newEvent.Attendees = new List <Attendee> //ToDo: consider whether this is desirable. This is not the Cornerstone session's "instructor" { new Attendee { EmailAddress = new EmailAddress { Address = request.CreatorEmail } } }; } await confClient.Users[ServiceAccountEmail].Events.Request().AddAsync(newEvent); return; }
public void FromDateTimeOffset_Should_Convert_DateTimeOffset_To_DateTimeTimeZone() { List <DateTimeTimeZone> dateTimeTimeZoneList = new List <DateTimeTimeZone>(); DateTimeTimeZone dateTimeTimeZoneTestOne = new DateTimeTimeZone { TimeZone = "Eastern Standard Time", DateTime = "2019-06-03T14:00:00.0000000" }; dateTimeTimeZoneList.Add(dateTimeTimeZoneTestOne); DateTimeTimeZone dateTimeTimeZoneTestTwo = new DateTimeTimeZone { TimeZone = "UTC", DateTime = "2019-01-25T06:37:39.8058788Z" }; dateTimeTimeZoneList.Add(dateTimeTimeZoneTestTwo); DateTimeTimeZone dateTimeTimeZoneTestThree = new DateTimeTimeZone { TimeZone = "Mauritius Standard Time", DateTime = "2019-06-03T22:00:00.0000000" }; dateTimeTimeZoneList.Add(dateTimeTimeZoneTestThree); foreach (var dateTimeTimeZone in dateTimeTimeZoneList) { DateTime dateTime = GetDateTimeFromDateTimeTimeZone(dateTimeTimeZone); TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(dateTimeTimeZone.TimeZone); TimeSpan offset = timeZoneInfo.GetUtcOffset(dateTime); dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified); var expectedDateTimeOffset = new DateTimeOffset(dateTime, offset); expectedDateTimeOffset = TimeZoneInfo.ConvertTime(expectedDateTimeOffset, timeZoneInfo); var actualDateTimeTimeZone = DateTimeTimeZone.FromDateTimeOffset(expectedDateTimeOffset, dateTimeTimeZone.TimeZone); Assert.Equal(expectedDateTimeOffset.ToString(DateTimeFormat, CultureInfo.InvariantCulture), actualDateTimeTimeZone.DateTime); Assert.Equal(timeZoneInfo.Id, actualDateTimeTimeZone.TimeZone); } }
/// <summary> /// Converts the dateTimeOffset to a DateTimeTimeZone object /// </summary> /// <param name="dateTimeOffset">>A single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00:00.0000000).</param> /// <param name="timeZoneInfo">The expected values for timeZone are specified here: https://docs.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0 </param> /// <returns></returns> public static DateTimeTimeZone ToDateTimeTimeZone(this DateTimeOffset dateTimeOffset, TimeZoneInfo timeZoneInfo) { return(DateTimeTimeZone.FromDateTimeOffset(dateTimeOffset, timeZoneInfo)); }
/// <summary> /// Converts the dateTimeOffset to a DateTimeTimeZone object /// </summary> /// <param name="dateTimeOffset">>A single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00:00.0000000).</param> /// <param name="timeZone">The expected values for timeZone are specified here: https://docs.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0 </param> /// <returns></returns> public static DateTimeTimeZone ToDateTimeTimeZone(this DateTimeOffset dateTimeOffset, string timeZone) { return(DateTimeTimeZone.FromDateTimeOffset(dateTimeOffset, timeZone)); }
/// <summary> /// Converts the dateTimeOffset to a DateTimeTimeZone object /// <para>This method assumes the value is expressed on the same timezone as the target mailbox and the local machine</para> /// </summary> /// <param name="dateTimeOffset">>A single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00:00.0000000).</param> /// <returns></returns> public static DateTimeTimeZone ToDateTimeTimeZone(this DateTimeOffset dateTimeOffset) { return(DateTimeTimeZone.FromDateTimeOffset(dateTimeOffset)); }