Skip to content

Instantly share code, notes, and snippets.

var policy = HttpPolicyExtensions
.HandleTransientHttpError()
.RetryAsync(10, (ex, count) =>
{
Console.WriteLine($"Polly: error during call, retry n. {count}");
});
// this is an example of registering a typed client
services.AddHttpClient<WeatherClient>(h =>
{
// this is an example of registering a typed client
services.AddHttpClient<WeatherClient>(h =>
{
h.BaseAddress = new Uri("https://someOtherDomain.com/");
})
.ConfigurePrimaryHttpMessageHandler(sp =>
(HttpMessageHandler)sp.GetService(MonoWasmHttpMessageHandlerType));
public class WeatherClient
{
private HttpClient _client;
public WeatherClient(HttpClient client)
{
_client = client;
}
public async Task<WeatherForecast[]> GetForecastsAsync()
public void ConfigureServices(IServiceCollection services)
{
// let's remove the current entry for HttpClient first
var httpSvc = services
.Single(x => x.ServiceType == typeof(HttpClient));
services.Remove(httpSvc);
// we add the WasmHttpMessageHandler
Type MonoWasmHttpMessageHandlerType = Assembly.Load("WebAssembly.Net.Http")
.GetType("WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler");
<ItemGroup>
<!-- other references here... -->
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0-preview2.19525.4" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.0-preview2.19525.4" />
</ItemGroup>
public class MsalAuthenticationStateProvider : AuthenticationStateProvider
{
// more code here
public async Task SignInAsync()
{
await _js.InvokeVoidAsync("azuread.signIn");
await AuthenticationChanged();
}
public class MsalAuthenticationStateProvider : AuthenticationStateProvider
{
private IJSRuntime _js;
public MsalAuthenticationStateProvider(IJSRuntime js)
{
_js = js;
}
public async override Task<AuthenticationState> GetAuthenticationStateAsync()
function AzureAd() {
AzureAd.prototype.initialize = function (msalConfig) {
this.msalObj = new Msal.UserAgentApplication(msalConfig);
};
AzureAd.prototype.signIn = function () {
return this.msalObj.loginPopup();
};
AzureAd.prototype.signOut = function () {
#Calculate date threshold
$threshold = (Get-Date).ToUniversalTime().AddDays(-30)
Write-Output "Deleting deployments older than $threshold"
#Get all deployments older than the threshold
$deployments = Get-AzureRmResourceGroup | `
Get-AzureRmResourceGroupDeployment | `
Where-Object{$_.Timestamp.Date -lt $threshold}
@cradle77
cradle77 / wkf.ps1
Created August 18, 2019 18:37
Powershell Workflow
workflow Deployment-Cleanup-Wkf
{
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `