-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapping of extensions to repository paths in DevHome core (#3230)
* declare appextension for git, find all source control extensions, UI changes, SDK changes, get extension information to use for mapping * changes to map extension to registered root paths, add validation to git implementation * changes after testing * use serilog in validation code * reorder using * use published SDK version * address PR feedback * address PR feedback * address PR feedback * Minor cleanup of RepositoryTracking.cs --------- Co-authored-by: Ryan Shepherd <ryansh@microsoft.com>
- Loading branch information
1 parent
6e3f0b7
commit 85e8858
Showing
18 changed files
with
361 additions
and
43 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
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
13 changes: 13 additions & 0 deletions
13
tools/Customization/DevHome.Customization/Helpers/ErrorType.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,13 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace DevHome.Customization.Helpers; | ||
|
||
public enum ErrorType | ||
{ | ||
None, | ||
Unknown, | ||
RepositoryProvderCreationFailed, | ||
OpenRepositoryFailed, | ||
SourceControlExtensionValidationFailed, | ||
} |
11 changes: 11 additions & 0 deletions
11
tools/Customization/DevHome.Customization/Helpers/ResultType.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,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace DevHome.Customization.Helpers; | ||
|
||
public enum ResultType | ||
{ | ||
Unknown, | ||
Success, | ||
Failure, | ||
} |
45 changes: 45 additions & 0 deletions
45
tools/Customization/DevHome.Customization/Helpers/SourceControlValidationResult.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,45 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DevHome.Customization.Helpers; | ||
|
||
public class SourceControlValidationResult | ||
{ | ||
public ResultType Result { get; private set; } = ResultType.Unknown; | ||
|
||
public ErrorType Error { get; private set; } = ErrorType.Unknown; | ||
|
||
public Exception? Exception | ||
{ | ||
get; set; | ||
} | ||
|
||
public string? DisplayMessage | ||
{ | ||
get; set; | ||
} | ||
|
||
public string? DiagnosticText | ||
{ | ||
get; set; | ||
} | ||
|
||
public SourceControlValidationResult() | ||
{ | ||
Result = ResultType.Success; | ||
Error = ErrorType.None; | ||
} | ||
|
||
public SourceControlValidationResult(ResultType result, ErrorType error, Exception? exception, string? displayMessage, string? diagnosticText) | ||
{ | ||
Result = result; | ||
Error = error; | ||
Exception = exception; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tools/Customization/DevHome.Customization/Models/SourceControlIntegration.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,62 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using DevHome.Customization.Helpers; | ||
using Microsoft.Windows.DevHome.SDK; | ||
using Serilog; | ||
using Windows.Win32; | ||
using WinRT; | ||
|
||
namespace DevHome.Customization.Models; | ||
|
||
public class SourceControlIntegration | ||
{ | ||
private static readonly Serilog.ILogger Log = Serilog.Log.ForContext("SourceContext", nameof(Models.SourceControlIntegration)); | ||
|
||
public static SourceControlValidationResult ValidateSourceControlExtension(string extensionCLSID, string rootPath) | ||
{ | ||
var providerPtr = IntPtr.Zero; | ||
try | ||
{ | ||
Log.Information("Validating source control extension with arguments: extensionCLSID = {extensionCLSID}, rootPath = {rootPath}", extensionCLSID, rootPath); | ||
|
||
var hr = PInvoke.CoCreateInstance(Guid.Parse(extensionCLSID), null, Windows.Win32.System.Com.CLSCTX.CLSCTX_LOCAL_SERVER, typeof(ILocalRepositoryProvider).GUID, out var extensionObj); | ||
providerPtr = Marshal.GetIUnknownForObject(extensionObj); | ||
if (hr < 0) | ||
{ | ||
Log.Error(hr.ToString(), "Failure occurred while creating instance of repository provider"); | ||
return new SourceControlValidationResult(ResultType.Failure, ErrorType.RepositoryProvderCreationFailed, null, null, null); | ||
} | ||
|
||
ILocalRepositoryProvider provider = MarshalInterface<ILocalRepositoryProvider>.FromAbi(providerPtr); | ||
GetLocalRepositoryResult result = provider.GetRepository(rootPath); | ||
|
||
if (result.Result.Status == ProviderOperationStatus.Failure) | ||
{ | ||
Log.Error("Could not open local repository."); | ||
Log.Error(result.Result.DisplayMessage); | ||
return new SourceControlValidationResult(ResultType.Failure, ErrorType.OpenRepositoryFailed, result.Result.ExtendedError, result.Result.DisplayMessage, result.Result.DiagnosticText); | ||
} | ||
else | ||
{ | ||
Log.Information("Local repository opened successfully."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error(ex, "An exception occurred while validating source control extension."); | ||
return new SourceControlValidationResult(ResultType.Failure, ErrorType.SourceControlExtensionValidationFailed, ex, null, null); | ||
} | ||
finally | ||
{ | ||
if (providerPtr != IntPtr.Zero) | ||
{ | ||
Marshal.Release(providerPtr); | ||
} | ||
} | ||
|
||
return new SourceControlValidationResult(); | ||
} | ||
} |
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,3 +1,4 @@ | ||
SHGetSetSettings | ||
ReadCabinetState | ||
WriteCabinetState | ||
CoCreateInstance |
37 changes: 37 additions & 0 deletions
37
...ization/DevHome.Customization/ViewModels/FileExplorerSourceControlIntegrationViewModel.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,37 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using DevHome.Common.Contracts.Services; | ||
using DevHome.Common.Extensions; | ||
using DevHome.Common.Models; | ||
using DevHome.Common.Services; | ||
using DevHome.Customization.ViewModels; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.Windows.DevHome.SDK; | ||
|
||
namespace DevHome.Customization.ViewModels; | ||
|
||
public partial class FileExplorerSourceControlIntegrationViewModel : ObservableObject | ||
{ | ||
public ObservableCollection<Breadcrumb> Breadcrumbs { get; } | ||
|
||
public IExtensionWrapper LocalRepositoryProvider { get; } | ||
|
||
public string ProviderName => LocalRepositoryProvider.ExtensionDisplayName; | ||
|
||
public FileExplorerSourceControlIntegrationViewModel(IExtensionWrapper localRepoProvider) | ||
{ | ||
LocalRepositoryProvider = localRepoProvider; | ||
|
||
var stringResource = new StringResource("DevHome.Customization.pri", "DevHome.Customization/Resources"); | ||
Breadcrumbs = | ||
[ | ||
new(stringResource.GetLocalized("MainPage_Header"), typeof(MainPageViewModel).FullName!), | ||
new(stringResource.GetLocalized("FileExplorer_Header"), typeof(FileExplorerViewModel).FullName!) | ||
]; | ||
} | ||
} |
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.