-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templates): improve project templates request pipeline + other s…
- Loading branch information
Showing
62 changed files
with
947 additions
and
242 deletions.
There are no files selected for viewing
This file contains 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 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
46 changes: 24 additions & 22 deletions
46
src/Templates/AdminPanel/Bit.AdminPanel/src/Client/Core/App.razor
This file contains 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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<Router AppAssembly="@GetType().Assembly" | ||
AdditionalAssemblies="@([Assembly.Load(BlazorModeDetector.Current.IsBlazorHybrid() ? "AdminPanel.Client.App" : "AdminPanel.Client.Web")])" | ||
OnNavigateAsync="@OnNavigateAsync"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData"> | ||
<NotAuthorized> | ||
<NotAuthorizedComponent /> | ||
</NotAuthorized> | ||
<Authorizing> | ||
<LoadingComponent Color="#002A66" /> | ||
</Authorizing> | ||
</AuthorizeRouteView> | ||
</Found> | ||
<NotFound> | ||
<PageNotFound /> | ||
</NotFound> | ||
<Navigating> | ||
<LoadingComponent Color="#002A66" /> | ||
</Navigating> | ||
</Router> | ||
</LayoutView> | ||
<CascadingAuthenticationState> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<Router AppAssembly="@GetType().Assembly" | ||
AdditionalAssemblies="@([Assembly.Load(BlazorModeDetector.Current.IsBlazorHybrid() ? "AdminPanel.Client.App" : "AdminPanel.Client.Web")])" | ||
OnNavigateAsync="@OnNavigateAsync"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData"> | ||
<NotAuthorized> | ||
<NotAuthorizedComponent /> | ||
</NotAuthorized> | ||
<Authorizing> | ||
<LoadingComponent Color="#002A66" /> | ||
</Authorizing> | ||
</AuthorizeRouteView> | ||
</Found> | ||
<NotFound> | ||
<PageNotFound /> | ||
</NotFound> | ||
<Navigating> | ||
<LoadingComponent Color="#002A66" /> | ||
</Navigating> | ||
</Router> | ||
</LayoutView> | ||
</CascadingAuthenticationState> |
12 changes: 12 additions & 0 deletions
12
...s/AdminPanel/Bit.AdminPanel/src/Client/Core/Extensions/IConfigurationBuilderExtensions.cs
This file contains 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,12 @@ | ||
using System.Reflection; | ||
|
||
namespace Microsoft.Extensions.Configuration; | ||
|
||
public static class IConfigurationBuilderExtensions | ||
{ | ||
public static void AddClientConfigurations(this IConfigurationBuilder builder) | ||
{ | ||
var assembly = Assembly.Load("AdminPanel.Client.Core"); | ||
builder.AddJsonStream(assembly.GetManifestResourceStream("AdminPanel.Client.Core.appsettings.json")!); | ||
} | ||
} |
This file contains 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 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
47 changes: 47 additions & 0 deletions
47
...anel/Bit.AdminPanel/src/Client/Core/Services/HttpMessageHandlers/AuthDelegatingHandler.cs
This file contains 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,47 @@ | ||
using System.Net.Http.Headers; | ||
|
||
namespace AdminPanel.Client.Core.Services.HttpMessageHandlers; | ||
|
||
public class AuthDelegatingHandler | ||
: DelegatingHandler | ||
{ | ||
private IAuthTokenProvider _tokenProvider = default!; | ||
private IJSRuntime _jsRuntime = default!; | ||
|
||
public AuthDelegatingHandler(IAuthTokenProvider tokenProvider, IJSRuntime jsRuntime, RetryDelegatingHandler handler) | ||
: base(handler) | ||
{ | ||
_tokenProvider = tokenProvider; | ||
_jsRuntime = jsRuntime; | ||
} | ||
|
||
public AuthDelegatingHandler(IAuthTokenProvider tokenProvider, IJSRuntime jsRuntime) | ||
: base() | ||
{ | ||
_tokenProvider = tokenProvider; | ||
_jsRuntime = jsRuntime; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
if (request.Headers.Authorization is null) | ||
{ | ||
var access_token = await _tokenProvider.GetAccessTokenAsync(); | ||
if (access_token is not null) | ||
{ | ||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", access_token); | ||
} | ||
} | ||
|
||
try | ||
{ | ||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
catch (UnauthorizedException) | ||
{ | ||
// try to get refresh token, store access token and refresh token, | ||
// then use the new access token to request's authorization header and call base.SendAsync again. | ||
throw; | ||
} | ||
} | ||
} |
This file contains 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
28 changes: 28 additions & 0 deletions
28
....AdminPanel/src/Client/Core/Services/HttpMessageHandlers/LocalizationDelegatingHandler.cs
This file contains 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,28 @@ | ||
using System.Net.Http.Headers; | ||
|
||
namespace AdminPanel.Client.Core.Services.HttpMessageHandlers; | ||
|
||
public class LocalizationDelegatingHandler | ||
: DelegatingHandler | ||
{ | ||
public LocalizationDelegatingHandler(AuthDelegatingHandler handler) | ||
: base(handler) | ||
{ | ||
|
||
} | ||
|
||
public LocalizationDelegatingHandler() | ||
{ | ||
|
||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
#if MultilingualEnabled | ||
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(CultureInfo.CurrentCulture.Name)); | ||
#endif | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
...nel/Bit.AdminPanel/src/Client/Core/Services/HttpMessageHandlers/RetryDelegatingHandler.cs
This file contains 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,55 @@ | ||
namespace AdminPanel.Client.Core.Services.HttpMessageHandlers; | ||
|
||
public class RetryDelegatingHandler | ||
: DelegatingHandler | ||
{ | ||
public RetryDelegatingHandler(ExceptionDelegatingHandler handler) | ||
: base(handler) | ||
{ | ||
|
||
} | ||
|
||
public RetryDelegatingHandler() | ||
{ | ||
|
||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var delays = GetDelays(scaleFirstTry: TimeSpan.FromSeconds(3), maxRetries: 3).ToArray(); | ||
|
||
Exception? lastExp = null; | ||
|
||
foreach (var delay in delays) | ||
{ | ||
try | ||
{ | ||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
catch (Exception exp) when (exp is not KnownException) | ||
{ | ||
lastExp = exp; | ||
await Task.Delay(delay, cancellationToken); | ||
} | ||
} | ||
|
||
throw lastExp!; | ||
} | ||
|
||
private static IEnumerable<TimeSpan> GetDelays(TimeSpan scaleFirstTry, int maxRetries) | ||
{ | ||
TimeSpan maxValue = TimeSpan.MaxValue; | ||
var maxTimeSpanDouble = maxValue.Ticks - 1_000.0; | ||
var i = 0; | ||
var targetTicksFirstDelay = scaleFirstTry.Ticks; | ||
var num = 0.0; | ||
for (; i < maxRetries; i++) | ||
{ | ||
var num2 = i + Random.Shared.NextDouble(); | ||
var next = Math.Pow(2.0, num2) * Math.Tanh(Math.Sqrt(4.0 * num2)); | ||
var num3 = next - num; | ||
yield return TimeSpan.FromTicks((long)Math.Min(num3 * 0.7_142_857_142_857_143 * targetTicksFirstDelay, maxTimeSpanDouble)); | ||
num = next; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.