Merge remote-tracking branch 'upstream/master' into middleware_staticfiles

This commit is contained in:
João Antônio Duarte 2020-04-28 21:12:55 -03:00
commit f324701a3c
18 changed files with 102 additions and 45 deletions

View File

@ -524,6 +524,8 @@ end;
- Fixed! [issue363](https://github.com/danieleteti/delphimvcframework/issues/363)
- Fixed! [issue364](https://github.com/danieleteti/delphimvcframework/issues/364) (Thanks to [João Antônio Duarte](https://github.com/joaoduarte19))
- Fixed! [issue366](https://github.com/danieleteti/delphimvcframework/issues/366)
- **Breaking Change!** In `MVCActiveRecord` attribute `MVCPrimaryKey` has been removed and merged with `MVCTableField`, so now `TMVCActiveRecordFieldOption` is a set of `foPrimaryKey`, `foAutoGenerated`, `foTransient` (check `activerecord_showcase.dproj` sample).

View File

@ -24,7 +24,13 @@ type
implementation
uses
System.SysUtils, Winapi.Windows, Winapi.Messages, System.IOUtils;
System.SysUtils,
System.IOUtils
{$IFDEF MSWINDOWS}
, Winapi.Windows
, Winapi.Messages
{$ENDIF}
;
{ TStringsLogAppender }
const
@ -37,7 +43,9 @@ end;
procedure TLoggerProOutputDebugStringAppender.Setup;
begin
{$IFDEF MSWINDOWS}
FModuleName := TPath.GetFileName(GetModuleName(HInstance));
{$ENDIF}
end;
procedure TLoggerProOutputDebugStringAppender.TearDown;
@ -47,13 +55,17 @@ end;
procedure TLoggerProOutputDebugStringAppender.WriteLog(const aLogItem
: TLogItem);
{$IFDEF MSWINDOWS}
var
lLog: string;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
lLog := '(' + FModuleName + ') ' + Format(DEFAULT_LOG_FORMAT,
[datetimetostr(aLogItem.TimeStamp), aLogItem.ThreadID,
aLogItem.LogTypeAsString, aLogItem.LogMessage, aLogItem.LogTag]);
OutputDebugString(PChar(lLog));
{$ENDIF}
end;
end.

View File

@ -20,7 +20,7 @@ type
TLogType = (Debug = 0, Info, Warning, Error);
TLogErrorReason = (QueueFull);
TLogErrorAction = (SkipNewest, DiscardOlder);
TLogExtendedInfo = (EIUserName, EIComputerName, EIProcessName, EIProcessID, EIDeviceID { mobile } );
TLogExtendedInfo = (EIUserName, EIComputerName, EIProcessName, EIProcessID, EIDeviceID { mobile });
TLoggerProExtendedInfo = set of TLogExtendedInfo;
{ @abstract(Represent the single log item)
@ -132,6 +132,8 @@ type
function GetAppendersClassNames: TArray<string>;
function GetAppenders(const Index: Integer): ILogAppender;
property Appenders[const index: Integer]: ILogAppender read GetAppenders;
procedure AddAppender(const aAppenders: ILogAppender);
procedure DelAppender(const aAppenders: ILogAppender);
function AppendersCount(): Integer;
end;
@ -146,8 +148,8 @@ type
protected
procedure Execute; override;
type
TAppenderStatus = (BeforeSetup, Running, WaitAfterFail, ToRestart, BeforeTearDown);
type
TAppenderStatus = (BeforeSetup, Running, WaitAfterFail, ToRestart, BeforeTearDown);
public
constructor Create(aLogAppender: ILogAppender; aAppenderQueue: TAppenderQueue);
property Failing: Boolean read FFailing write SetFailing;
@ -155,30 +157,31 @@ type
TLoggerThread = class(TThread)
private type
TAppenderAdapter = class
private
FAppenderQueue: TAppenderQueue;
FAppenderThread: TAppenderThread;
FLogAppender: ILogAppender;
FFailsCount: Cardinal;
public
constructor Create(aAppender: ILogAppender); virtual;
destructor Destroy; override;
function EnqueueLog(const aLogItem: TLogItem): Boolean;
property Queue: TAppenderQueue read FAppenderQueue;
property FailsCount: Cardinal read FFailsCount;
function GetLogLevel: TLogType;
end;
TAppenderAdapter = class
private
FAppenderQueue: TAppenderQueue;
FAppenderThread: TAppenderThread;
FLogAppender: ILogAppender;
FFailsCount: Cardinal;
public
constructor Create(aAppender: ILogAppender); virtual;
destructor Destroy; override;
function EnqueueLog(const aLogItem: TLogItem): Boolean;
property Queue: TAppenderQueue read FAppenderQueue;
property FailsCount: Cardinal read FFailsCount;
function GetLogLevel: TLogType;
end;
TAppenderAdaptersList = class(TObjectList<TAppenderAdapter>)
public
constructor Create;
end;
TAppenderAdaptersList = class(TObjectList<TAppenderAdapter>)
public
constructor Create;
end;
private
FQueue: TThreadSafeQueue<TLogItem>;
FAppenders: TLogAppenderList;
FEventsHandlers: TLoggerProEventsHandler;
FAppendersDecorators: TObjectList<TAppenderAdapter>;
function BuildAppendersDecorator: TAppenderAdaptersList;
procedure DoOnAppenderError(const FailAppenderClassName: string; const aFailedLogItem: TLogItem; const aReason: TLogErrorReason;
var aAction: TLogErrorAction);
@ -191,7 +194,7 @@ type
destructor Destroy; override;
property EventsHandlers: TLoggerProEventsHandler read FEventsHandlers write SetEventsHandlers;
property LogWriterQueue: TThreadSafeQueue<TLogItem> read FQueue;
property LogWriterQueue: TThreadSafeQueue < TLogItem > read FQueue;
end;
TLoggerProInterfacedObject = class(TInterfacedObject)
@ -210,6 +213,8 @@ type
function GetAppendersClassNames: TArray<string>;
public
function GetAppenders(const Index: Integer): ILogAppender;
procedure AddAppender(const aAppender: ILogAppender);
procedure DelAppender(const aAppender: ILogAppender);
function AppendersCount(): Integer;
constructor Create(aLogLevel: TLogType = TLogType.Debug); overload;
constructor Create(aLogAppenders: TLogAppenderList; aLogLevel: TLogType = TLogType.Debug); overload;
@ -412,6 +417,30 @@ begin
Result := Self.FLogAppenders[index];
end;
procedure TLogWriter.AddAppender(const aAppender: ILogAppender);
begin
Self.FLoggerThread.FAppenders.Add(aAppender);
Self.FLogAppenders.Add(aAppender);
Self.FLoggerThread.FAppendersDecorators.Add(TLoggerThread.TAppenderAdapter.Create(aAppender));
end;
procedure TLogWriter.DelAppender(const aAppender: ILogAppender);
var
i: Integer;
begin
i := Self.FLoggerThread.FAppenders.IndexOf(aAppender);
if i >= 0 then
Self.FLoggerThread.FAppenders.Delete(i);
i := Self.FLogAppenders.IndexOf(aAppender);
if i >= 0 then
Self.FLogAppenders.Delete(i);
for I := 0 to Self.FLoggerThread.FAppendersDecorators.Count - 1 do
if Self.FLoggerThread.FAppendersDecorators[i].FLogAppender = aAppender then
Self.FLoggerThread.FAppendersDecorators.Delete(i);
end;
function TLogWriter.GetAppendersClassNames: TArray<string>;
var
I: Cardinal;
@ -543,11 +572,10 @@ var
lQSize: UInt64;
lLogItem: TLogItem;
I: Integer;
lAppendersDecorators: TObjectList<TAppenderAdapter>;
lAction: TLogErrorAction;
lWaitResult: TWaitResult;
begin
lAppendersDecorators := BuildAppendersDecorator;
FAppendersDecorators := BuildAppendersDecorator;
try
while true do
begin
@ -558,14 +586,14 @@ begin
if lLogItem <> nil then
begin
try
for I := 0 to lAppendersDecorators.Count - 1 do
for I := 0 to FAppendersDecorators.Count - 1 do
begin
if lLogItem.LogType >= lAppendersDecorators[I].GetLogLevel then
if lLogItem.LogType >= FAppendersDecorators[I].GetLogLevel then
begin
if not lAppendersDecorators[I].EnqueueLog(lLogItem) then
if not FAppendersDecorators[I].EnqueueLog(lLogItem) then
begin
lAction := TLogErrorAction.SkipNewest; // default
DoOnAppenderError(TObject(lAppendersDecorators[I].FLogAppender).ClassName, lLogItem,
DoOnAppenderError(TObject(FAppendersDecorators[I].FLogAppender).ClassName, lLogItem,
TLogErrorReason.QueueFull, lAction);
case lAction of
TLogErrorAction.SkipNewest:
@ -575,7 +603,7 @@ begin
TLogErrorAction.DiscardOlder:
begin
// just remove the oldest log message
lAppendersDecorators[I].Queue.Dequeue.Free;
FAppendersDecorators[I].Queue.Dequeue.Free;
end;
end;
end;
@ -599,7 +627,7 @@ begin
end;
finally
lAppendersDecorators.Free;
FAppendersDecorators.Free;
end;
end;
@ -864,3 +892,4 @@ begin
end;
end.

View File

@ -48,6 +48,7 @@ contains
LoggerPro.RESTAppender in '..\..\LoggerPro.RESTAppender.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -120,6 +120,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@ -178,7 +179,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT.bpl" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT100.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>loggerproRT.bpl</RemoteName>
<Overwrite>true</Overwrite>

View File

@ -48,6 +48,7 @@ contains
LoggerPro.RESTAppender in '..\..\LoggerPro.RESTAppender.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -120,6 +120,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@ -179,7 +180,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT.bpl" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT101.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>loggerproRT.bpl</RemoteName>
<Overwrite>true</Overwrite>

View File

@ -48,6 +48,7 @@ contains
LoggerPro.RESTAppender in '..\..\LoggerPro.RESTAppender.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -120,6 +120,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@ -178,7 +179,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT.bpl" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRT102.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>loggerproRT.bpl</RemoteName>
<Overwrite>true</Overwrite>

View File

@ -48,6 +48,7 @@ contains
LoggerPro.RESTAppender in '..\..\LoggerPro.RESTAppender.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -93,7 +93,6 @@
<VerInfo_Locale>1033</VerInfo_Locale>
<DCC_Description>LoggerPro</DCC_Description>
<DllSuffix>103</DllSuffix>
<DCC_DebugDCUs>false</DCC_DebugDCUs>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
@ -121,6 +120,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@ -142,10 +142,11 @@
<Source Name="MainSource">loggerproRT.dpk</Source>
</Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\bcboffice2k260.bpl">Embarcadero C++Builder Office 2000 Servers Package</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\bcbofficexp260.bpl">Embarcadero C++Builder Office XP Servers Package</Excluded_Packages>
<Excluded_Packages Name="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\LockBoxFMXDD250.bpl">TurboPack LockBox Delphi FMX designtime package</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\DataExplorerDBXPluginEnt260.bpl">DBExpress Enterprise Data Explorer Integration</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k260.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp260.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="C:\Program Files (x86)\FastReports\LibD26\dclfrxtee26.bpl">FastReport 6.0 Tee Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">

View File

@ -45,6 +45,7 @@ contains
LoggerPro.Proxy in '..\..\LoggerPro.Proxy.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -117,6 +117,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

View File

@ -45,6 +45,7 @@ contains
LoggerPro.Proxy in '..\..\LoggerPro.Proxy.pas',
LoggerPro.UDPSyslogAppender in '..\..\LoggerPro.UDPSyslogAppender.pas',
LoggerPro.Utils in '..\..\LoggerPro.Utils.pas',
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas';
ThreadSafeQueueU in '..\..\ThreadSafeQueueU.pas',
LoggerPro.OutputDebugStringAppender in '..\..\LoggerPro.OutputDebugStringAppender.pas';
end.

View File

@ -117,6 +117,7 @@
<DCCReference Include="..\..\LoggerPro.UDPSyslogAppender.pas"/>
<DCCReference Include="..\..\LoggerPro.Utils.pas"/>
<DCCReference Include="..\..\ThreadSafeQueueU.pas"/>
<DCCReference Include="..\..\LoggerPro.OutputDebugStringAppender.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@ -150,7 +151,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRTxe7.bpl" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\loggerproRTxe8.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>loggerproRT.bpl</RemoteName>
<Overwrite>true</Overwrite>

View File

@ -117,6 +117,7 @@
<DllSuffix>103</DllSuffix>
<Debugger_IncludeSystemVars>true</Debugger_IncludeSystemVars>
<DCC_UNSUPPORTED_CONSTRUCT>false</DCC_UNSUPPORTED_CONSTRUCT>
<DCC_RunTimeTypeInfo>true</DCC_RunTimeTypeInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>

View File

@ -177,6 +177,7 @@ type
end;
TJWTCustomClaims = class(TJWTDictionaryObject)
public
property Items; default;
function AsCustomData: TMVCCustomData;
end;

View File

@ -384,7 +384,7 @@ begin
tkRecord:
begin
if string(AValue.TypeInfo.Name).StartsWith('Nullable') then
if AValue.TypeInfo.NameFld.ToString.StartsWith('Nullable') then
begin
if TryNullableToJSON(AValue, AJsonObject, AName) then
begin