private async void MailButton_Click(object sender, RoutedEventArgs e) { Exception exception = null; try { this.DefaultViewModel["Subtitle"] = "Recent emails"; this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } }; SampleModel.Exchange.Message[] messages = await GetMessages(); if (messages == null) { this.DefaultViewModel["Items"] = null; } else { this.DefaultViewModel["Items"] = messages.Select(message => new { Primary = message.Subject, Secondary = "Received " + ToLocalTimeString(message.DateTimeReceived) + " from " + message.From.Name }); } } catch (Exception ex) { exception = ex; } if (exception != null) { await Office365Helper.ShowErrorMessageAsync("An unexpected error has occurred", null); } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { Exception exception = null; try { this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } }; SampleModel.SharePoint.SharePointFile[] files = await GetSharePointFiles(); if (files == null) { this.DefaultViewModel["Items"] = null; } else { this.DefaultViewModel["Items"] = files.Select(file => new { Primary = file.Name, Secondary = "Author: " + file.Author.Title + ". Last modified: " + ToLocalTimeString(file.TimeLastModified) }); } } catch (Exception ex) { exception = ex; } if (exception != null) { await Office365Helper.ShowErrorMessageAsync("An unexpected error has occurred", null); } }
private async void loginClick(object sender, RoutedEventArgs e) { await Office365Helper.ClearSession(); UserProfile userProfile = await UserProfileInfo.GetUserProfileRequest(); if (userProfile == null) { return; } DisplayName.DataContext = userProfile.DisplayName; Mail.DataContext = userProfile.EMail; CalendarTitle.DataContext = this.CalendarTitleString; loginButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; logoutButton.Visibility = Windows.UI.Xaml.Visibility.Visible; addCalButton.Visibility = Windows.UI.Xaml.Visibility.Visible; removeCalButton.Visibility = Windows.UI.Xaml.Visibility.Visible; refreshButton.Visibility = Windows.UI.Xaml.Visibility.Visible; sendMailButton.Visibility = Windows.UI.Xaml.Visibility.Visible; SessionListView.Visibility = Windows.UI.Xaml.Visibility.Visible; EventsListView.Visibility = Windows.UI.Xaml.Visibility.Visible; GetSessionList(); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { Exception exception = null; try { this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } }; SampleModel.ActiveDirectory.UserProfile profile = await GetActiveDirectoryProfile(); if (profile == null) { this.DefaultViewModel["Items"] = null; } else { this.DefaultViewModel["Items"] = new[] { new { Primary = profile.DisplayName, Secondary = "Display Name" }, new { Primary = profile.GivenName, Secondary = "First Name" }, new { Primary = profile.Surname, Secondary = "Last Name" } }; } } catch (Exception ex) { exception = ex; } if (exception != null) { await Office365Helper.ShowErrorMessageAsync("An unexpected error has occurred", null); } }
public async Task <bool> DeleteCalendarEvent(string Id) { string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Calendar/Events('{1}')", _serviceInfo.ApiEndpoint, Id); Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, requestUrl); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); return(request); }; HttpResponseMessage response = await Office365Helper.SendRequestAsync(_serviceInfo, _httpClient, requestCreator); string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(_serviceInfo, responseString); return(false); } return(true); }
private async void CalendarButton_Click(object sender, RoutedEventArgs e) { Exception exception = null; try { this.DefaultViewModel["Subtitle"] = "Upcoming events"; this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } }; SampleModel.Exchange.CalendarEvent[] events = await GetCalendarEvents(); if (events == null) { this.DefaultViewModel["Items"] = null; } else { this.DefaultViewModel["Items"] = events.Select(calendarEvent => new { Primary = calendarEvent.Subject, Secondary = ToLocalTimeString(calendarEvent.Start) + " to " + ToLocalTimeString(calendarEvent.End) }); } } catch (Exception ex) { exception = ex; } if (exception != null) { await Office365Helper.ShowErrorMessageAsync("An unexpected error has occurred", null); } }
private async void ContactsButton_Click(object sender, RoutedEventArgs e) { Exception exception = null; try { this.DefaultViewModel["Subtitle"] = "Contacts"; this.DefaultViewModel["Items"] = new[] { new { Primary = "Loading...", Secondary = "Please wait..." } }; SampleModel.Exchange.Contact[] contacts = await GetContacts(); if (contacts == null) { this.DefaultViewModel["Items"] = null; } else { this.DefaultViewModel["Items"] = contacts.Select(contact => new { Primary = contact.DisplayName, Secondary = contact.EmailAddress1 }); } } catch (Exception ex) { exception = ex; } if (exception != null) { await Office365Helper.ShowErrorMessageAsync("An unexpected error has occurred", null); } }
public ActionResult GetMailList() { var client = Office365Helper.GetAuthenticatedClient(); var data = client.Me.Messages.Request().Top(10).GetAsync().Result; ViewBag.Mail = data.ToList(); return(View()); }
/// <summary> /// 列出最近使用的文档 /// </summary> /// <returns></returns> public ActionResult GetUserFile() { var client = Office365Helper.GetAuthenticatedClient(); var de = client.Me.Drive.Recent().Request().GetAsync().Result; ViewBag.Files = de; return(View()); }
/// <summary> /// 获取组织架构列表 /// </summary> /// <returns></returns> public ActionResult GetORGList() { var client = Office365Helper.GetAuthenticatedClient(); var org = client.Me.Events.Request().Top(10).GetAsync().Result; ViewBag.ORG = org.ToList(); return(View()); }
private async void SignoutButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // TODO: When incorporating the sample code into your app, you will want to include the // "Office365Helper.ClearSession()" call as part of your application's regular // sign-out routine, rather than a separate button on each page. await Office365Helper.ClearSession(); this.DefaultViewModel["Items"] = null; }
public async Task <CalendarEvent> AddOrUpdateCalendarEvent(CalendarEvent calendarEvent) { // Query to see if event already exists. If so, do Update instead. string[] queryParameters = { String.Format(CultureInfo.InvariantCulture, "$filter=contains(Subject,'Spid:[{0}]')", calendarEvent.Spid), }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Calendar/Events?{1}", _serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); int calendarItemCount = (await GetCalendarEventsRequest(requestUrl, true)); if (calendarItemCount > 1) { return(null); } if (calendarItemCount == 1) { return(await UpdateCalendarEvent(calendarEvent)); } requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Calendar/Events", _serviceInfo.ApiEndpoint); // string postData = JsonConvert.SerializeObject(calendarEvent); string postData = CommonCode.Serialize(calendarEvent); Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); request.Content = new StringContent(postData); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(request); }; HttpResponseMessage response = await Office365Helper.SendRequestAsync(_serviceInfo, _httpClient, requestCreator); string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(_serviceInfo, responseString); return(null); } // CalendarEvent c = JsonConvert.DeserializeObject<CalendarEvent>(responseString); CalendarEvent c = CommonCode.Deserialize <CalendarEvent>(responseString); return(c); }
public ActionResult GetUserList() { var client = Office365Helper.GetAuthenticatedClient(); var user = client.Users.Request().Top(10).GetAsync().Result; //client.Users.Request().AddAsync(new Microsoft.Graph.User(){ }).Result; ViewBag.Users = user.ToList(); return(View()); }
public static async Task <UserProfile> GetUserProfileRequest() { UserProfile userProfile = null; string errorMessage = string.Empty; try { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetActiveDirectoryServiceInfoAsync(); if (!serviceInfo.HasValidAccessToken) { throw new Exception("Unable to get AAD ServiceInfo"); } // Create a URL for retrieving the data: string[] queryParameters = { "api-version=2013-11-08" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/me?{1}", serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); // Prepare the HTTP request: using (HttpClient client = new HttpClient()) { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); return(request); }; using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); return(userProfile); } userProfile = JsonConvert.DeserializeObject <UserProfile>(responseString); } } } catch (Exception ex) { errorMessage = ex.Message; } return(userProfile); }
private async Task <int> GetCalendarEventsRequest(string requestUrl, bool firstPage) { string errorMessage = string.Empty; try { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); return(request); }; HttpResponseMessage response = await Office365Helper.SendRequestAsync(_serviceInfo, _httpClient, requestCreator); string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(_serviceInfo, responseString); return(0); } JsonValue jsonResponse = JsonValue.Parse(responseString); JsonArray events = jsonResponse.GetObject().GetNamedArray("value"); if (events.Count > 0) { foreach (JsonValue o in events) { //CalendarEvent c = JsonConvert.DeserializeObject<CalendarEvent>(o.Stringify()); CalendarEvent c = CommonCode.Deserialize <CalendarEvent>(o.Stringify()); JsonObject json = JsonObject.Parse(o.Stringify()); c.Id = json.GetNamedString("Id"); _events.Add(c); _calendarItemIdForUpdate = c.Id; } return(events.Count); } else { return(0); } } catch (Exception ex) { errorMessage = ex.Message; } await Office365Helper.ShowErrorMessageAsync("Unexpected error retrieving events", errorMessage); return(0); }
private static async Task <SampleModel.Exchange.CalendarEvent[]> GetCalendarEvents() { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetExchangeServiceInfoAsync(); if (!serviceInfo.HasValidAccessToken) { return(null); } // Create a URL for retrieving the data: string[] queryParameters = { String.Format(CultureInfo.InvariantCulture, "$filter=End ge {0}Z", DateTime.UtcNow.ToString("s")), "$top=10", "$select=Subject,Start,End" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Calendar/Events?{1}", serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); // Prepare the HTTP request: using (HttpClient client = new HttpClient()) { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); return(request); }; // Send the request using a helper method, which will add an authorization header to the request, // and automatically retry with a new token if the existing one has expired. using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); return(null); } var events = JObject.Parse(responseString)["value"].ToObject <SampleModel.Exchange.CalendarEvent[]>(); events = events.OrderBy(e => e.Start).ToArray(); return(events); } } }
public static async Task SendMail(Message mailMessage) { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetExchangeServiceInfoAsync(); if (!serviceInfo.HasValidAccessToken) { await Office365Helper.ShowErrorMessageAsync("Unable to get Exchange ServiceInfo", string.Empty); return; } HttpClient client = new HttpClient(); // Create a URL for retrieving the data: string[] queryParameters = new string[] { "MessageDisposition=SendOnly" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Messages?{1}", serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); // string postData = JsonConvert.SerializeObject(mailMessage); string postData = CommonCode.Serialize(mailMessage); Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); request.Content = new StringContent(postData); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(request); }; using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); } // TODO maybe display a confirmation. } }
private static async Task <SampleModel.SharePoint.SharePointFile[]> GetSharePointFiles() { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetSharePointOneDriveServiceInfoAsync(); if (!serviceInfo.HasValidAccessToken) { return(null); } // Create a URL for retrieving the data: string[] queryParameters = { "$orderby=Name", "$expand=Author", "$select=Name,Author,TimeLastModified" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Folders('Shared%20with%20Everyone')/Files?{1}", serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); // Prepare the HTTP request: using (HttpClient client = new HttpClient()) { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=verbose"); return(request); }; // Send the request using a helper method, which will add an authorization header to the request, // and automatically retry with a new token if the existing one has expired. using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); return(null); } return(JObject.Parse(responseString)["d"]["results"].ToObject <SampleModel.SharePoint.SharePointFile[]>()); } } }
private static async Task <SampleModel.ActiveDirectory.UserProfile> GetActiveDirectoryProfile() { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetActiveDirectoryServiceInfoAsync(); if (!serviceInfo.HasValidAccessToken) { return(null); } // Create a URL for retrieving the data: string[] queryParameters = { "api-version=2013-11-08" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/{1}/users/{2}?{3}", serviceInfo.ApiEndpoint, WebUtility.UrlEncode(Office365Helper.TenantId), WebUtility.UrlEncode(Office365Helper.UserId), String.Join("&", queryParameters)); // Prepare the HTTP request: using (HttpClient client = new HttpClient()) { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); return(request); }; // Send the request using a helper method, which will add an authorization header to the request, // and automatically retry with a new token if the existing one has expired. using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); return(null); } return(JsonConvert.DeserializeObject <SampleModel.ActiveDirectory.UserProfile>(responseString)); } } }
public static async Task <CalendarEvents> CreateCalendarInstance() { CalendarEvents calendarEvents = new CalendarEvents(); // Obtain information for communicating with the service: calendarEvents._serviceInfo = await Office365ServiceInfo.GetExchangeServiceInfoAsync(); if (!calendarEvents._serviceInfo.HasValidAccessToken) { await Office365Helper.ShowErrorMessageAsync("Unable to get Exchange ServiceInfo", string.Empty); return(null); } calendarEvents._httpClient = new HttpClient(); return(calendarEvents); }
/// <summary> /// 发送邮件 /// </summary> /// <returns></returns> public ActionResult SetMail() { var client = Office365Helper.GetAuthenticatedClient(); var claimsPrincipalCurrent = System.Security.Claims.ClaimsPrincipal.Current; var fromrecipient = new Microsoft.Graph.Recipient() { EmailAddress = new Microsoft.Graph.EmailAddress() { Address = claimsPrincipalCurrent.Identity.Name, Name = claimsPrincipalCurrent.FindFirst("name").Value } }; var toToRecipients = new List <Recipient>(); toToRecipients.Add(fromrecipient); byte[] contentBytes = System.IO.File.ReadAllBytes(@"C:\test\300.jpg"); string contentType = "image/jpg"; MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage(); attachments.Add(new FileAttachment { ODataType = "#microsoft.graph.fileAttachment", ContentBytes = contentBytes, ContentType = contentType, ContentId = "testing", Name = "300.jpg" }); Message email = new Message { Body = new ItemBody { Content = "测试邮件这是一个测试邮件", ContentType = BodyType.Text, }, Subject = "大会测试邮件", ToRecipients = toToRecipients, Attachments = attachments }; var d = client.Me.SendMail(email, true).Request().PostAsync(); return(View()); }
private async void logoutClick(object sender, RoutedEventArgs e) { DisplayName.DataContext = ""; Mail.DataContext = ""; CalendarTitle.DataContext = this.CalendarTitleString; loginButton.Visibility = Windows.UI.Xaml.Visibility.Visible; logoutButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; addCalButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; removeCalButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; refreshButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; sendMailButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed; SessionListView.Visibility = Windows.UI.Xaml.Visibility.Collapsed; EventsListView.Visibility = Windows.UI.Xaml.Visibility.Collapsed; await Office365Helper.ClearSession(); }
public ActionResult CheckUrl() { var is21v = ClaimsPrincipal.Current.FindFirst("iss").Value.IndexOf("china") >= 0; var siteUrl = HttpUtility.UrlDecode(Request.QueryString["siteUrl"]); // var accessToken = HttpCookie.get CacheHelper.Instance.Get(tenant)?.ToString(); var accessToken = SPOnlineController.Token; if (string.IsNullOrEmpty(accessToken)) { accessToken = Office365Helper.GetSPOnlineTokenAsync(Tenant, siteUrl, is21v); //CacheHelper.Instance.Set(tenant, accessToken, 3500); } var title = SPOnlineHelper.GetSharePointTitle(accessToken, siteUrl); ResponseModel r = new ResponseModel(); r.IsSuccess = !string.IsNullOrEmpty(title); r.Data = title; return(Json(r, JsonRequestBehavior.AllowGet)); }
public async Task <CalendarEvent> UpdateCalendarEvent(CalendarEvent calendarEvent) { string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/Me/Calendar/Events('{1}')", _serviceInfo.ApiEndpoint, _calendarItemIdForUpdate); // string postData = JsonConvert.SerializeObject(calendarEvent); string postData = CommonCode.Serialize(calendarEvent); Func <HttpRequestMessage> requestCreator = () => { var patch = new HttpMethod("PATCH"); HttpRequestMessage request = new HttpRequestMessage(patch, requestUrl); request.Content = new StringContent(postData); request.Headers.Add("Accept", "application/json;odata=minimalmetadata"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(request); }; HttpResponseMessage response = await Office365Helper.SendRequestAsync(_serviceInfo, _httpClient, requestCreator); string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(_serviceInfo, responseString); return(null); } // CalendarEvent c = JsonConvert.DeserializeObject<CalendarEvent>(responseString); CalendarEvent c = CommonCode.Deserialize <CalendarEvent>(responseString); return(c); }
public async Task <List <Session> > GetSessions() { List <Session> sessionList = new List <Session>(); string errorMessage = String.Empty; try { // Obtain information for communicating with the service: Office365ServiceInfo serviceInfo = await Office365ServiceInfo.GetSharePointServiceInfoAsync( AppSettings.SharePointHostResourceId, AppSettings.SharePointSessionListUri); if (!serviceInfo.HasValidAccessToken) { throw new Exception("Unable to get SharePoint ServiceInfo"); } // Create a URL for retrieving the data: string[] queryParameters = new string[] { "select=title,start,end,description,code" }; string requestUrl = String.Format(CultureInfo.InvariantCulture, "{0}/items?{1}", serviceInfo.ApiEndpoint, String.Join("&", queryParameters)); // Prepare the HTTP request: using (HttpClient client = new HttpClient()) { Func <HttpRequestMessage> requestCreator = () => { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl); request.Headers.Add("Accept", "application/json;odata=verbose"); return(request); }; // Send the request using a helper method, which will add an authorization header to the request, // and automatically retry with a new token if the existing one has expired. using (HttpResponseMessage response = await Office365Helper.SendRequestAsync( serviceInfo, client, requestCreator)) { // Read the response and deserialize the data: string responseString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { await Office365Helper.ShowErrorMessageAsync(serviceInfo, responseString); return(sessionList); } //sessionList = JObject.Parse(responseString)["d"]["results"].ToObject<List<Session>>(); JsonValue jsonResponse = JsonValue.Parse(responseString); JsonObject d = jsonResponse.GetObject().GetNamedObject("d"); JsonArray sessionsArray = d.GetObject().GetNamedArray("results"); if (sessionsArray.Count > 0) { foreach (JsonValue o in sessionsArray) { Session s = CommonCode.Deserialize <Session>(o.Stringify()); sessionList.Add(s); } } } } } catch (Exception ex) { errorMessage = ex.Message; } if (!sessionList.Any()) { await Office365Helper.ShowErrorMessageAsync("No Sessions Available.", errorMessage); } return(sessionList); }
public void Configuration(IAppBuilder app) { Office365Helper.ConfigurationAuth(app); }