diff --git a/src/ConnectedMode/Persistence/SolutionBindingRepository.cs b/src/ConnectedMode/Persistence/SolutionBindingRepository.cs index bdeea600e..79b22f5c1 100644 --- a/src/ConnectedMode/Persistence/SolutionBindingRepository.cs +++ b/src/ConnectedMode/Persistence/SolutionBindingRepository.cs @@ -22,7 +22,6 @@ using SonarLint.VisualStudio.ConnectedMode.Binding; using SonarLint.VisualStudio.Core; using SonarLint.VisualStudio.Core.Binding; -using SonarLint.VisualStudio.SLCore.Service.Project.Models; namespace SonarLint.VisualStudio.ConnectedMode.Persistence; @@ -31,15 +30,16 @@ namespace SonarLint.VisualStudio.ConnectedMode.Persistence; [PartCreationPolicy(CreationPolicy.Shared)] internal class SolutionBindingRepository : ISolutionBindingRepository, ILegacySolutionBindingRepository { - private readonly ISolutionBindingFileLoader solutionBindingFileLoader; - private readonly ISolutionBindingCredentialsLoader credentialsLoader; - private readonly IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider; - private readonly IServerConnectionsRepository serverConnectionsRepository; private readonly IBindingJsonModelConverter bindingJsonModelConverter; + private readonly ISolutionBindingCredentialsLoader credentialsLoader; private readonly ILogger logger; + private readonly IServerConnectionsRepository serverConnectionsRepository; + private readonly ISolutionBindingFileLoader solutionBindingFileLoader; + private readonly IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider; [ImportingConstructor] - public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, + public SolutionBindingRepository( + IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, IBindingJsonModelConverter bindingJsonModelConverter, IServerConnectionsRepository serverConnectionsRepository, ICredentialStoreService credentialStoreService, @@ -53,7 +53,8 @@ public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBind { } - internal /* for testing */ SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, + internal /* for testing */ SolutionBindingRepository( + IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider, IBindingJsonModelConverter bindingJsonModelConverter, IServerConnectionsRepository serverConnectionsRepository, ISolutionBindingFileLoader solutionBindingFileLoader, @@ -78,10 +79,7 @@ BoundSonarQubeProject ILegacySolutionBindingRepository.Read(string configFilePat }; } - public BoundServerProject Read(string configFilePath) - { - return Convert(ReadBindingFile(configFilePath), configFilePath); - } + public BoundServerProject Read(string configFilePath) => Convert(ReadBindingFile(configFilePath), configFilePath); public bool Write(string configFilePath, BoundServerProject binding) { @@ -98,10 +96,12 @@ public bool Write(string configFilePath, BoundServerProject binding) } BindingUpdated?.Invoke(this, EventArgs.Empty); - + return true; } + public bool DeleteBinding(string configFilePath) => throw new NotImplementedException(); + public event EventHandler BindingUpdated; public IEnumerable List() @@ -110,7 +110,7 @@ public IEnumerable List() { throw new InvalidOperationException("Could not retrieve all connections."); } - + var bindingConfigPaths = unintrusiveBindingPathProvider.GetBindingPaths(); foreach (var bindingConfigPath in bindingConfigPaths) @@ -123,7 +123,7 @@ public IEnumerable List() continue; } - if (connections.FirstOrDefault(c => c.Id == bindingJsonModel.ServerConnectionId) is not {} serverConnection) + if (connections.FirstOrDefault(c => c.Id == bindingJsonModel.ServerConnectionId) is not { } serverConnection) { logger.LogVerbose($"Skipped {bindingConfigPath} because connection {bindingJsonModel.ServerConnectionId} doesn't exist"); continue; @@ -134,7 +134,7 @@ public IEnumerable List() yield return boundServerProject; } } - + private BindingJsonModel ReadBindingFile(string configFilePath) { var bound = solutionBindingFileLoader.Load(configFilePath); @@ -144,11 +144,10 @@ private BindingJsonModel ReadBindingFile(string configFilePath) return null; } - Debug.Assert(!bound.Profiles?.ContainsKey(Core.Language.Unknown) ?? true, + Debug.Assert(!bound.Profiles?.ContainsKey(Language.Unknown) ?? true, "Not expecting the deserialized binding config to contain the profile for an unknown language"); return bound; - } private BoundServerProject Convert(BindingJsonModel bindingJsonModel, string configFilePath) => @@ -156,6 +155,6 @@ private BoundServerProject Convert(BindingJsonModel bindingJsonModel, string con ? Convert(bindingJsonModel, connection, configFilePath) : null; - private BoundServerProject Convert(BindingJsonModel bindingJsonModel, ServerConnection connection, string configFilePath) => + private BoundServerProject Convert(BindingJsonModel bindingJsonModel, ServerConnection connection, string configFilePath) => bindingJsonModelConverter.ConvertFromModel(bindingJsonModel, connection, unintrusiveBindingPathProvider.GetBindingKeyFromPath(configFilePath)); } diff --git a/src/Core/Binding/ISolutionBindingRepository.cs b/src/Core/Binding/ISolutionBindingRepository.cs index 8c270eb81..99d63a458 100644 --- a/src/Core/Binding/ISolutionBindingRepository.cs +++ b/src/Core/Binding/ISolutionBindingRepository.cs @@ -44,7 +44,13 @@ public interface ISolutionBindingRepository bool Write(string configFilePath, BoundServerProject binding); /// - /// Raises when operation completes successfully + /// Deletes the binding information + /// + /// If binding has been deleted + bool DeleteBinding(string configFilePath); + + /// + /// Raises when operation completes successfully /// event EventHandler BindingUpdated;