1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
procedure TdmServiceServer.IdTCPServerExecute(AContext: TIdContext);
var
CommandData : string;
Command : TXMLCmd;
Response : TXMLCmd;
CommandIsGood : Boolean; // <-- Ajout de cette variable
begin
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext), 8);
try
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' Before ReadLn', 8);
CommandData := AContext.Connection.Socket.ReadLn;
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' After ReadLn', 8);
except
on E : Exception do
begin
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' ReadLn failed ' + e.ClassName + ':' + e.Message, 8);
if (E is EIdSilentException) then
begin
CommandData := EmptyStr;
ABLogFileManager.LogLowDebugInfos2('EIdSilentException is run'); // <-- Je log une erreur silencieuse
end
else
begin
ABLogFileManager.LogLowDebugInfos2(E.ClassName + ' is run (Other Exception)'); // <-- Je log les autres erreurs non traitées
raise;
end;
end;
end;
if (CommandData <> EmptyStr) then
begin
CommandIsGood := True;
// Chaque demande est exécutée dans un thread séparé, il faut initialiser
// COM pour pouvoir utiliser XML
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' CoInitializeEx', 8);
CoInitializeEx(nil, COINIT_MULTITHREADED);
try
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' Uncrypt', 8);
Command := TXMLCmd.Create;
Command.XMLText := Uncrypt(CommandData);
Response := TXMLCmd.Create;
try
Response.CMDId := Command.CMDId;
Response.CMDName := Command.CMDName;
try
case Command.CMDId of
CMD_CONNECT_ID :
begin
ExecConnect(Command, Response);
end;
CMD_COMP_SUB_CONNECT_ID :
begin
ExecCompSubConnect(Command, Response);
end;
CMD_DISCONNECT_ID :
begin
ExecDisconnect(Command, Response);
end;
CMD_GET_SQL_CONNECTION_DATA_ID :
begin
ExecGetSQLConnectionData(Command, Response);
end;
.
.
.
else
// Commande invalide
Response.CMDId := CMD_ERROR_ID;
Response.CMDName := CMD_ERROR_NAME;
Response.ParamAsString['Message'] := Format(rsInvalidCommand, [Command.CMDName]);
CommandIsGood := False;
ABLogFileManager.LogLowDebugInfos2(rsInvalidCommand); // <-- Je log une commande invalide (Ne devrait jamais arriver)
end;
AContext.Connection.Socket.WriteLn(Crypt(Response.XMLText));
finally
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' Done', 8);
Response.Free;
end;
finally
Command.Free;
end;
finally
CoUnInitialize;
if Verbose then
ABLogFileManager.LogLowDebugInfos2('IdTCPServerExecute : $' + IntToHex(NativeInt(AContext) + ' CoUnInitialize', 8);
end;
if CommandIsGood then
ABLogFileManager.LogLowDebugInfos2('CommandData is treated !'); // <-- Je log que mon process est correctement traité
end
else
begin
ABLogFileManager.LogLowDebugInfos2('Empty CommandData !'); // <-- Je log une commande vide
Sleep(10); // <-- Je fais le Sleep 10 pour faire respirer.
end; |
Partager