Skip to content

Commit 93018fa

Browse files
authored
Merge branch 'master' into feature/mvvm-preview2
2 parents e7a4824 + 130dbe0 commit 93018fa

File tree

204 files changed

+2130
-2308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+2130
-2308
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
1515
<IsUwpProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Uwp'))</IsUwpProject>
1616
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>
17-
<DefaultTargetPlatformVersion>18362</DefaultTargetPlatformVersion>
18-
<DefaultTargetPlatformMinVersion>16299</DefaultTargetPlatformMinVersion>
17+
<DefaultTargetPlatformVersion>19041</DefaultTargetPlatformVersion>
18+
<DefaultTargetPlatformMinVersion>17763</DefaultTargetPlatformMinVersion>
1919
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\nupkg</PackageOutputPath>
2020
</PropertyGroup>
2121

Directory.Build.targets

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<Choose>
3-
<When Condition="'$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'uap10.0.16299' or '$(TargetFramework)' == 'native' or '$(TargetFramework)' == 'net461'">
3+
<When Condition="'$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'uap10.0.17763' or '$(TargetFramework)' == 'native' or '$(TargetFramework)' == 'net461'">
44
<!-- UAP versions for uap10.0 where TPMV isn't implied -->
55
<PropertyGroup>
66
<TargetPlatformVersion>10.0.$(DefaultTargetPlatformVersion).0</TargetPlatformVersion>
@@ -15,9 +15,6 @@
1515
<SDKReference Condition="'$(UseWindowsDesktopSdk)' == 'true' " Include="WindowsDesktop, Version=$(TargetPlatformVersion)">
1616
<Name>Windows Desktop Extensions for the UWP</Name>
1717
</SDKReference>
18-
<SDKReference Condition="'$(UseWindowsMobileSdk)' == 'true' " Include="WindowsMobile, Version=$(TargetPlatformVersion)">
19-
<Name>Windows Mobile Extensions for the UWP</Name>
20-
</SDKReference>
2118
</ItemGroup>
2219
</When>
2320
</Choose>

GazeInputTest/GazeInputTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AssemblyName>GazeInputTest</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
14-
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
14+
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
1515
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
1616
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
1717
<FileAlignment>512</FileAlignment>

Microsoft.Toolkit.HighPerformance/Helpers/BitHelper.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,68 @@ public static bool HasLookupFlag(uint table, int x, int min = 0)
103103
return valid;
104104
}
105105

106+
/// <summary>
107+
/// Checks whether the given value has any bytes that are set to 0.
108+
/// That is, given a <see cref="uint"/> value, which has a total of 4 bytes,
109+
/// it checks whether any of those have all the bits set to 0.
110+
/// </summary>
111+
/// <param name="value">The input value to check.</param>
112+
/// <returns>Whether <paramref name="value"/> has any bytes set to 0.</returns>
113+
/// <remarks>
114+
/// This method contains no branches.
115+
/// For more background on this subject, see <see href="https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord"/>.
116+
/// </remarks>
117+
[Pure]
118+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
119+
public static bool HasZeroByte(uint value)
120+
{
121+
return ((value - 0x0101_0101u) & ~value & 0x8080_8080u) != 0;
122+
}
123+
124+
/// <summary>
125+
/// Checks whether the given value has any bytes that are set to 0.
126+
/// This method mirrors <see cref="HasZeroByte(uint)"/>, but with <see cref="ulong"/> values.
127+
/// </summary>
128+
/// <param name="value">The input value to check.</param>
129+
/// <returns>Whether <paramref name="value"/> has any bytes set to 0.</returns>
130+
[Pure]
131+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
132+
public static bool HasZeroByte(ulong value)
133+
{
134+
return ((value - 0x0101_0101_0101_0101ul) & ~value & 0x8080_8080_8080_8080ul) != 0;
135+
}
136+
137+
/// <summary>
138+
/// Checks whether a byte in the input <see cref="uint"/> value matches a target value.
139+
/// </summary>
140+
/// <param name="value">The input value to check.</param>
141+
/// <param name="target">The target byte to look for.</param>
142+
/// <returns>Whether <paramref name="value"/> has any bytes set to <paramref name="target"/>.</returns>
143+
/// <remarks>
144+
/// This method contains no branches.
145+
/// For more info, see <see href="https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord"/>.
146+
/// </remarks>
147+
[Pure]
148+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
149+
public static bool HasByteEqualTo(uint value, byte target)
150+
{
151+
return HasZeroByte(value ^ (0x0101_0101u * target));
152+
}
153+
154+
/// <summary>
155+
/// Checks whether a byte in the input <see cref="uint"/> value matches a target value.
156+
/// This method mirrors <see cref="HasByteEqualTo(uint,byte)"/>, but with <see cref="ulong"/> values.
157+
/// </summary>
158+
/// <param name="value">The input value to check.</param>
159+
/// <param name="target">The target byte to look for.</param>
160+
/// <returns>Whether <paramref name="value"/> has any bytes set to <paramref name="target"/>.</returns>
161+
[Pure]
162+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
163+
public static bool HasByteEqualTo(ulong value, byte target)
164+
{
165+
return HasZeroByte(value ^ (0x0101_0101_0101_0101u * target));
166+
}
167+
106168
/// <summary>
107169
/// Sets a bit to a specified value.
108170
/// </summary>

Microsoft.Toolkit.Services/Microsoft.Toolkit.Services.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="MSBuild.Sdk.Extras">
22

33
<PropertyGroup>
4-
<TargetFrameworks>uap10.0.16299;netstandard2.0;NET462</TargetFrameworks>
4+
<TargetFrameworks>uap10.0.17763;netstandard2.0;NET462</TargetFrameworks>
55
<Title>Windows Community Toolkit .NET Standard Services</Title>
66
<Description>
77
This .NET standard library enables access to different data sources such as Microsoft Graph, OneDrive, Twitter, Microsoft Translator, and LinkedIn. It is part of the Windows Community Toolkit.
88
</Description>
99
<PackageTags>UWP Community Toolkit Windows Microsoft Graph OneDrive Twitter Translator LinkedIn service login OAuth</PackageTags>
10-
10+
<LangVersion>8.0</LangVersion>
1111
<NoWarn>CS8002;CS0618</NoWarn>
1212
<DeterministicSourcePaths Condition="'$(EnableSourceLink)' == ''">false</DeterministicSourcePaths>
1313
</PropertyGroup>
1414

15-
<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0.16299'">
15+
<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0.17763'">
1616
<DefineConstants Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">$(DefineConstants);WINRT</DefineConstants>
1717
</PropertyGroup>
1818

@@ -27,11 +27,11 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
30+
<PackageReference Include="System.Text.Json" Version="4.7.2" />
3131
<PackageReference Include="System.Net.Http" Version="4.3.4" />
3232
</ItemGroup>
3333

34-
<ItemGroup Condition="'$(TargetFramework)'=='uap10.0.16299'">
34+
<ItemGroup Condition="'$(TargetFramework)'=='uap10.0.17763'">
3535
<ProjectReference Include="..\Microsoft.Toolkit.Uwp\Microsoft.Toolkit.Uwp.csproj" />
3636
</ItemGroup>
3737

@@ -47,7 +47,7 @@
4747
<PackageReference Include="Microsoft.Toolkit.Forms.UI.Controls.WebView" Version="[5.0.0-preview.gb86cb1c4cb,)" />
4848
</ItemGroup>
4949

50-
<ItemGroup Condition="!('$(TargetFramework)'=='uap10.0.16299')">
50+
<ItemGroup Condition="!('$(TargetFramework)'=='uap10.0.17763')">
5151
<Compile Remove="PlatformSpecific\Uwp\**\*" />
5252
</ItemGroup>
53-
</Project>
53+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
3+
<Library Name="Microsoft.Toolkit.Services">
4+
<Namespace Name="System.Text.Json.Serialization.Converters" Dynamic="Required All"/>
5+
</Library>
6+
</Directives>

Microsoft.Toolkit.Services/Services/LinkedIn/LinkedInDataProvider.cs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
using System.Diagnostics;
88
using System.Net.Http;
99
using System.Text;
10+
using System.Text.Json;
1011
using System.Threading.Tasks;
1112
using Microsoft.Toolkit.Services.Core;
12-
using Newtonsoft.Json.Linq;
1313

1414
#if WINRT
1515
using Microsoft.Toolkit.Services.PlatformSpecific.Uwp;
@@ -81,7 +81,8 @@ public LinkedInDataProvider(LinkedInOAuthTokens tokens, LinkedInPermissions requ
8181
throw new ArgumentException("Missing callback uri");
8282
}
8383

84-
if (!Enum.IsDefined(typeof(LinkedInPermissions), requiredPermissions))
84+
// Check if its a valid combination of LinkedInPermissions
85+
if ((~(int)LinkedInPermissionsHelpers.AllPermissions & (int)requiredPermissions) != 0)
8586
{
8687
throw new ArgumentException("Error retrieving required permissions");
8788
}
@@ -186,22 +187,18 @@ public async Task<IEnumerable<TSchema>> GetDataAsync<TSchema>(LinkedInDataConfig
186187

187188
var url = $"{_baseUrl}{config.Query}/~:({fields})?oauth2_access_token={Tokens.AccessToken}&format=json&count={maxRecords}&start={startRecord}";
188189

189-
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(url)))
190-
{
191-
request.Headers.Connection.TryParseAdd("Keep-Alive");
192-
193-
using (var response = await client.SendAsync(request).ConfigureAwait(false))
194-
{
195-
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
190+
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
191+
request.Headers.Connection.TryParseAdd("Keep-Alive");
196192

197-
if (response.IsSuccessStatusCode && !string.IsNullOrEmpty(data))
198-
{
199-
return parser.Parse(data);
200-
}
193+
using var response = await client.SendAsync(request).ConfigureAwait(false);
194+
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
201195

202-
throw new RequestFailedException((System.Net.HttpStatusCode)response.StatusCode, data);
203-
}
196+
if (response.IsSuccessStatusCode && !string.IsNullOrEmpty(data))
197+
{
198+
return parser.Parse(data);
204199
}
200+
201+
throw new RequestFailedException((System.Net.HttpStatusCode)response.StatusCode, data);
205202
}
206203

207204
/// <summary>
@@ -222,22 +219,18 @@ public async Task<U> ShareDataAsync<T, U>(T dataToShare)
222219

223220
var url = $"{_baseUrl}/people/~/shares?oauth2_access_token={Tokens.AccessToken}&format=json";
224221

225-
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url)))
226-
{
227-
request.Headers.Add("x-li-format", "json");
228-
var stringContent = requestParser.Parse(shareRequest);
229-
request.Content = new StringContent(stringContent, Encoding.UTF8, "application/json");
222+
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
223+
request.Headers.Add("x-li-format", "json");
224+
var stringContent = requestParser.Parse(shareRequest);
225+
request.Content = new StringContent(stringContent, Encoding.UTF8, "application/json");
230226

231-
using (var response = await client.SendAsync(request).ConfigureAwait(false))
232-
{
233-
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
227+
using var response = await client.SendAsync(request).ConfigureAwait(false);
228+
var data = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
234229

235-
var responseParser = new LinkedInParser<U>();
230+
var responseParser = new LinkedInParser<U>();
236231

237-
var listResults = responseParser.Parse(data) as List<U>;
238-
return listResults[0];
239-
}
240-
}
232+
var listResults = responseParser.Parse(data) as List<U>;
233+
return listResults[0];
241234
}
242235

243236
return default(U);
@@ -263,15 +256,13 @@ private async Task<string> GetAccessTokenAsync(LinkedInOAuthTokens tokens, strin
263256
+ "&client_id=" + tokens.ClientId
264257
+ "&client_secret=" + tokens.ClientSecret;
265258

266-
using (var request = new HttpRequestMessage(HttpMethod.Post, new Uri(url)))
267-
{
268-
using (var response = await client.SendAsync(request).ConfigureAwait(false))
269-
{
270-
var jsonString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
271-
var json = JObject.Parse(jsonString);
272-
return json.GetValue("access_token").Value<string>();
273-
}
274-
}
259+
using var request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
260+
using var response = await client.SendAsync(request).ConfigureAwait(false);
261+
using var jsonStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
262+
using var jsonDoc = await JsonDocument.ParseAsync(jsonStream).ConfigureAwait(false);
263+
264+
var value = jsonDoc.RootElement.GetProperty("access_token");
265+
return value.GetString();
275266
}
276267

277268
private async Task<string> GetAuthorizeCodeAsync(LinkedInOAuthTokens tokens, LinkedInPermissions permissions)

Microsoft.Toolkit.Services/Services/LinkedIn/LinkedInParser.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
6-
using Newtonsoft.Json;
6+
using System.Text.Json;
77

88
namespace Microsoft.Toolkit.Services.LinkedIn
99
{
@@ -24,11 +24,11 @@ public IEnumerable<T> Parse(string data)
2424

2525
try
2626
{
27-
results = JsonConvert.DeserializeObject<List<T>>(data);
27+
results = JsonSerializer.Deserialize<List<T>>(data);
2828
}
29-
catch (JsonSerializationException)
29+
catch (JsonException)
3030
{
31-
T linkedInResult = JsonConvert.DeserializeObject<T>(data);
31+
T linkedInResult = JsonSerializer.Deserialize<T>(data);
3232
results = new List<T> { linkedInResult };
3333
}
3434

@@ -42,7 +42,7 @@ public IEnumerable<T> Parse(string data)
4242
/// <returns>Returns string data.</returns>
4343
public string Parse(T dataToShare)
4444
{
45-
return JsonConvert.SerializeObject(dataToShare, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
45+
return JsonSerializer.Serialize(dataToShare, typeof(T), new JsonSerializerOptions { IgnoreNullValues = true });
4646
}
4747
}
4848
}

Microsoft.Toolkit.Services/Services/LinkedIn/LinkedInPermissions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ public enum LinkedInPermissions
3737
/// </summary>
3838
WriteShare = 8
3939
}
40+
41+
#pragma warning disable SA1649 // File name should match first type name
42+
internal static class LinkedInPermissionsHelpers
43+
{
44+
/// <summary>
45+
/// Internal AllPermissions for LinkedInPermissions, so we don't expose it. Keep it in sync with <see cref="LinkedInPermissions"/>
46+
/// </summary>
47+
internal const LinkedInPermissions AllPermissions =
48+
LinkedInPermissions.ReadBasicProfile |
49+
LinkedInPermissions.ReadEmailAddress |
50+
LinkedInPermissions.ReadWriteCompanyAdmin |
51+
LinkedInPermissions.WriteShare;
52+
}
53+
#pragma warning restore SA1649 // File name should match first type name
4054
}

Microsoft.Toolkit.Services/Services/MicrosoftTranslator/AzureAuthToken.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
using System;
66
using System.Net.Http;
7+
using System.Text.Json;
78
using System.Threading.Tasks;
8-
using Newtonsoft.Json;
99

1010
namespace Microsoft.Toolkit.Services.MicrosoftTranslator
1111
{
@@ -24,6 +24,9 @@ internal class AzureAuthToken
2424
/// </summary>
2525
private static readonly Uri ServiceUrl = new Uri("https://api.cognitive.microsoft.com/sts/v1.0/issueToken");
2626

27+
// TODO
28+
// private static readonly Uri ServiceUrl = new Uri(THIS SHOULD BE A PARAMETER NOW);
29+
2730
/// <summary>
2831
/// After obtaining a valid token, this class will cache it for this duration.
2932
/// Use a duration of 8 minutes, which is less than the actual token lifetime of 10 minutes.
@@ -90,24 +93,22 @@ public async Task<string> GetAccessTokenAsync()
9093
return _storedTokenValue;
9194
}
9295

93-
using (var request = new HttpRequestMessage(HttpMethod.Post, ServiceUrl))
94-
{
95-
request.Headers.Add(OcpApimSubscriptionKeyHeader, SubscriptionKey);
96+
using var request = new HttpRequestMessage(HttpMethod.Post, ServiceUrl);
97+
request.Headers.Add(OcpApimSubscriptionKeyHeader, SubscriptionKey);
9698

97-
var response = await client.SendAsync(request).ConfigureAwait(false);
98-
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
99+
var response = await client.SendAsync(request).ConfigureAwait(false);
100+
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
99101

100-
if (!response.IsSuccessStatusCode)
101-
{
102-
var error = JsonConvert.DeserializeObject<ErrorResponse>(content);
103-
throw new TranslatorServiceException(error.Message);
104-
}
102+
if (!response.IsSuccessStatusCode)
103+
{
104+
var error = JsonSerializer.Deserialize<ErrorResponse>(content);
105+
throw new TranslatorServiceException(error?.Error?.Message);
106+
}
105107

106-
_storedTokenTime = DateTime.Now;
107-
_storedTokenValue = $"Bearer {content}";
108+
_storedTokenTime = DateTime.Now;
109+
_storedTokenValue = $"Bearer {content}";
108110

109-
return _storedTokenValue;
110-
}
111+
return _storedTokenValue;
111112
}
112113
}
113114
}

0 commit comments

Comments
 (0)