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
23 changes: 0 additions & 23 deletions DevHomeAzureExtension.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{A371
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureExtension.Test", "test\AzureExtension\AzureExtension.Test.csproj", "{D8EFDB34-7019-4807-AE97-1B50891F345D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevHome.Logging", "src\Logging\DevHome.Logging.csproj", "{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E4D6AB24-08F6-4352-9BB8-8E92148DA618}"
ProjectSection(SolutionItems) = preProject
test\scripts\CleanDevHome.ps1 = test\scripts\CleanDevHome.ps1
Expand Down Expand Up @@ -172,26 +170,6 @@ Global
{D8EFDB34-7019-4807-AE97-1B50891F345D}.Release|x64.Build.0 = Release|x64
{D8EFDB34-7019-4807-AE97-1B50891F345D}.Release|x86.ActiveCfg = Release|x86
{D8EFDB34-7019-4807-AE97-1B50891F345D}.Release|x86.Build.0 = Release|x86
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|Any CPU.ActiveCfg = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|Any CPU.Build.0 = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|ARM.ActiveCfg = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|ARM.Build.0 = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|arm64.ActiveCfg = Debug|arm64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|arm64.Build.0 = Debug|arm64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|x64.ActiveCfg = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|x64.Build.0 = Debug|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|x86.ActiveCfg = Debug|x86
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Debug|x86.Build.0 = Debug|x86
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|Any CPU.ActiveCfg = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|Any CPU.Build.0 = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|ARM.ActiveCfg = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|ARM.Build.0 = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|arm64.ActiveCfg = Release|arm64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|arm64.Build.0 = Release|arm64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|x64.ActiveCfg = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|x64.Build.0 = Release|x64
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|x86.ActiveCfg = Release|x86
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -203,7 +181,6 @@ Global
{8E1764CB-2FFC-4F23-9FC0-BDE84E519319} = {5BDF2709-4299-49C3-B971-B10747F2925D}
{A371A158-E88C-48D1-9397-22844DDC2EF4} = {10E87373-ADA7-408F-9879-0F6BF101BE87}
{D8EFDB34-7019-4807-AE97-1B50891F345D} = {429CEDBA-88C4-4315-9EA1-50AB6DF8855C}
{FEEEDA62-F746-4160-A3A8-1EE74137F8AB} = {5BDF2709-4299-49C3-B971-B10747F2925D}
{E4D6AB24-08F6-4352-9BB8-8E92148DA618} = {429CEDBA-88C4-4315-9EA1-50AB6DF8855C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
4 changes: 3 additions & 1 deletion src/AzureExtension/AzureExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Windows.DevHome.SDK;
using Serilog;

namespace DevHomeAzureExtension;

Expand All @@ -18,6 +19,7 @@ public sealed class AzureExtension : IExtension
{
private readonly ManualResetEvent _extensionDisposedEvent;
private readonly IHost _host;
private readonly ILogger _log = Log.ForContext("SourceContext", nameof(AzureExtension));

public AzureExtension(ManualResetEvent extensionDisposedEvent, IHost host)
{
Expand All @@ -38,7 +40,7 @@ public AzureExtension(ManualResetEvent extensionDisposedEvent, IHost host)
case ProviderType.ComputeSystem:
return _host.Services.GetService<DevBoxProvider>();
default:
Providers.Log.Logger()?.ReportInfo("Invalid provider");
_log.Information($"Invalid provider: {providerType}");
return null;
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/AzureExtension/AzureExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="16.205.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Logging\DevHome.Logging.csproj" />
<ProjectReference Include="..\Telemetry\AzureExtension.Telemetry.csproj" />
</ItemGroup>

Expand Down
11 changes: 7 additions & 4 deletions src/AzureExtension/Client/AzureClientHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
using Serilog;

namespace DevHomeAzureExtension.Client;

Expand All @@ -14,6 +15,7 @@ public class AzureClientHelpers
// about it from the server.
public static InfoResult GetQueryInfo(AzureUri azureUri, DeveloperId.DeveloperId devId)
{
var log = Log.ForContext("SourceContext", nameof(InfoResult));
if (devId == null)
{
return new InfoResult(azureUri, InfoType.Query, ResultType.Failure, ErrorType.NullDeveloperId);
Expand Down Expand Up @@ -55,12 +57,12 @@ public static InfoResult GetQueryInfo(AzureUri azureUri, DeveloperId.DeveloperId
{
if (ex.InnerException is VssResourceNotFoundException)
{
Log.Logger()?.ReportError($"Vss Resource Not Found for {azureUri}", ex);
log.Error($"Vss Resource Not Found for {azureUri}", ex);
return new InfoResult(azureUri, InfoType.Query, ResultType.Failure, ErrorType.VssResourceNotFound, ex);
}
else
{
Log.Logger()?.ReportError($"Failed getting query info for: {azureUri}", ex);
log.Error($"Failed getting query info for: {azureUri}", ex);
return new InfoResult(azureUri, InfoType.Query, ResultType.Failure, ErrorType.Unknown, ex);
}
}
Expand All @@ -81,6 +83,7 @@ public static InfoResult GetQueryInfo(Uri uri, DeveloperId.DeveloperId devId)
// about the target repository from the server.
public static InfoResult GetRepositoryInfo(AzureUri azureUri, DeveloperId.DeveloperId devId)
{
var log = Log.ForContext("SourceContext", nameof(InfoResult));
if (devId == null)
{
return new InfoResult(azureUri, InfoType.Repository, ResultType.Failure, ErrorType.NullDeveloperId);
Expand Down Expand Up @@ -122,12 +125,12 @@ public static InfoResult GetRepositoryInfo(AzureUri azureUri, DeveloperId.Develo
{
if (ex.InnerException is VssResourceNotFoundException)
{
Log.Logger()?.ReportError($"Vss Resource Not Found for {azureUri}", ex);
log.Error($"Vss Resource Not Found for {azureUri}", ex);
return new InfoResult(azureUri, InfoType.Repository, ResultType.Failure, ErrorType.VssResourceNotFound, ex);
}
else
{
Log.Logger()?.ReportError($"Failed getting repository info for: {azureUri}", ex);
log.Error($"Failed getting repository info for: {azureUri}", ex);
return new InfoResult(azureUri, InfoType.Repository, ResultType.Failure, ErrorType.Unknown, ex);
}
}
Expand Down
57 changes: 31 additions & 26 deletions src/AzureExtension/Client/AzureClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
using Microsoft.Identity.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Serilog;

namespace DevHomeAzureExtension.Client;

public class AzureClientProvider
{
private static readonly Lazy<ILogger> _log = new(() => Serilog.Log.ForContext("SourceContext", nameof(AzureClientProvider)));

private static readonly ILogger Log = _log.Value;

private static VssConnection? CreateConnection(Uri uri, DeveloperId.DeveloperId developerId)
{
var azureUri = new AzureUri(uri);
if (!azureUri.IsValid)
{
Log.Logger()?.ReportInfo($"Cannot Create Connection: invalid uri argument value i.e. {uri}");
Log.Information($"Cannot Create Connection: invalid uri argument value i.e. {uri}");
return null;
}

if (developerId == null)
{
Log.Logger()?.ReportInfo($"Cannot Create Connection: null developer id argument");
Log.Information($"Cannot Create Connection: null developer id argument");
return null;
}

Expand All @@ -33,41 +38,41 @@ public class AzureClientProvider

if (credentials == null)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId");
Log.Error($"Unable to get credentials for developerId");
return null;
}
}
catch (MsalUiRequiredException ex)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId failed and requires user interaction {ex}");
Log.Error($"Unable to get credentials for developerId failed and requires user interaction {ex}");
return null;
}
catch (MsalServiceException ex)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId: failed with MSAL service error: {ex}");
Log.Error($"Unable to get credentials for developerId: failed with MSAL service error: {ex}");
return null;
}
catch (MsalClientException ex)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId: failed with MSAL client error: {ex}");
Log.Error($"Unable to get credentials for developerId: failed with MSAL client error: {ex}");
return null;
}
catch (Exception ex)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId {ex}");
Log.Error($"Unable to get credentials for developerId {ex}");
return null;
}

var connection = new VssConnection(azureUri.Connection, credentials);
if (connection != null)
{
Log.Logger()?.ReportInfo($"Connection created for developer id");
Log.Debug($"Connection created for developer id");
return connection;
}
}
catch (Exception ex)
{
Log.Logger()?.ReportError($"Failed creating connection for developer id and {uri} with exception:", ex);
Log.Error($"Failed creating connection for developer id and {uri} with exception:", ex);
}

return null;
Expand All @@ -78,13 +83,13 @@ public static ConnectionResult CreateVssConnection(Uri uri, DeveloperId.Develope
var azureUri = new AzureUri(uri);
if (!azureUri.IsValid)
{
Log.Logger()?.ReportInfo($"Cannot Create Connection: invalid uri argument value i.e. {uri}");
Log.Information($"Cannot Create Connection: invalid uri argument value i.e. {uri}");
return new ConnectionResult(ResultType.Failure, ErrorType.InvalidArgument, false);
}

if (developerId == null)
{
Log.Logger()?.ReportInfo($"Cannot Create Connection: invalid developer id argument");
Log.Information($"Cannot Create Connection: invalid developer id argument");
return new ConnectionResult(ResultType.Failure, ErrorType.InvalidArgument, false);
}

Expand All @@ -94,28 +99,28 @@ public static ConnectionResult CreateVssConnection(Uri uri, DeveloperId.Develope
credentials = developerId.GetCredentials();
if (credentials == null)
{
Log.Logger()?.ReportError($"Unable to get credentials for developerId");
Log.Error($"Unable to get credentials for developerId");
return new ConnectionResult(ResultType.Failure, ErrorType.InvalidDeveloperId, false);
}
}
catch (MsalUiRequiredException ex)
{
Log.Logger()?.ReportError($"AcquireDeveloperAccountToken failed and requires user interaction {ex}");
Log.Error($"AcquireDeveloperAccountToken failed and requires user interaction {ex}");
return new ConnectionResult(ResultType.Failure, ErrorType.CredentialUIRequired, false, ex);
}
catch (MsalServiceException ex)
{
Log.Logger()?.ReportError($"AcquireDeveloperAccountToken failed with MSAL service error: {ex}");
Log.Error($"AcquireDeveloperAccountToken failed with MSAL service error: {ex}");
return new ConnectionResult(ResultType.Failure, ErrorType.MsalServiceError, false, ex);
}
catch (MsalClientException ex)
{
Log.Logger()?.ReportError($"AcquireDeveloperAccountToken failed with MSAL client error: {ex}");
Log.Error($"AcquireDeveloperAccountToken failed with MSAL client error: {ex}");
return new ConnectionResult(ResultType.Failure, ErrorType.MsalClientError, false, ex);
}
catch (Exception ex)
{
Log.Logger()?.ReportError($"AcquireDeveloperAccountToken failed with error: {ex}");
Log.Error($"AcquireDeveloperAccountToken failed with error: {ex}");
return new ConnectionResult(ResultType.Failure, ErrorType.GenericCredentialFailure, true);
}

Expand All @@ -129,18 +134,18 @@ public static ConnectionResult CreateVssConnection(Uri uri, DeveloperId.Develope

if (connection != null)
{
Log.Logger()?.ReportInfo($"Created new connection to {azureUri.Connection} for {developerId.LoginId}");
Log.Debug($"Created new connection to {azureUri.Connection} for {developerId.LoginId}");
return new ConnectionResult(azureUri.Connection, null, connection);
}
else
{
Log.Logger()?.ReportError($"Connection to {azureUri.Connection} was null.");
Log.Error($"Connection to {azureUri.Connection} was null.");
return new ConnectionResult(ResultType.Failure, ErrorType.NullConnection, false);
}
}
catch (Exception ex)
{
Log.Logger()?.ReportError($"Unable to establish VssConnection: {ex}");
Log.Error($"Unable to establish VssConnection: {ex}");
return new ConnectionResult(ResultType.Failure, ErrorType.InitializeVssConnectionFailure, true, ex);
}
}
Expand All @@ -159,20 +164,20 @@ public static VssConnection GetConnectionForLoggedInDeveloper(Uri uri, Developer
var azureUri = new AzureUri(uri);
if (!azureUri.IsValid)
{
Log.Logger()?.ReportError($"Uri is an invalid Azure Uri: {uri}");
Log.Error($"Uri is an invalid Azure Uri: {uri}");
throw new ArgumentException(uri.ToString());
}

if (developerId == null)
{
Log.Logger()?.ReportError($"No logged in developer for which connection needs to be retrieved");
Log.Error($"No logged in developer for which connection needs to be retrieved");
throw new ArgumentNullException(null);
}

var connection = CreateConnection(azureUri.Connection, developerId);
if (connection == null)
{
Log.Logger()?.ReportError($"Failed creating connection for developer id");
Log.Error($"Failed creating connection for developer id");
throw new AzureClientException($"Failed creating Vss connection: {azureUri.Connection} for {developerId.LoginId}");
}

Expand All @@ -183,7 +188,7 @@ public static ConnectionResult GetVssConnectionForLoggedInDeveloper(Uri uri, Dev
{
if (developerId == null)
{
Log.Logger()?.ReportError($"No logged in developer for which connection needs to be retrieved");
Log.Error($"No logged in developer for which connection needs to be retrieved");
return new ConnectionResult(ResultType.Failure, ErrorType.InvalidDeveloperId, false);
}

Expand All @@ -195,14 +200,14 @@ public static ConnectionResult GetVssConnectionForLoggedInDeveloper(Uri uri, Dev
{
if (string.IsNullOrEmpty(uri))
{
Log.Logger()?.ReportInfo($"Cannot GetClient: invalid uri argument value i.e. {uri}");
Log.Information($"Cannot GetClient: invalid uri argument value i.e. {uri}");
return null;
}

var azureUri = new AzureUri(uri);
if (!azureUri.IsValid)
{
Log.Logger()?.ReportInfo($"Cannot GetClient as uri validation failed: value of uri {uri}");
Log.Information($"Cannot GetClient as uri validation failed: value of uri {uri}");
return null;
}

Expand All @@ -227,7 +232,7 @@ public static ConnectionResult GetAzureDevOpsClient<T>(string uri, DeveloperId.D
var azureUri = new AzureUri(uri);
if (!azureUri.IsValid)
{
Log.Logger()?.ReportInfo($"Cannot GetClient as uri validation failed: value of uri {uri}");
Log.Information($"Cannot GetClient as uri validation failed: value of uri {uri}");
return new ConnectionResult(ResultType.Failure, ErrorType.InvalidArgument, false);
}

Expand Down
Loading