public ObjectExplorerServiceTests() { connectionServiceMock = new Mock <ConnectionService>(); serviceHostMock = new Mock <IProtocolEndpoint>(); service = CreateOEService(connectionServiceMock.Object); service.InitializeService(serviceHostMock.Object); }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override void Initialize() { base.Initialize(); DbFolderCommand.Initialize(this); this._objectExplorerService = new ObjectExplorerService(); AttachTreeViewEvents(); AddSkipLoading(); }
private async Task <ObjectExplorerSession> CreateSession(string databaseName) { ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName); //connectParams.Connection.Pooling = false; ConnectionDetails details = connectParams.Connection; string uri = ObjectExplorerService.GenerateUri(details); var session = await _service.DoCreateSession(details, uri); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "OE session created for database: {0}", databaseName)); return(session); }
public ObjectExplorerServiceTests() { connectionServiceMock = new Mock <ConnectionService>(); serviceHostMock = new Mock <IProtocolEndpoint>(); service = CreateOEService(connectionServiceMock.Object); connectionServiceMock.Setup(x => x.RegisterConnectedQueue(It.IsAny <string>(), It.IsAny <IConnectedBindingQueue>())); service.InitializeService(serviceHostMock.Object); ConnectedBindingContext connectedBindingContext = new ConnectedBindingContext(); connectedBindingContext.ServerConnection = new ServerConnection(new SqlConnection(fakeConnectionString)); connectedBindingQueue = new ConnectedBindingQueue(false); connectedBindingQueue.BindingContextMap.Add($"{details.ServerName}_{details.DatabaseName}_{details.UserName}_NULL", connectedBindingContext); service.ConnectedBindingQueue = connectedBindingQueue; }
/// <summary> /// Gets the <see cref="ObjectExplorerService"/> if available, by looking it up /// from the <see cref="ServiceProvider"/> /// </summary> /// <returns></returns> /// <exception cref="InvalidOperationException"> /// Thrown if the <see cref="ServiceProvider"/> is not set or the <see cref="ObjectExplorerService"/> /// isn't available from that provider /// </exception> public ObjectExplorerService GetObjectExplorerService() { if (ServiceProvider == null) { throw new InvalidOperationException(SqlTools.Hosting.SR.ServiceProviderNotSet); } ObjectExplorerService service = ServiceProvider.GetService <ObjectExplorerService>(); if (service == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SqlTools.Hosting.SR.ServiceNotFound, nameof(ObjectExplorerService))); } return(service); }
/// <summary> /// main addin entry method /// </summary> /// <param name="Application"></param> /// <param name="ConnectMode"></param> /// <param name="AddInInst"></param> /// <param name="custom"></param> public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { /* Microsoft.SqlServer.Management.UI.VSIntegration.ServiceCache * is from SqlPackageBase.dll and not from Microsoft.SqlServer.SqlTools.VSIntegration.dll * the code below just throws null exception if you have wrong reference */ objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService)); cs = (ContextService)objExplorerService.Container.Components[0]; cs.ObjectExplorerContext.CurrentContextChanged += new NodesChangedEventHandler(ObjectExplorerContext_CurrentContextChanged); } catch (Exception ex) { debug_message("OnConnection::ERROR " + ex.Message); } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _addInInstance = (AddIn)addInInst; // search ServiceCache.ServiceProvider.GetService -> // http://sqlblog.com/blogs/jonathan_kehayias/archive/2009/08/22/sql-2008-r2-breaks-ssms-addins.aspx ObjectExplorerService objectExplorer = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService)); // for some reason calling GetSelectedNodes forces to add ContextService to ObjectExplorerService.Container.Components int count = objectExplorer.Container.Components.Count; int nodeCount; INodeInformation[] nodes; objectExplorer.GetSelectedNodes(out nodeCount, out nodes); count = nodeCount; count = nodes.Length; count = objectExplorer.Container.Components.Count; ContextService contextService = (ContextService)objectExplorer.Container.Components[1]; INavigationContextProvider provider = contextService.ObjectExplorerContext; provider.CurrentContextChanged += new NodesChangedEventHandler(Provider_SelectionChanged); }