public Task <bool> updateNotificationsAsync(object notif) { if (notif is AmountConstraint) { AmountConstraint castedNotif = (AmountConstraint)notif; var existingNotif = _context.AmountConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { existingNotif.Min = castedNotif.Min; existingNotif.Max = castedNotif.Max; _context.SaveChanges(); } else { return(Task.FromResult(false)); } } else if (notif is TimeConstraint) { TimeConstraint castedNotif = (TimeConstraint)notif; var existingNotif = _context.TimeConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { existingNotif.TimeIn = castedNotif.TimeIn; existingNotif.TimeOut = castedNotif.TimeOut; _context.SaveChanges(); } else { return(Task.FromResult(false)); } } else if (notif is LocationConstraint) { LocationConstraint castedNotif = (LocationConstraint)notif; var existingNotif = _context.LocationConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { existingNotif.Location = castedNotif.Location; _context.SaveChanges(); } else { return(Task.FromResult(false)); } } return(Task.FromResult(true)); }
public async Task <MeetingTimeSuggestionsResult> FindMeetingSuggestion(FindRoomRequest request) { List <Attendee> attendees = new List <Attendee>(); // Adding placeholder user to be able to remove the // Required flag on the user looking for available rooms. // An empty collection causes findMeetingTimes to look for free time slots for only the organizer. if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["PlaceholderAttendeeEmail"])) { attendees = new List <Attendee>() { new Attendee() { EmailAddress = new EmailAddress() { Address = WebConfigurationManager.AppSettings["PlaceholderAttendeeEmail"] } } }; } var locationConstraint = new LocationConstraint() { IsRequired = true, SuggestLocation = true, }; var timeConstraint = new TimeConstraint() { ActivityDomain = ActivityDomain.Unrestricted, Timeslots = new List <TimeSlot>() { new TimeSlot() { Start = new DateTimeTimeZone() { DateTime = request.From.ToString(), TimeZone = "UTC" }, End = new DateTimeTimeZone() { DateTime = request.To.ToString(), TimeZone = "UTC" } } } }; return(await _graphClient.Me.FindMeetingTimes(attendees, TimeConstraint : timeConstraint, MeetingDuration : new Duration(request.Duration), IsOrganizerOptional : attendees.Any(), LocationConstraint : locationConstraint) .Request() .PostAsync()); }
public async Task <List <LocationConstraint> > GetLocationConstraints(List <UserToNotifications> notifArray) { List <LocationConstraint> locationConstraints = new List <LocationConstraint>(); List <LocationConstraint> testC = new List <LocationConstraint>(); foreach (var z in notifArray) { testC = _context.LocationConstraint.Where(x => x.NotificationId == z.NotificationId).ToList(); if (testC.Count > 0) { LocationConstraint temp = _context.LocationConstraint.Where(x => x.NotificationId == z.NotificationId).ToList()[0]; locationConstraints.Add(temp); } } return(locationConstraints); }
private async Task <MeetingTimeSuggestionsResult> FindMeetingSuggestions(DateTimeTimeZone start, DateTimeTimeZone end) { var timeZone = User.GetUserGraphTimeZone(); var attendees = new List <AttendeeBase>() { new AttendeeBase { Type = AttendeeType.Required, EmailAddress = new EmailAddress { Name = "seetharam konda", Address = "*****@*****.**" } } }; var locationConstraint = new LocationConstraint { IsRequired = false, SuggestLocation = false, Locations = new List <LocationConstraintItem>() { new LocationConstraintItem { ResolveAvailability = false, DisplayName = "Conf room Hood" } } }; var timeConstraint = new TimeConstraint { ActivityDomain = ActivityDomain.Work, TimeSlots = new List <TimeSlot>() { new TimeSlot { Start = start, End = end //Start = new DateTimeTimeZone //{ // DateTime = "2019-04-16T09:00:00", // TimeZone = "Pacific Standard Time" //}, //End = new DateTimeTimeZone //{ // DateTime = "2019-04-18T17:00:00", // TimeZone = "Pacific Standard Time" //} } } }; var isOrganizerOptional = false; var meetingDuration = new Duration("PT1H"); var returnSuggestionReasons = true; var minimumAttendeePercentage = (double)100; MeetingTimeSuggestionsResult x = await _graphClient.Me .FindMeetingTimes(attendees, locationConstraint, timeConstraint, meetingDuration, null, isOrganizerOptional, returnSuggestionReasons, minimumAttendeePercentage) .Request() .Header("Prefer", "outlook.timezone=\"India Standard Time\"") .PostAsync(); return(x); }
private async Task RequestHandler(HttpContext ctx) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } DateTime startTime = DateTime.Now; S3Context s3ctx = null; try { s3ctx = new S3Context(ctx, _BaseDomains, null, (Logging.S3Requests ? Logger : null)); s3ctx.Response.Headers.Add("x-amz-request-id", s3ctx.Request.RequestId); s3ctx.Response.Headers.Add("x-amz-id-2", s3ctx.Request.RequestId); } catch (Exception e) { if (Logging.Exceptions) { Logger?.Invoke(_Header + "Exception:" + Environment.NewLine + Common.SerializeJson(e, true)); } return; } bool success = false; bool exists = false; S3Object s3obj = null; ObjectMetadata md = null; AccessControlPolicy acp = null; LegalHold legalHold = null; Retention retention = null; Tagging tagging = null; ListAllMyBucketsResult buckets = null; ListBucketResult listBucketResult = null; ListVersionsResult listVersionResult = null; LocationConstraint location = null; BucketLoggingStatus bucketLogging = null; VersioningConfiguration versionConfig = null; WebsiteConfiguration wc = null; DeleteMultiple delMultiple = null; DeleteResult delResult = null; try { if (Logging.HttpRequests) { Logger?.Invoke(_Header + "HTTP request: " + Environment.NewLine + s3ctx.Http.ToJson(true)); } if (Logging.S3Requests) { Logger?.Invoke(_Header + "S3 request: " + Environment.NewLine + s3ctx.Request.ToJson(true)); } if (PreRequestHandler != null) { success = await PreRequestHandler(s3ctx).ConfigureAwait(false); if (success) { await s3ctx.Response.Send().ConfigureAwait(false); return; } } switch (s3ctx.Request.RequestType) { #region Service case S3RequestType.ListBuckets: if (Service.ListBuckets != null) { buckets = await Service.ListBuckets(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(buckets)).ConfigureAwait(false); return; } break; #endregion #region Bucket case S3RequestType.BucketDelete: if (Bucket.Delete != null) { await Bucket.Delete(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 204; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketDeleteTags: if (Bucket.DeleteTagging != null) { await Bucket.DeleteTagging(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 204; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketDeleteWebsite: if (Bucket.DeleteWebsite != null) { await Bucket.DeleteWebsite(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 204; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketExists: if (Bucket.Exists != null) { exists = await Bucket.Exists(s3ctx).ConfigureAwait(false); if (exists) { ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); } else { ctx.Response.StatusCode = 404; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); } return; } break; case S3RequestType.BucketRead: if (Bucket.Read != null) { listBucketResult = await Bucket.Read(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(listBucketResult)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadAcl: if (Bucket.ReadAcl != null) { acp = await Bucket.ReadAcl(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(acp)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadLocation: if (Bucket.ReadLocation != null) { location = await Bucket.ReadLocation(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(location)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadLogging: if (Bucket.ReadLogging != null) { bucketLogging = await Bucket.ReadLogging(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(bucketLogging)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadTags: if (Bucket.ReadTagging != null) { tagging = await Bucket.ReadTagging(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(tagging)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadVersioning: if (Bucket.ReadVersioning != null) { versionConfig = await Bucket.ReadVersioning(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(versionConfig)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadVersions: if (Bucket.ReadVersions != null) { listVersionResult = await Bucket.ReadVersions(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(listVersionResult)).ConfigureAwait(false); return; } break; case S3RequestType.BucketReadWebsite: if (Bucket.ReadWebsite != null) { wc = await Bucket.ReadWebsite(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(wc)).ConfigureAwait(false); return; } break; case S3RequestType.BucketWrite: if (Bucket.Write != null) { await Bucket.Write(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketWriteAcl: if (Bucket.WriteAcl != null) { try { acp = Common.DeserializeXml <AccessControlPolicy>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Bucket.WriteAcl(s3ctx, acp).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketWriteLogging: if (Bucket.WriteLogging != null) { try { bucketLogging = Common.DeserializeXml <BucketLoggingStatus>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Bucket.WriteLogging(s3ctx, bucketLogging).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketWriteTags: if (Bucket.WriteTagging != null) { try { tagging = Common.DeserializeXml <Tagging>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Bucket.WriteTagging(s3ctx, tagging).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketWriteVersioning: if (Bucket.WriteVersioning != null) { try { versionConfig = Common.DeserializeXml <VersioningConfiguration>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Bucket.WriteVersioning(s3ctx, versionConfig).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.BucketWriteWebsite: if (Bucket.WriteWebsite != null) { try { wc = Common.DeserializeXml <WebsiteConfiguration>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Bucket.WriteWebsite(s3ctx, wc).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; #endregion #region Object case S3RequestType.ObjectDelete: if (Object.Delete != null) { await Object.Delete(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 204; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectDeleteMultiple: if (Object.DeleteMultiple != null) { try { delMultiple = Common.DeserializeXml <DeleteMultiple>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } delResult = await Object.DeleteMultiple(s3ctx, delMultiple).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(delResult)).ConfigureAwait(false); return; } break; case S3RequestType.ObjectDeleteTags: if (Object.DeleteTagging != null) { await Object.DeleteTagging(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 204; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectExists: if (Object.Exists != null) { md = await Object.Exists(s3ctx).ConfigureAwait(false); if (md != null) { if (!String.IsNullOrEmpty(md.ETag)) { ctx.Response.Headers.Add("ETag", md.ETag); } ctx.Response.Headers.Add("Last-Modified", md.LastModified.ToString()); ctx.Response.Headers.Add("x-amz-storage-class", md.StorageClass); ctx.Response.StatusCode = 200; ctx.Response.ContentLength = md.Size; ctx.Response.ContentType = md.ContentType; await ctx.Response.Send(md.Size).ConfigureAwait(false); } else { ctx.Response.StatusCode = 404; await ctx.Response.Send().ConfigureAwait(false); } return; } break; case S3RequestType.ObjectRead: if (Object.Read != null) { s3obj = await Object.Read(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = s3obj.ContentType; ctx.Response.ContentLength = s3obj.Size; await ctx.Response.Send(s3obj.Size, s3obj.Data).ConfigureAwait(false); return; } break; case S3RequestType.ObjectReadAcl: if (Object.ReadAcl != null) { acp = await Object.ReadAcl(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(acp)).ConfigureAwait(false); return; } break; case S3RequestType.ObjectReadLegalHold: if (Object.ReadLegalHold != null) { legalHold = await Object.ReadLegalHold(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(legalHold)).ConfigureAwait(false); return; } break; case S3RequestType.ObjectReadRange: if (Object.ReadRange != null) { s3obj = await Object.ReadRange(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = s3obj.ContentType; ctx.Response.ContentLength = s3obj.Size; await ctx.Response.Send(s3obj.Size, s3obj.Data).ConfigureAwait(false); return; } break; case S3RequestType.ObjectReadRetention: if (Object.ReadRetention != null) { retention = await Object.ReadRetention(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(retention)).ConfigureAwait(false); return; } break; case S3RequestType.ObjectReadTags: if (Object.ReadTagging != null) { tagging = await Object.ReadTagging(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/xml"; await ctx.Response.Send(Common.SerializeXml(tagging)).ConfigureAwait(false); return; } break; case S3RequestType.ObjectWrite: if (Object.Write != null) { await Object.Write(s3ctx).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectWriteAcl: if (Object.WriteAcl != null) { try { acp = Common.DeserializeXml <AccessControlPolicy>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Object.WriteAcl(s3ctx, acp).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectWriteLegalHold: if (Object.WriteLegalHold != null) { try { legalHold = Common.DeserializeXml <LegalHold>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Object.WriteLegalHold(s3ctx, legalHold).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectWriteRetention: if (Object.WriteRetention != null) { try { retention = Common.DeserializeXml <Retention>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Object.WriteRetention(s3ctx, retention).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; case S3RequestType.ObjectWriteTags: if (Object.WriteTagging != null) { try { tagging = Common.DeserializeXml <Tagging>(s3ctx.Request.DataAsString); } catch (InvalidOperationException ioe) { ioe.Data.Add("Context", s3ctx); ioe.Data.Add("RequestBody", s3ctx.Request.DataAsString); Logger?.Invoke(_Header + "XML exception: " + Environment.NewLine + Common.SerializeJson(ioe, true)); await s3ctx.Response.Send(S3Objects.ErrorCode.MalformedXML).ConfigureAwait(false); return; } await Object.WriteTagging(s3ctx, tagging).ConfigureAwait(false); ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; await ctx.Response.Send().ConfigureAwait(false); return; } break; #endregion } if (DefaultRequestHandler != null) { await DefaultRequestHandler(s3ctx).ConfigureAwait(false); return; } await s3ctx.Response.Send(S3Objects.ErrorCode.InvalidRequest).ConfigureAwait(false); return; } catch (S3Exception s3e) { if (Logging.Exceptions) { Logger?.Invoke(_Header + "S3 exception:" + Environment.NewLine + Common.SerializeJson(s3e, true)); } await s3ctx.Response.Send(s3e.Error).ConfigureAwait(false); return; } catch (Exception e) { if (Logging.Exceptions) { Logger?.Invoke(_Header + "exception:" + Environment.NewLine + Common.SerializeJson(e, true)); } await s3ctx.Response.Send(S3Objects.ErrorCode.InternalError).ConfigureAwait(false); return; } finally { if (Logging.HttpRequests) { Logger?.Invoke( _Header + "[" + ctx.Request.Source.IpAddress + ":" + ctx.Request.Source.Port + "] " + ctx.Request.Method.ToString() + " " + ctx.Request.Url.RawWithoutQuery + " " + s3ctx.Response.StatusCode + " [" + Common.TotalMsFrom(startTime) + "ms]"); } if (PostRequestHandler != null) { await PostRequestHandler(s3ctx).ConfigureAwait(false); } } }
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength) { locationConstraint = new LocationConstraint(); XmlParse.ParseLocationConstraint(inputStream, locationConstraint); }
public async Task <List <MeetingTimeCandidate> > FindMeetingTime() { // Get the group id. //var group = await graphClient.Groups[id].Request().GetAsync(); User me = await graphClient.Me.Request().Select("mail,userPrincipalName").GetAsync(); //Build the list of attendees List <Attendee> attendees = new List <Attendee>(); Attendee attendee = new Attendee(); EmailAddress mailaddress1 = new EmailAddress(); mailaddress1.Address = me.Mail; attendee.EmailAddress = mailaddress1; attendees.Add(attendee); //Build the list of locationcontraints LocationConstraint location = new LocationConstraint(); location.IsRequired = false; location.SuggestLocation = false; List <LocationConstraintItem> locationConstraints = new List <LocationConstraintItem>(); locationConstraints.Add(new LocationConstraintItem { DisplayName = "", LocationEmailAddress = "*****@*****.**" }); //Build the duration Duration duration = new Duration("PT1H"); TimeConstraint timeConstraint = new TimeConstraint(); List <TimeSlot> timeSlots = new List <TimeSlot>(); TimeSlot slot1 = new TimeSlot(); Microsoft.Graph.DateTimeTimeZone start = new Microsoft.Graph.DateTimeTimeZone(); start.DateTime = @"2017-06-10T15:30:00.000"; start.TimeZone = @"W. Europe Standard Time"; Microsoft.Graph.DateTimeTimeZone end = new Microsoft.Graph.DateTimeTimeZone(); end.DateTime = @"2017-06-14T18:00:00.000"; end.TimeZone = @"W. Europe Standard Time"; slot1.Start = start; slot1.End = end; timeSlots.Add(slot1); timeConstraint.Timeslots = timeSlots; //Execute the request var request = graphClient.Me.FindMeetingTimes(attendees, location, timeConstraint, duration, 3, false, false, 50).Request(); MeetingTimeSuggestionsResult meetingSuggestions = await request.PostAsync(); List <MeetingTimeCandidate> meetingTimeCandidates = new List <MeetingTimeCandidate>(); // Create model objects foreach (MeetingTimeSuggestion meetingJson in meetingSuggestions.MeetingTimeSuggestions) { MeetingTimeCandidate candidate = new MeetingTimeCandidate { Confidence = meetingJson.Confidence.Value, MeetingTimeSlotStart = meetingJson.MeetingTimeSlot.Start.DateTime, MeetingTimeSlotEnd = meetingJson.MeetingTimeSlot.End.DateTime, OrganizerAvailability = meetingJson.OrganizerAvailability.Value.ToString() ?? string.Empty, SuggestionHint = meetingJson.SuggestionReason }; meetingTimeCandidates.Add(candidate); } return(meetingTimeCandidates); }
public Task <bool> DeleteNotificationAsync(object notif) { if (notif is AmountConstraint) { AmountConstraint castedNotif = (AmountConstraint)notif; var existingNotif = _context.AmountConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); var existingJoin = _context.UserToNotifications .Where(y => y.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { _context.AmountConstraint.Remove(existingNotif); _context.UserToNotifications.Remove(existingJoin); _context.SaveChanges(); } else { return(Task.FromResult(false)); } } else if (notif is TimeConstraint) { TimeConstraint castedNotif = (TimeConstraint)notif; var existingNotif = _context.TimeConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); var existingJoin = _context.UserToNotifications .Where(y => y.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { _context.TimeConstraint.Remove(existingNotif); _context.UserToNotifications.Remove(existingJoin); _context.SaveChanges(); } else { return(Task.FromResult(false)); } } else if (notif is LocationConstraint) { LocationConstraint castedNotif = (LocationConstraint)notif; var existingNotif = _context.LocationConstraint .Where(x => x.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); var existingJoin = _context.UserToNotifications .Where(y => y.NotificationId == castedNotif.NotificationId) .FirstOrDefault(); if (existingNotif != null) { _context.LocationConstraint.Remove(existingNotif); _context.UserToNotifications.Remove(existingJoin); _context.SaveChanges(); } else { return(Task.FromResult(false)); } } return(Task.FromResult(true)); }
/// <summary> /// Adds a new LocationConstraint notification rule to database context /// </summary> /// <param name="newNotif"></param> /// <returns>true or false from Task</returns> public Task <LocationConstraint> AddLocationNotification(LocationConstraint newNotif) { _context.LocationConstraint.Add(newNotif); _context.SaveChanges(); return(Task.FromResult(newNotif)); }
private async void CalendarInviteButton_Click(object sender, RoutedEventArgs e) { // Call app specific code to subscribe to the service. For example: //BigTextArea.Text = PersonName.Text; try { GraphServiceClient graphClient = ProviderManager.Instance.GlobalProvider.Graph; var user = await graphClient.Users[PersonEmail.Text.ToString()] .Request() .GetAsync(); var attendees = new List <AttendeeBase>() { new AttendeeBase { EmailAddress = new EmailAddress { Address = user.Mail, Name = user.DisplayName }, Type = AttendeeType.Required } }; var timeConstraint = new TimeConstraint { TimeSlots = new List <TimeSlot>() { new TimeSlot { Start = new DateTimeTimeZone { DateTime = "2020-07-12T19:58:00.557Z", TimeZone = "Pacific Standard Time" }, End = new DateTimeTimeZone { DateTime = "2020-07-19T19:58:00.557Z", TimeZone = "Pacific Standard Time" } } } }; var locationConstraint = new LocationConstraint { IsRequired = false, SuggestLocation = true, Locations = new List <LocationConstraintItem>() { new LocationConstraintItem { DisplayName = "Conf Room 32/1368", LocationEmailAddress = "*****@*****.**" } } }; var meetingDuration = new Microsoft.Graph.Duration("PT1H"); MeetingTimeSuggestionsResult response = await graphClient.Me .FindMeetingTimes(attendees, null, null, meetingDuration, null, null, null, null) //.FindMeetingTimes(attendees, locationConstraint, timeConstraint, meetingDuration, null, null, null, null) .Request() .PostAsync(); if (response.MeetingTimeSuggestions.Count() == 0) { BigTextArea.Text = "No common meeting time found"; } else { var StartTime = response.MeetingTimeSuggestions.First().MeetingTimeSlot.Start; var EndTime = response.MeetingTimeSuggestions.First().MeetingTimeSlot.End; // Calendar Invite var @event = new Event { Subject = "My Calendar Invite via code", Start = StartTime, End = EndTime, Attendees = new List <Attendee>() { new Attendee { EmailAddress = new EmailAddress { Address = user.Mail, Name = user.DisplayName }, Type = AttendeeType.Required } }, IsOnlineMeeting = true, OnlineMeetingProvider = OnlineMeetingProviderType.TeamsForBusiness }; await graphClient.Me.Events .Request() .AddAsync(@event); var dateconvertinstance = new GraphDateTimeTimeZoneConverter(); BigTextArea.Text = "Calendar invite sent from " + dateconvertinstance.Convert(StartTime, null, null, null) + " to " + dateconvertinstance.Convert(EndTime, null, null, null) + "\n\n" + "Please check your calendar for teams meeting."; } } catch (Microsoft.Graph.ServiceException ex) { if (ex.Error.Code == "Request_ResourceNotFound") { BigTextArea.Text = "This user does not exit in the directory"; } else { BigTextArea.Text = "Error message - \n" + ex.Message; } } }