Skip to content

Commit 9940b3e

Browse files
committed
updated nuget packages + fixes
calculating optimal pageSize automatically, implementing a debouncer
1 parent 5950d70 commit 9940b3e

File tree

10 files changed

+83
-29
lines changed

10 files changed

+83
-29
lines changed

MsGraphSamples.Services/AuthService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class AuthService : IAuthService
2222
private static readonly string[] _scopes = ["Directory.Read.All"];
2323

2424
private GraphServiceClient? _graphClient;
25-
25+
2626
//public GraphServiceClient GraphClient => _graphClient ??= new GraphServiceClient(GetAppCredential());
2727
public GraphServiceClient GraphClient => _graphClient ??= new GraphServiceClient(GetBrowserCredential());
2828

@@ -42,7 +42,7 @@ private InteractiveBrowserCredential GetBrowserCredential()
4242
var credentialOptions = new InteractiveBrowserCredentialOptions
4343
{
4444
ClientId = _configuration["clientId"],
45-
TokenCachePersistenceOptions = new TokenCachePersistenceOptions()// { UnsafeAllowUnencryptedStorage = true }
45+
TokenCachePersistenceOptions = new TokenCachePersistenceOptions()
4646
};
4747

4848
if (File.Exists(_tokenPath))

MsGraphSamples.Services/GraphExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public static async IAsyncEnumerable<T> Batch<T>(
114114
params RequestInformation[] requests)
115115
where T : IParsable, new()
116116
{
117-
BatchRequestContentCollection batchRequestContent = new(graphClient);
117+
var batchRequestContent = new BatchRequestContentCollection(graphClient);
118118

119-
var addBatchTasks = requests.Select(batchRequestContent.AddBatchRequestStepAsync);
119+
var addBatchTasks = requests.Select(request => batchRequestContent.AddBatchRequestStepAsync(request));
120120
var requestIds = await Task.WhenAll(addBatchTasks);
121121

122122
var batchResponse = await graphClient.Batch.PostAsync(batchRequestContent, cancellationToken, ErrorMappings);

MsGraphSamples.Services/MSGraphSamples.Services.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Azure.Identity" Version="1.12.0" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
14-
<PackageReference Include="Microsoft.Graph" Version="5.56.0" />
12+
<PackageReference Include="Azure.Identity" Version="1.12.1" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
14+
<PackageReference Include="Microsoft.Graph" Version="5.60.0" />
15+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
1516
</ItemGroup>
1617

1718
</Project>

MsGraphSamples.WPF/MsGraphSamples.WPF.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
21-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
22-
<PackageReference Include="Microsoft.Graph" Version="5.56.0" />
23-
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.122" />
20+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
21+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
22+
<PackageReference Include="Microsoft.Graph" Version="5.60.0" />
23+
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

MsGraphSamples.WinUI/App.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
x:Class="MsGraphSamples.WinUI.App"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6-
xmlns:local="using:MsGraphSamples.WinUI">
6+
xmlns:converters="using:CommunityToolkit.WinUI.Converters">
77
<Application.Resources>
88
<ResourceDictionary>
99
<ResourceDictionary.MergedDictionaries>
1010
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
1111
<!-- Other merged dictionaries here -->
1212
</ResourceDictionary.MergedDictionaries>
13+
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
14+
<converters:StringFormatConverter x:Key="StringFormatConverter" />
1315
<!-- Other app resources here -->
1416
</ResourceDictionary>
1517
</Application.Resources>

MsGraphSamples.WinUI/Helpers/Converters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace MsGraphSamples.WinUI.Converters;
77

8-
public class AdditionalDataConverter : IValueConverter
8+
public partial class AdditionalDataConverter : IValueConverter
99
{
1010
public object Convert(object value, Type targetType, object parameter, string language)
1111
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.UI.Xaml;
2+
3+
namespace MsGraphSamples.WinUI.Helpers;
4+
5+
public class Debouncer
6+
{
7+
private readonly DispatcherTimer timer;
8+
private Action? action;
9+
10+
public Debouncer(TimeSpan delay)
11+
{
12+
timer = new DispatcherTimer { Interval = delay };
13+
timer.Tick += Timer_Tick;
14+
}
15+
public void Debounce(Action action)
16+
{
17+
this.action = action;
18+
timer.Stop();
19+
timer.Start();
20+
}
21+
22+
private void Timer_Tick(object? sender, object e)
23+
{
24+
timer.Stop();
25+
action?.Invoke();
26+
}
27+
}

MsGraphSamples.WinUI/MsGraphSamples.WinUI.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
4+
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
55
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
66
<ApplicationManifest>app.manifest</ApplicationManifest>
77
<Platforms>x86;x64;arm64</Platforms>
@@ -12,7 +12,7 @@
1212
<ImplicitUsings>enable</ImplicitUsings>
1313
<Nullable>enable</Nullable>
1414
<PlatformTarget>x64</PlatformTarget>
15-
<SupportedOSPlatformVersion>10.0.22000.0</SupportedOSPlatformVersion>
15+
<SupportedOSPlatformVersion>10.0.26100.0</SupportedOSPlatformVersion>
1616
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
1717
<ApplicationIcon>Assets\MSGraph.ico</ApplicationIcon>
1818
</PropertyGroup>
@@ -30,14 +30,14 @@
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
34-
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.0.240109" />
33+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
34+
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.1.240916" />
3535
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
36-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
37-
<PackageReference Include="Microsoft.Graph" Version="5.56.0" />
38-
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240627000" />
36+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
37+
<PackageReference Include="Microsoft.Graph" Version="5.60.0" />
38+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
3939
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
40-
<PackageReference Include="System.Text.Json" Version="8.0.4" />
40+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
4141
</ItemGroup>
4242

4343
<ItemGroup>

MsGraphSamples.WinUI/Views/MainPage.xaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
7-
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
87
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
98
xmlns:graph="using:Microsoft.Graph.Models"
109
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -13,10 +12,7 @@
1312
Loaded="{x:Bind ViewModel.PageLoaded}"
1413
mc:Ignorable="d">
1514

16-
<Page.Resources>
17-
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
18-
<converters:StringFormatConverter x:Key="StringFormatConverter" />
19-
</Page.Resources>
15+
<Page.Resources />
2016

2117
<Grid Margin="0,28,0,0">
2218
<Grid.RowDefinitions>
@@ -184,14 +180,16 @@
184180
Margin="6"
185181
d:DataContext="{d:DesignInstance Type=graph:User}"
186182
AutoGenerateColumns="False"
183+
DataFetchSize="4"
187184
DoubleTapped="{x:Bind ViewModel.DrillDown}"
188-
Sorting="{x:Bind ViewModel.Sort}"
189185
GridLinesVisibility="Horizontal"
190-
IncrementalLoadingThreshold="0.6"
186+
IncrementalLoadingThreshold="2"
191187
IsReadOnly="True"
192188
ItemsSource="{x:Bind ViewModel.DirectoryObjects, Mode=OneWay}"
193189
SelectedItem="{x:Bind ViewModel.SelectedObject, Mode=TwoWay}"
194-
SelectionMode="Single">
190+
SelectionMode="Single"
191+
SizeChanged="DirectoryObjectsGrid_SizeChanged"
192+
Sorting="{x:Bind ViewModel.Sort}">
195193
<controls:DataGrid.Columns>
196194
<controls:DataGridTextColumn Binding="{Binding Id}" Header="id" />
197195
<controls:DataGridTextColumn Binding="{Binding DisplayName}" Header="displayName" />

MsGraphSamples.WinUI/Views/MainPage.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
using Microsoft.UI.Xaml.Controls;
66
using Microsoft.UI.Xaml.Data;
77
using MsGraphSamples.WinUI.Converters;
8+
using MsGraphSamples.WinUI.Helpers;
89
using MsGraphSamples.WinUI.ViewModels;
910
using System.Collections.Immutable;
11+
using System.Reflection;
12+
using Windows.Foundation;
1013

1114
namespace MsGraphSamples.WinUI.Views;
1215
public sealed partial class MainPage : Page, IRecipient<ImmutableSortedDictionary<string, DataGridSortDirection?>>
1316
{
1417
public MainViewModel ViewModel { get; } = Ioc.Default.GetRequiredService<MainViewModel>();
18+
private readonly Debouncer debouncer = new(TimeSpan.FromMilliseconds(600));
1519

1620
public MainPage()
1721
{
@@ -54,4 +58,26 @@ private void TextBox_SelectAll(object sender, RoutedEventArgs _)
5458
var textBox = (TextBox)sender;
5559
textBox.SelectAll();
5660
}
61+
62+
private void DirectoryObjectsGrid_SizeChanged(object sender, SizeChangedEventArgs e)
63+
{
64+
debouncer.Debounce(SetPageSize);
65+
}
66+
67+
private void SetPageSize()
68+
{
69+
var rowsPresenterAvailableSizeObj = typeof(DataGrid)
70+
.GetField("_rowsPresenterAvailableSize", BindingFlags.NonPublic | BindingFlags.Instance)
71+
?.GetValue(DirectoryObjectsGrid);
72+
73+
var rowHeightEstimateObj = typeof(DataGrid)
74+
.GetProperty("RowHeightEstimate", BindingFlags.NonPublic | BindingFlags.Instance)
75+
?.GetValue(DirectoryObjectsGrid);
76+
77+
if (rowsPresenterAvailableSizeObj is Size rowPresenterSize &&
78+
rowHeightEstimateObj is double rowHeight)
79+
{
80+
ViewModel.PageSize = (ushort)Math.Min(Math.Round(DirectoryObjectsGrid.DataFetchSize * rowPresenterSize.Height / rowHeight), 999);
81+
}
82+
}
5783
}

0 commit comments

Comments
 (0)