-
Notifications
You must be signed in to change notification settings - Fork 37
Initial GraphPresenter prototype for #17 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8988341
Initial GraphPresenter prototype for #17
michael-hawker 268fdff
Merge branch 'master' into michael-hawker/graph-presenter
michael-hawker f6b6a0d
Update Example to use ImageEx to show something for files with no images
michael-hawker eedfc14
Update link to issue filed in Graph for the API we're trying to use
michael-hawker 7d43dd8
Update Missing Headers
michael-hawker 3a844f8
Merge remote-tracking branch 'origin/main' into michael-hawker/graph-…
michael-hawker 0c04921
[Broken] CalendarView Example
michael-hawker e5b3013
Add forgotten .NET Foundation Header
michael-hawker 2a9e157
Add OrderBy property to GraphPresenter
michael-hawker 6556c2d
Try updating dependencies
michael-hawker ff9ee75
Fix Stylecop Issues
michael-hawker dc8a641
Reconfigure Proxy to work in all cases and more effectively
michael-hawker b70e6b7
Better separate out Samples in UWP app
michael-hawker f028d3f
Add (Mail) Messages GraphPresenter sample
michael-hawker a4919fb
Add Task sample to GraphPresenter
michael-hawker 7cdd34f
Add in Teams Messages example to GraphPresenter
michael-hawker b93e18c
Remove unused OneDrive sample Converters
michael-hawker 97d4eba
Initial PR Feedback
michael-hawker 6e71a13
Apply suggestions from code review
michael-hawker bdabc31
Apply last feedback comment from @Sergio0694
michael-hawker 4a45671
Add extra scopes needed for InteractiveProvider for new samples
michael-hawker 3cc9ec3
Update Microsoft.Toolkit.Graph/Providers/MockProvider.cs
michael-hawker f012a4e
Address PR comments
michael-hawker c2dd9ea
Update Microsoft.Toolkit.Graph.Controls/Controls/GraphPresenter/Query…
azchohfi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
Microsoft.Toolkit.Graph.Controls/Controls/GraphPresenter/GraphPresenter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using Microsoft.Graph; | ||
| using Microsoft.Toolkit.Uwp.Helpers; | ||
| using Newtonsoft.Json.Linq; | ||
| using Windows.UI.Xaml; | ||
| using Windows.UI.Xaml.Controls; | ||
|
|
||
| namespace Microsoft.Toolkit.Graph.Controls | ||
| { | ||
| /// <summary> | ||
| /// Specialized <see cref="ContentPresenter"/> to fetch and display data from the Microsoft Graph. | ||
| /// </summary> | ||
| public class GraphPresenter : ContentPresenter | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets a <see cref="IBaseRequestBuilder"/> to be used to make a request to the graph. The results will be automatically populated to the <see cref="ContentPresenter.Content"/> property. Use a <see cref="ContentPresenter.ContentTemplate"/> to change the presentation of the data. | ||
| /// </summary> | ||
| public IBaseRequestBuilder RequestBuilder | ||
| { | ||
| get { return (IBaseRequestBuilder)GetValue(RequestBuilderProperty); } | ||
| set { SetValue(RequestBuilderProperty, value); } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Identifies the <see cref="RequestBuilder"/> dependency property. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// The identifier for the <see cref="RequestBuilder"/> dependency property. | ||
| /// </returns> | ||
| public static readonly DependencyProperty RequestBuilderProperty = | ||
| DependencyProperty.Register(nameof(RequestBuilder), typeof(IBaseRequestBuilder), typeof(GraphPresenter), new PropertyMetadata(null)); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="Type"/> of item returned by the <see cref="RequestBuilder"/>. | ||
| /// Set to the base item type and use the <see cref="IsCollection"/> property to indicate if a collection is expected back. | ||
| /// </summary> | ||
| public Type ResponseType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the returned data from the <see cref="RequestBuilder"/> is a collection. | ||
| /// </summary> | ||
| public bool IsCollection { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets list of <see cref="QueryOption"/> representing <see cref="Microsoft.Graph.QueryOption"/> values to pass into the request built by <see cref="RequestBuilder"/>. | ||
| /// </summary> | ||
| public List<QueryOption> QueryOptions { get; set; } = new List<QueryOption>(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a string to indicate a sorting order for the <see cref="RequestBuilder"/>. This is a helper to add this specific request option to the <see cref="QueryOptions"/>. | ||
| /// </summary> | ||
| public string OrderBy { get; set; } | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="GraphPresenter"/> class. | ||
| /// </summary> | ||
| public GraphPresenter() | ||
| { | ||
| Loaded += GraphPresenter_Loaded; | ||
| } | ||
|
|
||
| private async void GraphPresenter_Loaded(object sender, RoutedEventArgs e) | ||
| { | ||
| // Note: some interfaces from the Graph SDK don't implement IBaseRequestBuilder properly, see https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/722 | ||
| if (RequestBuilder != null) | ||
| { | ||
| var request = new BaseRequest( | ||
| RequestBuilder.RequestUrl, | ||
| RequestBuilder.Client); // TODO: Do we need separate Options here? | ||
| request.Method = "GET"; | ||
| request.QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List<Microsoft.Graph.QueryOption>(); | ||
|
|
||
| // Handle Special QueryOptions | ||
| if (!string.IsNullOrWhiteSpace(OrderBy)) | ||
| { | ||
| request.QueryOptions.Add(new Microsoft.Graph.QueryOption("$orderby", OrderBy)); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var response = await request.SendAsync<object>(null, CancellationToken.None).ConfigureAwait(false) as JObject; | ||
|
|
||
| //// TODO: Deal with paging? | ||
|
|
||
| var values = response["value"]; | ||
| object data = null; | ||
|
|
||
| if (IsCollection) | ||
| { | ||
| data = values.ToObject(Array.CreateInstance(ResponseType, 0).GetType()); | ||
| } | ||
| else | ||
| { | ||
| data = values.ToObject(ResponseType); | ||
| } | ||
|
|
||
| _ = DispatcherHelper.ExecuteOnUIThreadAsync(() => Content = data); | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| catch | ||
| { | ||
| // TODO: We should figure out what we want to do for Loading/Error states here. | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
Microsoft.Toolkit.Graph.Controls/Controls/GraphPresenter/QueryOption.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Windows.UI.Xaml; | ||
|
|
||
| namespace Microsoft.Toolkit.Graph.Controls | ||
| { | ||
| /// <summary> | ||
| /// XAML Proxy for <see cref="Microsoft.Graph.QueryOption"/>. | ||
| /// </summary> | ||
| public sealed class QueryOption | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <inheritdoc cref="Microsoft.Graph.Option.Name"/> | ||
| public string Name { get; set; } | ||
|
|
||
| /// <inheritdoc cref="Microsoft.Graph.Option.Value"/> | ||
| public string Value { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Implicit conversion for <see cref="QueryOption"/> to <see cref="Microsoft.Graph.QueryOption"/>. | ||
| /// </summary> | ||
| /// <param name="option">query option to convert.</param> | ||
| public static implicit operator Microsoft.Graph.QueryOption(QueryOption option) | ||
| { | ||
| return new Microsoft.Graph.QueryOption(option.Name, option.Value); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.