Skip to content

Commit 684f5fc

Browse files
Configuration of the database session is updated to use a datastore instead of separate properties.
1 parent 8515b1c commit 684f5fc

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

dotnet/src/dotnetcore/GxClasses/Services/Session/GXSessionFactory.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using GeneXus.Application;
23
using GeneXus.Configuration;
4+
using GeneXus.Data;
35
using GeneXus.Encryption;
46
using GxClasses.Helpers;
57
using log4net;
@@ -110,47 +112,44 @@ public class GxDatabaseSession : ISessionService
110112
internal static string SESSION_PASSWORD = "SESSION_PROVIDER_PASSWORD";
111113
internal static string SESSION_SCHEMA = "SESSION_PROVIDER_SCHEMA";
112114
internal static string SESSION_TABLE_NAME = "SESSION_PROVIDER_TABLE_NAME";
113-
internal static string SESSION_PROVIDER_SERVER = "SESSION_PROVIDER_SERVER";
114-
internal static string SESSION_PROVIDER_DATABASE = "SESSION_PROVIDER_DATABASE";
115-
internal static string SESSION_PROVIDER_USER = "SESSION_PROVIDER_USER";
115+
internal static string SESSION_DATASTORE = "SESSION_PROVIDER_DATASTORE";
116116

117117
public GxDatabaseSession(GXService serviceProvider)
118118
{
119-
string password = serviceProvider.Properties.Get(SESSION_PASSWORD);
120-
if (!string.IsNullOrEmpty(password))
119+
string datastoreName = serviceProvider.Properties.Get(SESSION_DATASTORE);
120+
if (!string.IsNullOrEmpty(datastoreName))
121121
{
122-
password = CryptoImpl.Decrypt(password);
122+
GxContext context = GxContext.CreateDefaultInstance();
123+
IGxDataStore datastore = context.GetDataStore(datastoreName);
124+
string schema = datastore.Connection.CurrentSchema;
125+
string tableName = serviceProvider.Properties.Get(SESSION_TABLE_NAME);
126+
ConnectionString = datastore.Connection.ConnectionString;
127+
Schema = schema;
128+
TableName = tableName;
129+
context.CloseConnections();
123130
}
124-
string serverName = serviceProvider.Properties.Get(SESSION_PROVIDER_SERVER);
125-
string userName = serviceProvider.Properties.Get(SESSION_PROVIDER_USER);
126-
string database = serviceProvider.Properties.Get(SESSION_PROVIDER_DATABASE);
127-
string schema = serviceProvider.Properties.Get(SESSION_SCHEMA);
128-
string tableName = serviceProvider.Properties.Get(SESSION_TABLE_NAME);
129-
130-
string sessionAddresCompatibility = serviceProvider.Properties.Get(GxDatabaseSession.SESSION_ADDRESS);
131-
if (!string.IsNullOrEmpty(sessionAddresCompatibility))
131+
else //Backward compatibility configuration
132132
{
133-
ConnectionString = sessionAddresCompatibility;
134-
}
133+
string password = serviceProvider.Properties.Get(SESSION_PASSWORD);
134+
if (!string.IsNullOrEmpty(password))
135+
{
136+
password = CryptoImpl.Decrypt(password);
137+
}
138+
string schema = serviceProvider.Properties.Get(SESSION_SCHEMA);
139+
string tableName = serviceProvider.Properties.Get(SESSION_TABLE_NAME);
140+
string sessionAddresCompatibility = serviceProvider.Properties.Get(SESSION_ADDRESS);
141+
if (!string.IsNullOrEmpty(sessionAddresCompatibility))
142+
{
143+
ConnectionString = sessionAddresCompatibility;
144+
}
145+
if (!string.IsNullOrEmpty(password))
146+
{
147+
ConnectionString += $";password={password}";
148+
}
149+
Schema = schema;
150+
TableName = tableName;
135151

136-
if (!string.IsNullOrEmpty(serverName))
137-
{
138-
ConnectionString += $"Data Source={serverName};";
139-
}
140-
if (!string.IsNullOrEmpty(database))
141-
{
142-
ConnectionString += $"Initial Catalog={database}";
143152
}
144-
if (!string.IsNullOrEmpty(password))
145-
{
146-
ConnectionString += $";password={password}";
147-
}
148-
if (!string.IsNullOrEmpty(userName))
149-
{
150-
ConnectionString += $";user={userName}";
151-
}
152-
Schema = schema;
153-
TableName = tableName;
154153
SessionTimeout = Preferences.SessionTimeout;
155154
}
156155
public GxDatabaseSession(string host, string password, string schema, string tableName)

0 commit comments

Comments
 (0)