public static async Task <byte[]> GetAttachedImgContent(string userId, string eventId, HttpClient graphHttpClient) { HttpResponseMessage response = await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/users/{userId}/calendar/events/{eventId}/attachments"); string responseMsg = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new FocusException($"List event attachments graph call failed: {responseMsg}"); } GraphDataSet <EventAttachment> dataSet = JsonConvert.DeserializeObject <GraphDataSet <EventAttachment> >(responseMsg); if (dataSet != null && dataSet.Value != null && dataSet.Value.Count > 0) { foreach (EventAttachment attachment in dataSet.Value) { if (attachment.ContentType.IndexOf("image", StringComparison.OrdinalIgnoreCase) > -1) { return(Convert.FromBase64String(attachment.ContentBytes)); } } } return(null); }
public static async Task <List <Event> > GetInComingEventsAsync(string userId, string organizerMail, HttpClient graphHttpClient) { List <Event> result = new List <Event>(); HttpResponseMessage response = await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/users/{userId}/calendar/events"); string responseMsg = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new FocusException($"List events graph call failed: {responseMsg}"); } GraphDataSet <Event> dataSet = JsonConvert.DeserializeObject <GraphDataSet <Event> >(responseMsg); foreach (Event e in dataSet.Value) { if (e.EventStartTimeOffset > DateTimeOffset.UtcNow && string.Equals(e.OrganizerEmail, organizerMail, StringComparison.OrdinalIgnoreCase)) { e.UserId = userId; result.Add(e); } } return(result); }
public static async Task <IEnumerable <TeamsApp> > GetInstalledAppsAsync(string groupId, HttpClient graphhttpClient) { HttpResponseMessage response = await graphhttpClient.GetAsync($"{Settings.GraphBaseUri}/teams/{groupId}/installedApps?$expand=teamsAppDefinition"); string responseMsg = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new FocusException($"Get teams installed apps graph call failed: {responseMsg}"); } GraphDataSet <TeamsApp> dataSet = JsonConvert.DeserializeObject <GraphDataSet <TeamsApp> >(responseMsg); return(dataSet.Value); }
public static async Task <IEnumerable <Identity> > GetGroupUsersAsync(string groupId, HttpClient graphHttpClient) { HttpResponseMessage response = await graphHttpClient.GetAsync($"{Settings.GraphBaseUri}/groups/{groupId}/members"); string responseMsg = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new FocusException($"List group users graph call failed: {responseMsg}"); } GraphDataSet <Identity> dataSet = JsonConvert.DeserializeObject <GraphDataSet <Identity> >(responseMsg); return(dataSet.Value.Where(x => !string.IsNullOrEmpty(x.Mail))); }
//https://docs.microsoft.com/en-us/graph/api/group-list?view=graph-rest-1.0&tabs=http public static async Task <string> GetDemoGroupId(HttpClient graphHttpClient) { //Read the graph document to update the api path string apiPath = "Please update the api path"; HttpResponseMessage response = await graphHttpClient.GetAsync(apiPath); string responseMsg = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new FocusException($"List groups graph call failed: {responseMsg}"); } GraphDataSet <Identity> dataSet = JsonConvert.DeserializeObject <GraphDataSet <Identity> >(responseMsg); return(dataSet.Value.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Mail) && Settings.DemoGroupMail.IndexOf(x.Mail, StringComparison.CurrentCultureIgnoreCase) >= 0).Id); }