Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add async interfaces for http procedures #987

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dotnet/src/dotnetcore/GxClasses.Web/Middleware/HandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GeneXus.Configuration;
using GeneXus.Http;
using GeneXus.Mime;
using GeneXus.Procedure;
using GeneXus.Utils;
using Microsoft.AspNetCore.Http;

Expand Down Expand Up @@ -74,8 +75,16 @@ public async Task Invoke(HttpContext context)
handler.sendAdditionalHeaders();
return Task.CompletedTask;
});
handler.ProcessRequest(context);
await Task.CompletedTask;
GXWebProcedure gxWebProc = handler as GXWebProcedure;
if (gxWebProc != null && gxWebProc.GetAsyncEnabledInternal())
{
await gxWebProc.ProcessRequestAsync(context);
}
else
{
handler.ProcessRequest(context);
await Task.CompletedTask;
}
handler.ControlOutputWriter?.Flush();
}
else
Expand Down
17 changes: 17 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace GeneXus.Application
using System.Security.Claims;
using System.Security;
using Microsoft.Net.Http.Headers;
using System.Threading.Tasks;
using GeneXus.Data.ADO;

public interface IGxContext
{
Expand Down Expand Up @@ -1407,12 +1409,27 @@ public IGxDataStore GetDataStore(string id)
return ds;
return null;
}
#if NETCORE
internal async Task CloseConnectionsAsync()
{
GxUserInfo.RemoveHandle(this.handle);
foreach (GxDataStore ds in _DataStores)
await ds.CloseConnectionsAsync();

CloseConnectionsResources();
}
#endif
public void CloseConnections()
{
GxUserInfo.RemoveHandle(this.handle);
foreach (IGxDataStore ds in _DataStores)
ds.CloseConnections();

CloseConnectionsResources();
}

private void CloseConnectionsResources()
{
if (_reportHandlerToClose != null)
{
for (int i = 0; i < _reportHandlerToClose.Count; i++)
Expand Down
39 changes: 23 additions & 16 deletions dotnet/src/dotnetframework/GxClasses/Core/Web/HttpAjaxContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,29 +685,36 @@ internal static JArray GetParmsJArray(Object[] parms)

public string GetAjaxEncryptionKey()
{
if (context.ReadSessionKey<string>(CryptoImpl.AJAX_ENCRYPTION_KEY) == null)
string ajaxKey = context.ReadSessionKey<string>(CryptoImpl.AJAX_ENCRYPTION_KEY);
if (ajaxKey == null)
{
if(!RecoverEncryptionKey())
context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY,CryptoImpl.GetRijndaelKey());
string sessionKey;
if (!RecoverEncryptionKey(out sessionKey)) {
ajaxKey = CryptoImpl.GetRijndaelKey();
context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY, ajaxKey);
}
else
{
ajaxKey = sessionKey;
}
}
return context.ReadSessionKey<string>(CryptoImpl.AJAX_ENCRYPTION_KEY);
return ajaxKey;
}
private bool RecoverEncryptionKey()
private bool RecoverEncryptionKey(out string sessionKey)
{
if ( (context.ReadSessionKey<string>(CryptoImpl.AJAX_ENCRYPTION_KEY) == null))
sessionKey = null;
if (context.HttpContext != null)
{
if (context.HttpContext != null)
String clientKey = context.HttpContext.Request.Headers[CryptoImpl.AJAX_SECURITY_TOKEN];
if (!string.IsNullOrEmpty(clientKey))
{
String clientKey = context.HttpContext.Request.Headers[CryptoImpl.AJAX_SECURITY_TOKEN];
if (!string.IsNullOrEmpty(clientKey))
bool correctKey;
clientKey = CryptoImpl.DecryptRijndael(CryptoImpl.GX_AJAX_PRIVATE_IV + clientKey, CryptoImpl.GX_AJAX_PRIVATE_KEY, out correctKey);
if (correctKey)
{
bool correctKey = false;
clientKey = CryptoImpl.DecryptRijndael(CryptoImpl.GX_AJAX_PRIVATE_IV + clientKey, CryptoImpl.GX_AJAX_PRIVATE_KEY, out correctKey);
if (correctKey)
{
context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY, clientKey);
return true;
}
sessionKey = clientKey;
context.WriteSessionKey(CryptoImpl.AJAX_ENCRYPTION_KEY, clientKey);
return true;
}
}
}
Expand Down
83 changes: 82 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using GeneXus.Application;
using GeneXus.Cache;
using GeneXus.Configuration;
Expand Down Expand Up @@ -212,7 +213,22 @@ public void RemoveAllConnections(int handle)
throw e;
}
}
#if NETCORE
internal async Task RemoveConnectionAsync(int handle, string dataSource)
{

ServerUserInformation sui;
if (userConnections.TryGetValue(handle, out sui))
{
GXLogging.Debug(log, "RemoveConnection handle " + handle + ",datasource:" + dataSource);
GxConnection con = sui[dataSource];
if (sui.TryRemove(dataSource, out con))
await con.DisposeAsync();
ServerUserInformation suiDeleted;
if (sui.Count == 0) userConnections.TryRemove(handle, out suiDeleted);
}
}
#endif
public void RemoveConnection(int handle, string dataSource)
{

Expand Down Expand Up @@ -411,7 +427,12 @@ public void Dispose()
{
Close();
}

#if NETCORE
internal async Task DisposeAsync()
{
await CloseAsync();
}
#endif
public IGxDataStore DataStore
{
get{ return dataStore;}
Expand Down Expand Up @@ -736,7 +757,61 @@ public void Close()
wmiconnection.CleanUp();
}
}
#if NETCORE
internal async Task CloseAsync()
{
if (connection != null)
{
GXLogging.Debug(log, "GxConnection.Close Id " + " connection State '" + connection.State + "'" + " handle:" + handle + " datastore:" + DataStore.Id);
}
if (connection != null && ((connection.State & ConnectionState.Closed) == 0))
{
try
{
connectionCache.Clear();
}
catch (Exception e)
{
GXLogging.Warn(log, "GxConnection.Close can't close all prepared cursors", e);
}

GXLogging.Debug(log, "UncommitedChanges before Close:" + UncommitedChanges);
try
{
if (UncommitedChanges)
{
rollbackTransactionOnly();
UncommitedChanges = false;
}
}
catch (Exception e)
{
GXLogging.Warn(log, "GxConnection.Close can't rollback transaction", e);
}
try
{
await connection.CloseAsync();
if (transaction != null)
{
transaction.Dispose();
transaction = null;
}

}
catch (Exception e)
{
GXLogging.Warn(log, "GxConnection.Close can't close connection", e);
}
spid = 0;
GXLogging.Debug(log, "GxConnection.Close connection is closed ");
}
m_opened = false;
if (Preferences.Instrumented && wmiconnection != null)
{
wmiconnection.CleanUp();
}
}
#endif
public int OpenHandles
{
get{return openHandles;}
Expand Down Expand Up @@ -2837,6 +2912,12 @@ public void CloseConnections()
{
GxConnectionManager.Instance.RemoveConnection(handle, id);
}
#if NETCORE
internal async Task CloseConnectionsAsync()
{
await ((GxConnectionManager)GxConnectionManager.Instance).RemoveConnectionAsync(handle, id);
}
#endif
public void Release()
{
}
Expand Down
22 changes: 22 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using GeneXus.Metadata;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;

namespace GeneXus.Data
{
Expand Down Expand Up @@ -4338,7 +4339,28 @@ public virtual void Close()
{
InternalConnection.Close();
}
#if NETCORE
internal virtual async Task CloseAsync()
{
try
{

DbConnection dbConnection = InternalConnection as DbConnection;
if (dbConnection != null)
{
await dbConnection.CloseAsync();
}
else
{
InternalConnection.Close();
}
}
catch (Exception ex)
{
throw new DataException(ex.Message, ex);
}
}
#endif
public void ChangeDatabase(String database)
{
throw new NotSupportedException("NoChangeMsg00" + database);
Expand Down
16 changes: 15 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Data/GXDataDb2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GeneXus.Application;
using GeneXus.Cache;
using GeneXus.Metadata;
Expand Down Expand Up @@ -655,7 +656,20 @@ override public void Close()
throw new DataException(ex.Message, ex);
}
}

#if NETCORE
internal override async Task CloseAsync()
{
try
{
CheckState(false);
await base.CloseAsync();
}
catch (Exception ex)
{
throw new DataException(ex.Message, ex);
}
}
#endif
override public IDbCommand CreateCommand()
{
return InternalConnection.CreateCommand();
Expand Down
17 changes: 15 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataHana.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using GeneXus.Cache;
using GeneXus.Metadata;
using GeneXus.Utils;
Expand Down Expand Up @@ -415,15 +416,27 @@ override public void Close()
{
try
{
CheckState(false);
InternalConnection.Close();
}
catch (Exception ex)
{
throw new DataException(ex.Message, ex);
}
}

#if NETCORE
internal override async Task CloseAsync()
{
try
{
CheckState(false);
await base.CloseAsync();
}
catch (Exception ex)
{
throw new DataException(ex.Message, ex);
}
}
#endif
override public IDbCommand CreateCommand()
{
return InternalConnection.CreateCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ override public void Close()
{
try
{
CheckState(false);
InternalConnection.Close();
}
catch (Exception ex)
Expand Down
9 changes: 9 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ public static void Warn(ILog log, string msg, Exception ex)
log.Warn(msg, ex);
}
}
internal static void DebugSanitized(IGXLogger log, string startMsg, Func<string> buildMsg)
{
if (log.IsDebugEnabled)
{
string msg = buildMsg();
DebugSanitized(log, startMsg + msg);
}
}

public static void DebugSanitized(ILog log, Exception ex, params string[] list)
{
if (log.IsDebugEnabled)
Expand Down
Loading
Loading