Skip to content
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 @@ -43,11 +43,16 @@ static AzureRMCmdlet()
}
}

/// <summary>
/// Creates new instance from AzureRMCmdlet and add the RPRegistration handler.
/// </summary>
public AzureRMCmdlet()
{
AzureSession.ClientFactory.RemoveHandler(typeof(RPRegistrationDelegatingHandler));
AzureSession.ClientFactory.AddHandler(new RPRegistrationDelegatingHandler(
() => AzureSession.ClientFactory.CreateClient<ResourceManagementClient>(DefaultContext, AzureEnvironment.Endpoint.ResourceManager),
() => new ResourceManagementClient(
AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(DefaultContext, AzureEnvironment.Endpoint.ResourceManager),
DefaultContext.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)),
s => _debugMessages.Enqueue(s)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public RPRegistrationDelegatingHandler(Func<ResourceManagementClient> createClie

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
ResourceManagementClient = createClient();

HttpResponseMessage responseMessage = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
if (IsProviderNotRegistereError(responseMessage))
{
Expand All @@ -61,6 +59,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
registeredProviders.Add(providerName);
try
{
ResourceManagementClient = createClient();
writeDebug(string.Format(Resources.ResourceProviderRegisterAttempt, providerName));
ResourceManagementClient.Providers.Register(providerName);
Provider provider = null;
Expand Down