// TODO decide whether a cache is needed to handle lookups in elements with a large # children //private const int Cachesize = 10000; //private Cache<string, NodeMapping> cache; public ObjectExplorerSession(string uri, TreeNode root, IMultiServiceProvider serviceProvider, ConnectionService connectionService) { Validate.IsNotNullOrEmptyString("uri", uri); Validate.IsNotNull("root", root); Uri = uri; Root = root; this.serviceProvider = serviceProvider; this.connectionService = connectionService; }
private SmoQueryContext CreateContext(IMultiServiceProvider serviceProvider) { string exceptionMessage; ConnectionInfo connectionInfo; SqlConnection connection = null; // Get server object from connection if (!connectionService.TryFindConnection(this.connectionUri, out connectionInfo) || connectionInfo.AllConnections == null || connectionInfo.AllConnections.Count == 0) { ErrorStateMessage = string.Format(CultureInfo.CurrentCulture, SR.ServerNodeConnectionError, connectionSummary.ServerName); return(null); } //TODO: figure out how to use existing connections DbConnection dbConnection = connectionInfo.AllConnections.First(); ReliableSqlConnection reliableSqlConnection = dbConnection as ReliableSqlConnection; SqlConnection sqlConnection = dbConnection as SqlConnection; if (reliableSqlConnection != null) { connection = reliableSqlConnection.GetUnderlyingConnection(); } else if (sqlConnection != null) { connection = sqlConnection; } else { ErrorStateMessage = string.Format(CultureInfo.CurrentCulture, SR.ServerNodeConnectionError, connectionSummary.ServerName); return(null); } try { Server server = SmoWrapper.CreateServer(connection); return(new SmoQueryContext(server, serviceProvider, SmoWrapper) { Parent = server, SqlServerType = this.sqlServerType }); } catch (ConnectionFailureException cfe) { exceptionMessage = cfe.Message; } catch (Exception ex) { exceptionMessage = ex.Message; } Logger.Write(LogLevel.Error, "Exception at ServerNode.CreateContext() : " + exceptionMessage); this.ErrorStateMessage = string.Format(SR.TreeNodeError, exceptionMessage); return(null); }
public void GetServiceShouldReturnNullGivenInvalidMetadata() { //given var serverDefinition = new ServerDefinition(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); IMultiServiceProvider provider = CreateServiceProvider(); //when IServerDiscoveryProvider service = ExtensionUtils.GetService <IServerDiscoveryProvider>(provider, serverDefinition); //then Assert.Null(service); }
public void GetServiceShouldReturnNullGivenUnSupportedMetadata() { //given var serverDefinition = new ServerDefinition("SqlServer", "Local"); IMultiServiceProvider provider = CreateServiceProvider(); //when IAccountManager service = ExtensionUtils.GetService <IAccountManager>(provider, serverDefinition); //then Assert.Null(service); }
public void RequiresUserAccountShouldReturnFalseGivenNotSecuredService() { //given var serverDefinition = new ServerDefinition("SqlServer", "Local"); IMultiServiceProvider provider = CreateServiceProvider(); //when IServerDiscoveryProvider service = ExtensionUtils.GetService <IServerDiscoveryProvider>(provider, serverDefinition); //then Assert.NotNull(service); }
public void GetServiceShouldReturnTheServiceThatHasGivenMetadataCorrectly() { //given var serverDefinition = new ServerDefinition("SqlServer", "Azure"); IMultiServiceProvider provider = CreateServiceProvider(); //when IServerDiscoveryProvider service = ExtensionUtils.GetService <IServerDiscoveryProvider>(provider, serverDefinition); //then Assert.NotNull(service); Assert.True(service.GetType() == typeof(FakeSecureServerDiscoveryProvider)); }
public void ShouldFindDatabaseQuerierFromRealPath() { // Given the extension type loader is set to find SmoCollectionQuerier objects IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider(); // When I request a database compatible querier SmoQuerier querier = serviceProvider.GetService <SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database))); // Then I expect to get back the SqlDatabaseQuerier Assert.NotNull(querier); Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType()); // And I expect the service provider to have been set by the extension code Assert.NotNull(querier.ServiceProvider); }
/// <summary> /// As an <see cref="IComposableService"/>, this will be set whenever the service is initialized /// via an <see cref="IMultiServiceProvider"/> /// </summary> /// <param name="provider"></param> public override void SetServiceProvider(IMultiServiceProvider provider) { Validate.IsNotNull(nameof(provider), provider); serviceProvider = provider; connectionService = provider.GetService <ConnectionService>(); try { connectionService.RegisterConnectedQueue(connectionName, bindingQueue); } catch (Exception ex) { Logger.Write(LogLevel.Error, ex.Message); } }
private SmoQuerier GetSmoQuerier(Type querierType) { // Given the extension type loader is set to find SmoCollectionQuerier objects IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider(); // When I request a compatible querier SmoQuerier querier = serviceProvider.GetService <SmoQuerier>(q => q.SupportedObjectTypes.Contains(querierType)); // Then I expect to get back the Querier Assert.NotNull(querier); // And I expect the service provider to have been set by the extension code Assert.NotNull(querier.ServiceProvider); return(querier); }
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider, ServerConnection serverConnection) : base() { Validate.IsNotNull(nameof(connInfo), connInfo); Validate.IsNotNull("connInfo.ConnectionSummary", connInfo.ConnectionSummary); Validate.IsNotNull(nameof(serviceProvider), serviceProvider); this.connectionSummary = connInfo.ConnectionSummary; this.serverInfo = connInfo.ServerInfo; this.sqlServerType = ServerVersionHelper.CalculateServerType(this.serverInfo); this.context = new Lazy <SmoQueryContext>(() => CreateContext(serviceProvider)); this.serverConnection = serverConnection; NodeValue = connectionSummary.ServerName; IsAlwaysLeaf = false; NodeType = NodeTypes.Server.ToString(); NodeTypeId = NodeTypes.Server; Label = GetConnectionLabel(); }
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection) { ServerNode rootNode = new ServerNode(response, serviceProvider, serverConnection); return(new ObjectExplorerSession(response.OwnerUri, rootNode, serviceProvider, serviceProvider.GetService <ConnectionService>())); }
/// <summary> /// As an <see cref="IComposableService"/>, this will be set whenever the service is initialized /// via an <see cref="IMultiServiceProvider"/> /// </summary> /// <param name="provider"></param> public override void SetServiceProvider(IMultiServiceProvider provider) { Validate.IsNotNull(nameof(provider), provider); serviceProvider = provider; connectionService = provider.GetService <ConnectionService>(); }
/// <summary> /// Creates a context object with a server to use as the basis for any queries /// </summary> /// <param name="server"></param> public SmoQueryContext(Server server, IMultiServiceProvider serviceProvider) : this(server, serviceProvider, null) { }
internal SmoQueryContext(Server server, IMultiServiceProvider serviceProvider, SmoWrapper serverManager) { this.server = server; ServiceProvider = serviceProvider; this.smoWrapper = serverManager ?? new SmoWrapper(); }
public FormatterVisitor(FormatContext context, IMultiServiceProvider serviceProvider) : base() { Context = context; this.serviceProvider = serviceProvider; }
public virtual void SetServiceProvider(IMultiServiceProvider provider) { ServiceProvider = provider; }
public void SetServiceProvider(IMultiServiceProvider provider) { _serviceProvider = provider; }
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection, bool isDefaultOrSystemDatabase) { ServerNode rootNode = new ServerNode(response, serviceProvider, serverConnection); var session = new ObjectExplorerSession(response.OwnerUri, rootNode, serviceProvider, serviceProvider.GetService <ConnectionService>()); if (!isDefaultOrSystemDatabase) { // Assuming the databases are in a folder under server node DatabaseTreeNode databaseNode = new DatabaseTreeNode(rootNode, response.ConnectionSummary.DatabaseName); session.Root = databaseNode; } return(session); }
public void SetServiceProvider(IMultiServiceProvider provider) { throw new NotImplementedException(); }