mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Added ToFree and ToFree<T: class>. Objects added in this list will be freed after action execution. It is very useful for functional actions.
Also, the route logger emits a ERROR log if the status code is >= 500 indipendently if an exception has been raised or not
This commit is contained in:
parent
292694d2dd
commit
6ac033b809
@ -910,6 +910,7 @@ type
|
|||||||
/// After action execution frees all the objects added. Works only with functional actions.
|
/// After action execution frees all the objects added. Works only with functional actions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
function ToFree<T: class>(aObject: T): T; overload;
|
function ToFree<T: class>(aObject: T): T; overload;
|
||||||
|
procedure ToFree(aObject: TObject); overload;
|
||||||
|
|
||||||
procedure OnBeforeAction(AContext: TWebContext; const AActionName: string;
|
procedure OnBeforeAction(AContext: TWebContext; const AActionName: string;
|
||||||
var AHandled: Boolean); virtual;
|
var AHandled: Boolean); virtual;
|
||||||
@ -2573,20 +2574,27 @@ begin
|
|||||||
const Sender: TMVCCustomRouter;
|
const Sender: TMVCCustomRouter;
|
||||||
const RouterLogState: TMVCRouterLogState;
|
const RouterLogState: TMVCRouterLogState;
|
||||||
const Context: TWebContext)
|
const Context: TWebContext)
|
||||||
|
var
|
||||||
|
lStatusCode: Word;
|
||||||
begin
|
begin
|
||||||
|
lStatusCode := Context.Response.StatusCode;
|
||||||
case RouterLogState of
|
case RouterLogState of
|
||||||
rlsRouteFound:
|
rlsRouteFound:
|
||||||
begin
|
begin
|
||||||
|
if lStatusCode < HTTP_STATUS.InternalServerError then
|
||||||
LogI(Context.Request.HTTPMethodAsString + ':' +
|
LogI(Context.Request.HTTPMethodAsString + ':' +
|
||||||
Context.Request.PathInfo + ' [' + Context.Request.ClientIp + '] -> ' +
|
Context.Request.PathInfo + ' [' + Context.Request.ClientIp + '] -> ' +
|
||||||
Sender.GetQualifiedActionName + ' - ' + IntToStr(Context.Response.StatusCode) + ' ' +
|
Sender.GetQualifiedActionName + ' - ' + IntToStr(lStatusCode))
|
||||||
Context.Response.ReasonString);
|
else
|
||||||
|
LogE(Context.Request.HTTPMethodAsString + ':' +
|
||||||
|
Context.Request.PathInfo + ' [' + Context.Request.ClientIp + '] -> ' +
|
||||||
|
Sender.GetQualifiedActionName + ' - ' + IntToStr(lStatusCode))
|
||||||
end;
|
end;
|
||||||
rlsRouteNotFound:
|
rlsRouteNotFound:
|
||||||
begin
|
begin
|
||||||
LogW(Context.Request.HTTPMethodAsString + ':' +
|
LogW(Context.Request.HTTPMethodAsString + ':' +
|
||||||
Context.Request.PathInfo + ' [' + Context.Request.ClientIp + '] -> {ROUTE NOT FOUND} - ' +
|
Context.Request.PathInfo + ' [' + Context.Request.ClientIp + '] -> {ROUTE NOT FOUND} - ' +
|
||||||
IntToStr(Context.Response.StatusCode) + ' ' + Context.Response.ReasonString);
|
IntToStr(Context.Response.StatusCode));
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
raise EMVCException.Create('Invalid RouterLogState');
|
raise EMVCException.Create('Invalid RouterLogState');
|
||||||
@ -4200,13 +4208,18 @@ begin
|
|||||||
Result := GetSHA1HashFromString(Data);
|
Result := GetSHA1HashFromString(Data);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMVCController.ToFree<T>(aObject: T): T;
|
procedure TMVCController.ToFree(aObject: TObject);
|
||||||
begin
|
begin
|
||||||
if not Assigned(fFreeList) then
|
if not Assigned(fFreeList) then
|
||||||
begin
|
begin
|
||||||
fFreeList := TObjectList<TObject>.Create(True);
|
fFreeList := TObjectList<TObject>.Create(True);
|
||||||
end;
|
end;
|
||||||
fFreeList.Add(aObject);
|
fFreeList.Add(aObject);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMVCController.ToFree<T>(aObject: T): T;
|
||||||
|
begin
|
||||||
|
ToFree(aObject);
|
||||||
Result := aObject;
|
Result := aObject;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4892,32 +4905,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TMVCController.GetRenderedView(const AViewNames: TArray<string>; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string;
|
function TMVCController.GetRenderedView(const AViewNames: TArray<string>; const OnBeforeRenderCallback: TMVCSSVBeforeRenderCallback): string;
|
||||||
var
|
|
||||||
lView: TMVCBaseViewEngine;
|
|
||||||
lViewName: string;
|
|
||||||
lStrStream: TStringBuilder;
|
|
||||||
begin
|
begin
|
||||||
lStrStream := TStringBuilder.Create;
|
Result := GetRenderedView(AViewNames, nil, OnBeforeRenderCallback);
|
||||||
try
|
|
||||||
lView := FEngine.ViewEngineClass.Create(
|
|
||||||
Engine,
|
|
||||||
Context,
|
|
||||||
Self,
|
|
||||||
FViewModel,
|
|
||||||
ContentType);
|
|
||||||
try
|
|
||||||
lView.FBeforeRenderCallback := OnBeforeRenderCallback;
|
|
||||||
for lViewName in AViewNames do
|
|
||||||
begin
|
|
||||||
lView.Execute(lViewName, lStrStream);
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
lView.Free;
|
|
||||||
end;
|
|
||||||
Result := lStrStream.ToString;
|
|
||||||
finally
|
|
||||||
lStrStream.Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMVCRenderer.Render<T>(const ACollection: TObjectList<T>;
|
procedure TMVCRenderer.Render<T>(const ACollection: TObjectList<T>;
|
||||||
|
Loading…
Reference in New Issue
Block a user