Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class EnterpriseServerPATPage : LoginUIPage
public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString inputPAT)
: base(LoginUIState.EnterpriseServerPATPage)
{
Data = new PageData()
Data = new EnterpriseServerPATPageData()
{
EnterpriseServerPATPageInputValue = new System.Net.NetworkCredential(string.Empty, inputPAT).Password ?? string.Empty,
EnterpriseServerPATPageErrorValue = errorText ?? string.Empty,
Expand All @@ -22,7 +22,7 @@ public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString i
};
}

internal sealed class PageData : ILoginUIPageData
internal sealed class EnterpriseServerPATPageData : ILoginUIPageData
{
public string EnterpriseServerPATPageInputValue { get; set; } = string.Empty;

Expand All @@ -36,7 +36,7 @@ internal sealed class PageData : ILoginUIPageData

public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class EnterpriseServerPage : LoginUIPage
public EnterpriseServerPage(Uri? hostAddress, string errorText)
: base(LoginUIState.EnterpriseServerPage)
{
Data = new PageData()
Data = new EnterpriseServerPageData()
{
EnterpriseServerInputValue = hostAddress?.ToString() ?? string.Empty,
EnterpriseServerPageErrorValue = errorText ?? string.Empty,
Expand All @@ -21,15 +21,15 @@ public EnterpriseServerPage(Uri? hostAddress, string errorText)
public EnterpriseServerPage(string hostAddress, string errorText)
: base(LoginUIState.EnterpriseServerPage)
{
Data = new PageData()
Data = new EnterpriseServerPageData()
{
EnterpriseServerInputValue = hostAddress,
EnterpriseServerPageErrorValue = errorText ?? string.Empty,
EnterpriseServerPageErrorVisible = !string.IsNullOrEmpty(errorText),
};
}

internal sealed class PageData : ILoginUIPageData
internal sealed class EnterpriseServerPageData : ILoginUIPageData
{
public string EnterpriseServerInputValue { get; set; } = string.Empty;

Expand All @@ -40,7 +40,7 @@ internal sealed class PageData : ILoginUIPageData

public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;
using static GitHubExtension.DeveloperId.LoginUI.EnterpriseServerPage;
using static GitHubExtension.DeveloperId.LoginUI.EnterpriseServerPATPage;
using static GitHubExtension.DeveloperId.LoginUI.LoginFailedPage;
using static GitHubExtension.DeveloperId.LoginUI.LoginPage;
using static GitHubExtension.DeveloperId.LoginUI.LoginSucceededPage;
using static GitHubExtension.DeveloperId.LoginUI.WaitingPage;

namespace GitHubExtension.DeveloperId;

[JsonSerializable(typeof(EnterpriseServerPageData))]
[JsonSerializable(typeof(EnterpriseServerPATPageData))]
[JsonSerializable(typeof(LoginFailedPageData))]
[JsonSerializable(typeof(LoginPageData))]
[JsonSerializable(typeof(LoginSucceededPageData))]
[JsonSerializable(typeof(WaitingPageData))]
internal sealed partial class JsonSourceGenerationContext : JsonSerializerContext
{
}
2 changes: 1 addition & 1 deletion src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class LoginFailedPageData : ILoginUIPageData
{
public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}
}
6 changes: 3 additions & 3 deletions src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ internal sealed class LoginPage : LoginUIPage
public LoginPage()
: base(LoginUIState.LoginPage)
{
Data = new PageData();
Data = new LoginPageData();
}

internal sealed class PageData : ILoginUIPageData
internal sealed class LoginPageData : ILoginUIPageData
{
public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class LoginSucceededPageData : ILoginUIPageData

public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}
}
10 changes: 10 additions & 0 deletions src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;
using System.Text.Json.Serialization;
using GitHubExtension.Helpers;
using Microsoft.Windows.DevHome.SDK;

Expand All @@ -12,6 +14,14 @@ internal class LoginUIPage
private readonly LoginUIState _state;
private ILoginUIPageData? _data;

public static readonly JsonSerializerOptions _optionsWithContext = new()
{
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
IncludeFields = true,
TypeInfoResolver = JsonSourceGenerationContext.Default,
};

public interface ILoginUIPageData
{
public abstract string GetJson();
Expand Down
2 changes: 1 addition & 1 deletion src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class WaitingPageData : ILoginUIPageData
{
public string GetJson()
{
return Json.Stringify(this);
return Json.Stringify(this, _optionsWithContext);
}
}
}
4 changes: 2 additions & 2 deletions src/GitHubExtension/Helpers/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public static async Task<string> StringifyAsync<T>(T value)
});
}

public static string Stringify<T>(T value)
public static string Stringify<T>(T value, JsonSerializerOptions? options = null)
{
if (typeof(T) == typeof(bool))
{
return value!.ToString()!.ToLowerInvariant();
}

return System.Text.Json.JsonSerializer.Serialize(value, _options);
return System.Text.Json.JsonSerializer.Serialize(value, options ?? _options);
}

public static T? ToObject<T>(string json)
Expand Down