- messages and subscription expiring

- refactoring
- fixing border-case bugs
This commit is contained in:
Daniele Teti 2021-10-20 11:12:57 +02:00
parent cda0651182
commit 18ae4a86f9
5 changed files with 48 additions and 21 deletions

View File

@ -439,7 +439,8 @@ type
['{7B87473C-1784-489F-A838-925E7DDD0DE2}'] ['{7B87473C-1784-489F-A838-925E7DDD0DE2}']
procedure AddConnection(const aName: string; const aConnection: TFDConnection; procedure AddConnection(const aName: string; const aConnection: TFDConnection;
const Owns: Boolean = false); const Owns: Boolean = false);
procedure AddDefaultConnection(const aConnection: TFDConnection; const Owns: Boolean = false); procedure AddDefaultConnection(const aConnection: TFDConnection; const Owns: Boolean = false); overload;
procedure AddDefaultConnection(const aConnectionDefName: String); overload;
procedure RemoveConnection(const aName: string; const RaiseExceptionIfNotAvailable: Boolean = True); procedure RemoveConnection(const aName: string; const RaiseExceptionIfNotAvailable: Boolean = True);
procedure RemoveDefaultConnection(const RaiseExceptionIfNotAvailable: Boolean = True); procedure RemoveDefaultConnection(const RaiseExceptionIfNotAvailable: Boolean = True);
procedure SetCurrent(const aName: string); procedure SetCurrent(const aName: string);
@ -467,7 +468,8 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure AddConnection(const aName: string; const aConnection: TFDConnection; procedure AddConnection(const aName: string; const aConnection: TFDConnection;
const aOwns: Boolean = false); const aOwns: Boolean = false);
procedure AddDefaultConnection(const aConnection: TFDConnection; const aOwns: Boolean = false); procedure AddDefaultConnection(const aConnection: TFDConnection; const aOwns: Boolean = false); overload;
procedure AddDefaultConnection(const aConnectionDefName: String); overload;
procedure RemoveConnection(const aName: string; const RaiseExceptionIfNotAvailable: Boolean = True); procedure RemoveConnection(const aName: string; const RaiseExceptionIfNotAvailable: Boolean = True);
procedure RemoveDefaultConnection(const RaiseExceptionIfNotAvailable: Boolean = True); procedure RemoveDefaultConnection(const RaiseExceptionIfNotAvailable: Boolean = True);
procedure SetCurrent(const aName: string); procedure SetCurrent(const aName: string);
@ -716,6 +718,24 @@ begin
AddConnection('default', aConnection, aOwns); AddConnection('default', aConnection, aOwns);
end; end;
procedure TMVCConnectionsRepository.AddDefaultConnection(
const aConnectionDefName: String);
var
lConn: TFDConnection;
begin
lConn := TFDConnection.Create(nil);
try
lConn.ConnectionDefName := aConnectionDefName;
AddDefaultConnection(lConn, True);
except
on E: Exception do
begin
lConn.Free;
raise;
end;
end;
end;
constructor TMVCConnectionsRepository.Create; constructor TMVCConnectionsRepository.Create;
begin begin
inherited; inherited;

View File

@ -139,7 +139,7 @@ begin
// create gzip compliant streams // create gzip compliant streams
{.$ELSE} {.$ELSE}
lZStream := TZCompressionStream.Create(lMemStream, lZStream := TZCompressionStream.Create(lMemStream,
TZCompressionLevel.zcDefault, MVC_COMPRESSION_ZLIB_WINDOW_BITS TZCompressionLevel.zcMax, MVC_COMPRESSION_ZLIB_WINDOW_BITS
[lRespCompressionType]); [lRespCompressionType]);
try try
lContentStream.Position := 0; lContentStream.Position := 0;

View File

@ -40,7 +40,7 @@ uses
MVCFramework.Serializer.Intf, MVCFramework.Serializer.Intf,
MVCFramework.Commons, MVCFramework.Commons,
MVCFramework.Serializer.Commons, MVCFramework.Serializer.Commons,
Data.DB; Data.DB, JsonDataObjects;
type type
IMVCRESTResponse = interface; IMVCRESTResponse = interface;
@ -459,6 +459,8 @@ type
function ContentRawBytes: TBytes; function ContentRawBytes: TBytes;
procedure SaveContentToStream(aStream: TStream); procedure SaveContentToStream(aStream: TStream);
procedure SaveContentToFile(const aFileName: string); procedure SaveContentToFile(const aFileName: string);
function ToJSONObject: TJDOJsonObject;
function ToJSONArray: TJDOJsonArray;
end; end;
implementation implementation

View File

@ -46,7 +46,7 @@ uses
MVCFramework.RESTClient.Commons, MVCFramework.RESTClient.Commons,
MVCFramework.Serializer.Intf, MVCFramework.Serializer.Intf,
MVCFramework.Serializer.Commons, MVCFramework.Serializer.Commons,
Data.DB; Data.DB, JsonDataObjects;
type type
/// <summary> /// <summary>
@ -506,6 +506,8 @@ type
function ContentRawBytes: TBytes; function ContentRawBytes: TBytes;
procedure SaveContentToStream(aStream: TStream); procedure SaveContentToStream(aStream: TStream);
procedure SaveContentToFile(const aFileName: string); procedure SaveContentToFile(const aFileName: string);
function ToJSONObject: TJDOJsonObject;
function ToJSONArray: TJDOJsonArray;
end; end;
implementation implementation
@ -1761,6 +1763,16 @@ end;
{ TMVCRESTResponse } { TMVCRESTResponse }
function TMVCRESTResponse.ToJSONArray: TJDOJsonArray;
begin
Result := StrTOJSONArray(fContent, True);
end;
function TMVCRESTResponse.ToJSONObject: TJDOJsonObject;
begin
Result := StrTOJSONObject(fContent, True);
end;
function TMVCRESTResponse.Content: string; function TMVCRESTResponse.Content: string;
begin begin
Result := fContent; Result := fContent;

View File

@ -1085,18 +1085,18 @@ uses
MVCFramework.Serializer.HTML, MVCFramework.Serializer.Abstract; MVCFramework.Serializer.HTML, MVCFramework.Serializer.Abstract;
var var
_IsShuttingDown: Int64 = 0; gIsShuttingDown: Int64 = 0;
_MVCGlobalActionParamsCache: TMVCStringObjectDictionary<TMVCActionParamCacheItem> = nil; gMVCGlobalActionParamsCache: TMVCStringObjectDictionary<TMVCActionParamCacheItem> = nil;
_HostingFramework: TMVCHostingFrameworkType = hftUnknown; gHostingFramework: TMVCHostingFrameworkType = hftUnknown;
function IsShuttingDown: Boolean; function IsShuttingDown: Boolean;
begin begin
Result := TInterlocked.Read(_IsShuttingDown) = 1 Result := TInterlocked.Read(gIsShuttingDown) = 1
end; end;
procedure EnterInShutdownState; procedure EnterInShutdownState;
begin begin
TInterlocked.Add(_IsShuttingDown, 1); TInterlocked.Add(gIsShuttingDown, 1);
end; end;
function CreateResponse(const StatusCode: UInt16; const ReasonString: string; function CreateResponse(const StatusCode: UInt16; const ReasonString: string;
@ -2333,7 +2333,7 @@ begin
try try
DefineDefaultResponseHeaders(lContext); DefineDefaultResponseHeaders(lContext);
lHandled := False; lHandled := False;
lRouter := TMVCRouter.Create(FConfig, _MVCGlobalActionParamsCache); lRouter := TMVCRouter.Create(FConfig, gMVCGlobalActionParamsCache);
try // finally try // finally
lSelectedController := nil; lSelectedController := nil;
try // only for lSelectedController try // only for lSelectedController
@ -4087,21 +4087,14 @@ begin
FFormat := AFormat; FFormat := AFormat;
end; end;
{ TMVCHackHTTPAppRequest }
// function TMVCHackHTTPAppRequest.GetHeaders: TStringList;
// begin
// Result := FRequestInfo.RawHeaders;
// end;
initialization initialization
_IsShuttingDown := 0; gIsShuttingDown := 0;
_MVCGlobalActionParamsCache := TMVCStringObjectDictionary<TMVCActionParamCacheItem>.Create; gMVCGlobalActionParamsCache := TMVCStringObjectDictionary<TMVCActionParamCacheItem>.Create;
finalization finalization
FreeAndNil(_MVCGlobalActionParamsCache); FreeAndNil(gMVCGlobalActionParamsCache);
end. end.