Skip to content

Commit

Permalink
14.5.3.1002 Fixed Connection Dialog database dropdown .
Browse files Browse the repository at this point in the history
New / Enhancements
- Added __User Option__ `BlackbirdSQL Server Tools > Ddex Provider > Debug > Expected exceptions`. Enabling this option causes expected exceptions to be output to the __BlackbirdSql__ section of the VS output window for Release builds.

Fixes
- Fixed anomaly where defining a property's `ReadOnlyAttribute` as false causes the property to attach to the Class `ReadonlyAttribute`. This caused a programmatic  change to property's `ReadOnlyAttribute` to modify the Class level `ReadOnlyAttribute`, and by default to modify all properties without a `ReadOnlyAttribute`.
- Fixed issue in Connection Dialog where a dummy blank database was not inserted if no Server Explorer or FlameRobin database existed for the selected DataSource/Server.
  • Loading branch information
BlackbirdSQL committed Oct 22, 2024
1 parent 207b72a commit 4ca4c04
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 129 deletions.
Binary file modified BlackbirdDsl/BlackbirdDsl.rc
Binary file not shown.
8 changes: 4 additions & 4 deletions BlackbirdDsl/BlackbirdDsl.rc2
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 14,5,3,1001
PRODUCTVERSION 14,5,3,1001
FILEVERSION 14,5,3,1002
PRODUCTVERSION 14,5,3,1002
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -32,12 +32,12 @@ BLOCK "1c0904b0"
BEGIN
VALUE "CompanyName", "BlackbirdSql"
VALUE "FileDescription", "Blackbird Dsl Parser"
VALUE "FileVersion", "14.5.3.1001"
VALUE "FileVersion", "14.5.3.1002"
VALUE "InternalName", "BlackbirdDsl.dll"
VALUE "LegalCopyright", "Copyright (C) 2023"
VALUE "OriginalFilename", "BlackbirdDsl.dll"
VALUE "ProductName", "BlackbirdDsl"
VALUE "ProductVersion", "14.5.3.1001"
VALUE "ProductVersion", "14.5.3.1002"
END
END
BLOCK "VarFileInfo"
Expand Down
6 changes: 3 additions & 3 deletions BlackbirdDsl/Include/AssemblyInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#define Assembly_Copyright L"Copyright © BlackbirdSql 2023"
#define Assembly_Description L"BlackbirdSql DSL Parser"
#define File_Version 14,5,3,1001
#define File_Version_Str "14.5.3.1001"
#define File_Version 14,5,3,1002
#define File_Version_Str "14.5.3.1002"

//CLR assembly version
#define Assembly_Version L"14.5.3.1001"
#define Assembly_Version L"14.5.3.1002"

2 changes: 0 additions & 2 deletions BlackbirdSql.Core/Ctl/ComponentModel/AbstractUomConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ public void OnEditControlGotFocus(object sender, EditControlFocusEventArgs e)
if (e.SelectionItem.PropertyDescriptor.Attributes[typeof(ReadOnlyAttribute)] is ReadOnlyAttribute attr)
{
if ((bool)Reflect.GetFieldValue(attr, "isReadOnly"))
{
return;
}
}

_EditActive = true;
Expand Down
115 changes: 42 additions & 73 deletions BlackbirdSql.Core/Model/AbstractCsb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using BlackbirdSql.Core.Ctl.ComponentModel;
Expand Down Expand Up @@ -125,17 +124,17 @@ static AbstractCsb()

Describers.AddRange(
[
new Describer(C_KeyExDatasetKey, typeof(string), C_DefaultExDatasetKey, D_Default),
new Describer(C_KeyExConnectionKey, typeof(string), C_DefaultExConnectionKey, D_Default),
new Describer(C_KeyExDatasetName, typeof(string), C_DefaultExDatasetName, D_Default),
new Describer(C_KeyExDataset, typeof(string), C_DefaultExDataset, D_Default | D_Derived),
new Describer(C_KeyExDatasetKey, typeof(string), C_DefaultExDatasetKey, D_DefaultReadOnly),
new Describer(C_KeyExConnectionKey, typeof(string), C_DefaultExConnectionKey, D_DefaultReadOnly),
new Describer(C_KeyExDatasetName, typeof(string), C_DefaultExDatasetName, D_DefaultReadOnly),
new Describer(C_KeyExDataset, typeof(string), C_DefaultExDataset, D_DefaultReadOnly | D_Derived),

new Describer(C_KeyExConnectionName, typeof(string), C_DefaultExConnectionName, D_Default),
new Describer(C_KeyExConnectionSource, typeof(EnConnectionSource), C_DefaultExConnectionSource, D_Default),
new Describer(C_KeyExConnectionName, typeof(string), C_DefaultExConnectionName, D_DefaultReadOnly),
new Describer(C_KeyExConnectionSource, typeof(EnConnectionSource), C_DefaultExConnectionSource, D_DefaultReadOnly),

new Describer(C_KeyExClientVersion, typeof(Version), C_DefaultExClientVersion, D_Public | D_Derived),
new Describer(C_KeyExMemoryUsage, typeof(string), C_DefaultExMemoryUsage, D_Public | D_Derived),
new Describer(C_KeyExActiveUsers, typeof(int), C_DefaultExActiveUsers, D_Public | D_Derived),
new Describer(C_KeyExClientVersion, typeof(Version), C_DefaultExClientVersion, D_Public | D_Derived | D_HasReadOnly),
new Describer(C_KeyExMemoryUsage, typeof(string), C_DefaultExMemoryUsage, D_Public | D_Derived | D_HasReadOnly),
new Describer(C_KeyExActiveUsers, typeof(int), C_DefaultExActiveUsers, D_Public | D_Derived | D_HasReadOnly),

new Describer(C_KeyExServerVersion, typeof(Version), C_DefaultExServerVersion, D_Public | D_Derived),
new Describer(C_KeyExPersistPassword, typeof(bool), C_DefaultExPersistPassword, D_Public | D_Derived),
Expand Down Expand Up @@ -175,6 +174,9 @@ private void Initialize(string server, int port, EnServerType serverType, string
// =====================================================================================================


bool _ServerNameValidated = false;


#endregion Constants


Expand Down Expand Up @@ -381,13 +383,31 @@ public string ServerExplorerName
retval = DisplayDatasetName;

if (!string.IsNullOrWhiteSpace(DataSource))
retval = S_DatasetKeyFormat.FmtRes(DataSource, retval);
retval = S_DatasetKeyFormat.FmtRes(ServerName, retval);
}
return retval;
}
}


/// <summary>
/// The registered ServerName for the DataSource.
/// </summary>
[Browsable(false)]
public string ServerName
{
get
{
string retval = DataSource;

if (_ServerNameValidated || string.IsNullOrWhiteSpace(retval))
return retval;

return RctManager.RegisterServer(retval, Port);
}
}




/// <summary>
Expand Down Expand Up @@ -492,7 +512,7 @@ public string AdornedTitle
/// The DatasetKey if ConnectionName is null else the DisplayName qualified with the server name.
/// </summary>
[Browsable(false)]
public string QualifiedName => string.IsNullOrEmpty(ConnectionName) ? DatasetKey : S_DatasetKeyFormat.FmtRes(DataSource, DisplayName);
public string QualifiedName => string.IsNullOrEmpty(ConnectionName) ? DatasetKey : S_DatasetKeyFormat.FmtRes(ServerName, DisplayName);



Expand Down Expand Up @@ -986,33 +1006,22 @@ private void Extract(IVsDataExplorerNode node)
// Evs.Debug(GetType(), "Extract(IVsDataExplorerNode)", $"Node type is {@object}.");

object value;
object readOnly;
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(this);



foreach (KeyValuePair<string, Describer> pair in Csb.Describers)
{
try
{
if (!@object.Properties.ContainsKey(pair.Key))
if (pair.Value.IsDerived)
continue;

value = @object.Properties[pair.Key];

if (Cmd.IsNullValue(value))
continue;

readOnly = Reflect.GetAttributeValue(descriptors[pair.Key], typeof(ReadOnlyAttribute), "isReadOnly");

if (readOnly != null && (bool)readOnly)
if (!@object.Properties.ContainsKey(pair.Key))
continue;

value = @object.Properties[pair.Key];

if (pair.Value.DefaultEquals(value))
if (Cmd.IsNullValue(value) || pair.Value.DefaultEquals(value))
continue;


this[pair.Key] = value;
}
catch (Exception ex)
Expand Down Expand Up @@ -1070,57 +1079,17 @@ public void ValidateProposedName()
// ---------------------------------------------------------------------------------
public void ValidateServerName()
{
string dataSource, server;
string dataSource;

if (ContainsKey(C_KeyDataSource) && !string.IsNullOrWhiteSpace(dataSource = DataSource)
&& !RctManager.ShutdownState && !dataSource.Equals(server = RctManager.RegisterServer(dataSource, Port)))
{
DataSource = server;
}
}



/// <summary>
/// Updates descriptor ReadonlyAttributes.
/// </summary>
public static bool UpdateDescriptorReadOnlyAttribute(ref PropertyDescriptorCollection descriptors, string[] readOnlyDescriptors, bool readOnly)
{
if (descriptors == null || descriptors.Count == 0)
return false;

bool value;
bool updated = false;

try
&& !RctManager.ShutdownState)
{
foreach (string name in readOnlyDescriptors)
{
PropertyDescriptor descriptor = descriptors.Find(name, true);
_ServerNameValidated = true;
string server = RctManager.RegisterServer(dataSource, Port);

if (descriptor == null)
continue;

if (descriptor.Attributes[typeof(ReadOnlyAttribute)] is not ReadOnlyAttribute attr)
throw new IndexOutOfRangeException($"ReadOnlyAttribute not found in PropertyDescriptor for {name}.");

FieldInfo fieldInfo = Reflect.GetFieldInfo(attr, "isReadOnly");

value = readOnly;

if ((bool)Reflect.GetFieldInfoValue(attr, fieldInfo) != value)
{
updated = true;
Reflect.SetFieldInfoValue(attr, fieldInfo, value);
}
}
}
catch (Exception ex)
{
Diag.Dug(ex);
if (!dataSource.Equals(server))
DataSource = server;
}

return updated;
}


Expand Down
2 changes: 1 addition & 1 deletion BlackbirdSql.Core/Model/AbstractRunningConnectionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ protected Csb InternalUpdateRegisteredConnection(string connectionString, EnConn
}
else
{
csa.DatasetKey = S_DatasetKeyFormat.FmtRes(csa.DataSource, csa.DisplayDatasetName);
csa.DatasetKey = S_DatasetKeyFormat.FmtRes(csa.ServerName, csa.DisplayDatasetName);
}
}

Expand Down
23 changes: 19 additions & 4 deletions BlackbirdSql.Core/Model/AbstruseRunningConnectionTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using BlackbirdSql.Core.Ctl.Config;
using BlackbirdSql.Core.Enums;
using BlackbirdSql.Core.Properties;
Expand Down Expand Up @@ -1196,7 +1197,7 @@ private void InternalLoadServerExplorerConnection(string connectionName, string

// If the connection name matches the datasetKey constructed from the datasetName, remove it.
if (!string.IsNullOrEmpty(datasetName) && !csa.ContainsKey(C_KeyExConnectionName)
&& connectionName == S_DatasetKeyFormat.FmtRes(csa.DataSource, datasetName))
&& connectionName == S_DatasetKeyFormat.FmtRes(csa.ServerName, datasetName))
{
connectionName = null;
}
Expand Down Expand Up @@ -1747,6 +1748,7 @@ private void RegisterAppConnectionStrings(string projectName, string xmlPath)

int i = 0;
string sortkey;
string serverName;
List<string> sortlist = [];
Dictionary<string, Csb> sortdict = [];

Expand All @@ -1773,7 +1775,12 @@ private void RegisterAppConnectionStrings(string projectName, string xmlPath)
csa.DatasetName = datasetName;
csa.ConnectionSource = EnConnectionSource.Application;

sortkey = csa.DataSource + datasetName + "\n" + (i++).ToString("D4");
// To keep uniformity of server names, the case of the first connection
// discovered for a server name is the case that will be used for all
// connections for that server.
serverName = InternalRegisterServer(csa.DataSource, csa.Port);

sortkey = serverName + datasetName + "\n" + (i++).ToString("D4");
sortlist.Add(sortkey);
sortdict[sortkey] = csa;
}
Expand Down Expand Up @@ -1829,7 +1836,12 @@ private void RegisterAppConnectionStrings(string projectName, string xmlPath)
csa.DatasetName = datasetName;
csa.ConnectionSource = EnConnectionSource.Application;

sortkey = csa.DataSource + datasetName + "\n" + (i++).ToString("D4");
// To keep uniformity of server names, the case of the first connection
// discovered for a server name is the case that will be used for all
// connections for that server.
serverName = InternalRegisterServer(csa.DataSource, csa.Port);

sortkey = serverName + datasetName + "\n" + (i++).ToString("D4");
sortlist.Add(sortkey);
sortdict[sortkey] = csa;
}
Expand Down Expand Up @@ -2075,7 +2087,7 @@ private DataRow RegisterUniqueConnectionImpl(string proposedConnectionName,
bool createServerExplorerConnection = false;

GenerateUniqueDatasetKey(source, ref proposedConnectionName, ref proposedDatasetName,
csa.DataSource, csa.Dataset, connectionUrl, null, ref createServerExplorerConnection,
csa.ServerName, csa.Dataset, connectionUrl, null, ref createServerExplorerConnection,
out _, out _, out string uniqueDatasetKey, out string uniqueConnectionName,
out string uniqueDatasetName);

Expand Down Expand Up @@ -2266,6 +2278,9 @@ protected bool UpdateDataRowFromCsa(DataRow row, Csb csa = null)
? csa[describer.Name]
: describer.DefaultValue;

if (describer.Name == C_KeyDataSource && !string.IsNullOrWhiteSpace((string)csaValue))
csaValue = InternalRegisterServer((string)csaValue, csa.Port);

updated = UpdateDataColumn(row, describer.Name, csaValue, updated);
}

Expand Down
2 changes: 2 additions & 0 deletions BlackbirdSql.Core/Model/ConnectionCsb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public ConnectionCsb(string server, int port, string database, string userId, st
Database = database;
UserID = userId;
Password = password;

ValidateServerName();
}


Expand Down
6 changes: 3 additions & 3 deletions BlackbirdSql.Core/Model/Csb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void ApplyValidKeys(string connectionName, string datasetName, bool clear
}
else if (!string.IsNullOrWhiteSpace(datasetName))
{
string derivedConnectionName = S_DatasetKeyFormat.FmtRes(DataSource, datasetName);
string derivedConnectionName = S_DatasetKeyFormat.FmtRes(ServerName, datasetName);

if (!derivedConnectionName.Equals(datasetKey))
Remove(C_KeyExDatasetKey);
Expand Down Expand Up @@ -613,8 +613,8 @@ public string ToDisplayString()
// Now that the datasetName is established, we can determined its default derived value
// and the default derived value of the datasetKey.
string derivedDatasetName = string.IsNullOrEmpty(datasetName) ? dataset : datasetName;
string derivedConnectionName = S_DatasetKeyFormat.FmtRes(DataSource, derivedDatasetName);
string derivedAlternateConnectionName = S_DatasetKeyAlternateFormat.FmtRes(DataSource, derivedDatasetName);
string derivedConnectionName = S_DatasetKeyFormat.FmtRes(ServerName, derivedDatasetName);
string derivedAlternateConnectionName = S_DatasetKeyAlternateFormat.FmtRes(ServerName, derivedDatasetName);


// Now the proposed DatasetKey, ConnectionName. If it exists and is equal to the derived
Expand Down
13 changes: 8 additions & 5 deletions BlackbirdSql.Core/Root/RctManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ private static Csb EnsureInstance(string connectionString, EnConnectionSource so

if (csa.ContainsKey(SysConstants.C_KeyExConnectionName)
&& !string.IsNullOrWhiteSpace(csa.ConnectionName)
&& (SysConstants.S_DatasetKeyFormat.FmtRes(csa.DataSource, datasetName) == csa.ConnectionName
|| SysConstants.S_DatasetKeyAlternateFormat.FmtRes(csa.DataSource, datasetName) == csa.ConnectionName))
&& (SysConstants.S_DatasetKeyFormat.FmtRes(csa.ServerName, datasetName) == csa.ConnectionName
|| SysConstants.S_DatasetKeyAlternateFormat.FmtRes(csa.ServerName, datasetName) == csa.ConnectionName))
{
// csa.Remove(SysConstants.C_KeyExConnectionName);
}
Expand Down Expand Up @@ -990,8 +990,8 @@ public static Csb EnsureVolatileInstance(IDbConnection connection)


if (!string.IsNullOrWhiteSpace(csa.ConnectionName)
&& (SysConstants.S_DatasetKeyFormat.FmtRes(csa.DataSource, datasetName) == csa.ConnectionName
|| SysConstants.S_DatasetKeyAlternateFormat.FmtRes(csa.DataSource, datasetName) == csa.ConnectionName))
&& (SysConstants.S_DatasetKeyFormat.FmtRes(csa.ServerName, datasetName) == csa.ConnectionName
|| SysConstants.S_DatasetKeyAlternateFormat.FmtRes(csa.ServerName, datasetName) == csa.ConnectionName))
{
csa.ConnectionName = SysConstants.C_DefaultExConnectionName;
}
Expand Down Expand Up @@ -1524,7 +1524,7 @@ public static void ValidateAndUpdateExplorerConnectionRename(IVsDataExplorerConn
bool createServerExplorerConnection = false;
string connectionUrl = csa.Moniker;
string proposedDatasetName = csa.DatasetName;
string dataSource = csa.DataSource;
string dataSource = csa.ServerName;
string dataset = csa.Dataset;


Expand Down Expand Up @@ -1658,6 +1658,7 @@ public static (bool, bool, bool) ValidateSiteProperties(IVsDataConnectionPropert
proposedDatasetName = null;

string dataSource = (string)site[SysConstants.C_KeyDataSource];
int port = site.ContainsKey(SysConstants.C_KeyPort) ? Convert.ToInt32(site[SysConstants.C_KeyPort]) : SysConstants.C_DefaultPort;
string database = (string)site[SysConstants.C_KeyDatabase];
string dataset;

Expand All @@ -1677,6 +1678,8 @@ public static (bool, bool, bool) ValidateSiteProperties(IVsDataConnectionPropert
// Evs.Trace(typeof(RctManager), "ValidateSiteProperties()", "connectionSource: {0}, serverExplorerInsertMode: {1}, proposedConnectionName: {2}, proposedDatasetName: {3}, dataSource: {4}, dataset: {5}.",
// connectionSource, serverExplorerInsertMode, proposedConnectionName, proposedDatasetName, dataSource, dataset);

if (!string.IsNullOrEmpty(dataSource))
dataSource = RegisterServer(dataSource, port);

// Validate the proposed names.
bool rctExists = Instance.GenerateUniqueDatasetKey(connectionSource, ref proposedConnectionName, ref proposedDatasetName,
Expand Down
Loading

0 comments on commit 4ca4c04

Please sign in to comment.