procedure TComponentDebugger.SendToAccessControlClick(Sender: TObject);
var
Request: TWebRequest;
Response: TWebResponse;
Return: THTTPCode;
ResponseJSON: TJSONObject;
const
INTERNAL_PATH = '/tlra/accesscontrol/v1/access/{personId}/{deviceId}/{accessMode}/{accessDirection}';
BASE_URL = 'http://localhost/api';
procedure SetAccessDataInINI;
var
URL : string;
Path: string;
begin
Path := INTERNAL_PATH.Replace('{personId}', edtPersonIdAccess.Text, [rfReplaceAll])
.Replace('{deviceId}', edtDeviceIdAccess.Text, [rfReplaceAll])
.Replace('{accessMode}', cbxAccessMode.ItemIndex.Succ.ToString, [rfReplaceAll])
.Replace('{accessDirection}', cbxAccessDirection.ItemIndex.ToString, [rfReplaceAll]);
URL := BASE_URL.Concat([Path]);
TIniReader.Instance.OpenFile(FBasePath + BIOMETRIES_INI_FILE)
.Section['Extra Headers']
.WriteString('Url', URL)
.Root
.Section['CGI']
.WriteString('Logical Path', Path)
.WriteString('Physical Path', Path)
.UpdateFile;
end;
procedure Prepare;
begin
SetAccessDataInINI;
sedtResponse.Lines.Clear;
Request := TWinCGIRequest.Create(FBasePath + BIOMETRIES_INI_FILE, FBasePath + CONTENT_FILE, FBasePath + OUTPUT_FILE);
Response := TCGIResponse.Create(Request);
end;
begin
Prepare;
Return := TCATRACAFactory.Instance.GetObject(ACCESS_CONTROL_CLASS_KEY).SetLogFile(FLogFile)
.SetErrorLogFile(FErrorLogFile)
.TreatRequest(FConnection
, Request
, Response);
ResponseJSON := Response.Content.ToJSON;
sedtResponse.Text := ResponseJSON.PrettyFormat(2);
AccessID := ResponseJSON.TryReadNode('id', EmptyStr);
ResponseJSON.Free;
Request.Free;
Response.Free;
case AccessID.IsEmpty of
True : btnEndAccess.Enabled := False;
False:
begin
btnEndAccess.Enabled := True;
Seconds := 20;
btnEndAccess.Caption := 'Finish [%d]'.Format([Seconds]);
tmrFinishAccess.Enabled := True;
end;
end;
case Return.IsOkResult of
True : Application.MessageBox(PWideChar(RESPONSE_MESSAGE.Format([Return.Code, Return.Message])), 'Informação', MB_OK or MB_ICONINFORMATION);
False: Application.MessageBox(PWideChar(RESPONSE_MESSAGE.Format([Return.Code, Return.Message])), 'Erro', MB_OK or MB_ICONERROR);
end;
end; |