/// <summary> /// Parse the OneNote Service API create page response /// </summary> /// <param name="response">The HttpResponseMessage from the create page request</param> private async static Task <StandardResponse> ParseResponse(HttpResponseMessage response) { StandardResponse standardResponse; if (response.StatusCode == HttpStatusCode.Created) { dynamic responseObject = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); standardResponse = new CreateSuccessResponse { StatusCode = response.StatusCode, OneNoteClientUrl = responseObject.links.oneNoteClientUrl.href, OneNoteWebUrl = responseObject.links.oneNoteWebUrl.href }; } else { standardResponse = new StandardErrorResponse { StatusCode = response.StatusCode, Message = await response.Content.ReadAsStringAsync() }; } // Extract the correlation id. Apps should log this if they want to collect data to diagnose failures with Microsoft support IEnumerable <string> correlationValues; if (response.Headers.TryGetValues("X-CorrelationId", out correlationValues)) { standardResponse.CorrelationId = correlationValues.FirstOrDefault(); } return(standardResponse); }
/// <summary> /// Open the created page in the OneNote app /// </summary> private async void HyperlinkButton_Click(object sender, RoutedEventArgs e) { if (_response as CreateSuccessResponse != null) { CreateSuccessResponse successResponse = (CreateSuccessResponse)_response; await Windows.System.Launcher.LaunchUriAsync(FormulatePageUri(successResponse.OneNoteClientUrl)); } }