From 67c7e20c13c684137033100f8e01f68dbdb2bc18 Mon Sep 17 00:00:00 2001 From: Justin M <63619224+JustinMDotNet@users.noreply.github.com> Date: Thu, 19 Nov 2020 14:18:58 -0800 Subject: [PATCH] 13159 Created SetDatabaseName in KustoClient to take database name from ( ). Changed ListDatabases in Kusto ConnnectionService to set DatabaseNames in a different format when the PrettyName doesn't match the name. (#1123) --- .../Connection/ConnectionService.cs | 11 +++++++++-- .../DataSource/KustoClient.cs | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs index 42044a69..4879e2e7 100644 --- a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs @@ -793,7 +793,8 @@ namespace Microsoft.Kusto.ServiceLayer.Connection ListDatabasesResponse response = new ListDatabasesResponse(); // Mainly used by "manage" dashboard - if(listDatabasesParams.IncludeDetails.HasTrue()){ + if (listDatabasesParams.IncludeDetails.HasTrue()) + { IEnumerable databaseMetadataInfo = dataSource.GetChildObjects(objectMetadata, true); List metadata = MetadataFactory.ConvertToDatabaseInfo(databaseMetadataInfo); response.Databases = metadata.ToArray(); @@ -802,7 +803,13 @@ namespace Microsoft.Kusto.ServiceLayer.Connection } IEnumerable databaseMetadata = dataSource.GetChildObjects(objectMetadata); - if(databaseMetadata != null) response.DatabaseNames = databaseMetadata.Select(objMeta => objMeta.PrettyName).ToArray(); + if (databaseMetadata != null) + { + response.DatabaseNames = databaseMetadata + .Select(objMeta => objMeta.PrettyName == objMeta.Name ? objMeta.PrettyName : $"{objMeta.PrettyName} ({objMeta.Name})") + .ToArray(); + } + return response; } diff --git a/src/Microsoft.Kusto.ServiceLayer/DataSource/KustoClient.cs b/src/Microsoft.Kusto.ServiceLayer/DataSource/KustoClient.cs index 8f3dae6a..aea3b446 100644 --- a/src/Microsoft.Kusto.ServiceLayer/DataSource/KustoClient.cs +++ b/src/Microsoft.Kusto.ServiceLayer/DataSource/KustoClient.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Linq; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Kusto.Cloud.Platform.Data; @@ -42,11 +43,23 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource { _ownerUri = ownerUri; ClusterName = GetClusterName(connectionString); - DatabaseName = new SqlConnectionStringBuilder(connectionString).InitialCatalog; + + var dbName = new SqlConnectionStringBuilder(connectionString).InitialCatalog; + SetDatabaseName(dbName); + Initialize(ClusterName, DatabaseName, azureAccountToken); SchemaState = LoadSchemaState(); } + private void SetDatabaseName(string databaseName) + { + var regex = new Regex(@"(?<=\().+?(?=\))"); + + DatabaseName = regex.IsMatch(databaseName) + ? regex.Match(databaseName).Value + : databaseName; + } + private GlobalState LoadSchemaState() { IEnumerable tableSchemas = Enumerable.Empty(); @@ -297,7 +310,7 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource public void UpdateDatabase(string databaseName) { - DatabaseName = databaseName; + SetDatabaseName(databaseName); SchemaState = LoadSchemaState(); }