1. Connettersi a un server WebSocket
Usa TsgcWebSocketClient per connetterti a qualsiasi server conforme a RFC 6455, inviare un messaggio e reagire ai frame in arrivo.
uses
sgcWebSocket;
var
oClient: TsgcWebSocketClient;
begin
oClient := TsgcWebSocketClient.Create(nil);
try
oClient.URL := 'wss://echo.websocket.org';
oClient.WatchDog.Enabled := True; // auto-reconnect
oClient.OnMessage := procedure(Connection: TsgcWSConnection;
const Text: string)
begin
Writeln('Server says: ', Text);
end;
oClient.Active := True;
oClient.WriteData('Hello from Delphi!');
Readln;
finally
oClient.Free;
end;
end;
2. Generare un client REST Delphi da OpenAPI
Punta TsgcOpenAPI_Generator a qualsiasi specifica OpenAPI 3 (file locale o URL HTTP) ed emetti un client Delphi tipizzato — classi, metodi, autenticazione e DTO di request/response — in una sola chiamata.
uses
sgcOpenAPI_Parser, sgcOpenAPI_Generator;
var
oGen: TsgcOpenAPI_Generator;
begin
oGen := TsgcOpenAPI_Generator.Create(nil);
try
oGen.Source := 'https://petstore3.swagger.io/api/v3/openapi.json';
oGen.OutputFolder := 'C:\Projects\PetStoreClient\src';
oGen.Language := lngDelphi;
oGen.Namespace := 'PetStore.Client';
oGen.Generate;
Writeln('Generated ', oGen.Files.Count, ' Delphi units');
finally
oGen.Free;
end;
end;
3. Firmare un PDF
Usa TsgcSignPDF per produrre una firma conforme a PAdES con un certificato da uno qualsiasi dei key provider supportati (PKCS#11, Azure Key Vault, AWS KMS, Windows Cert Store, PFX locale).
uses
sgcSign_PAdES, sgcSign_KeyProvider_Windows;
var
oSigner: TsgcSignPDF;
oKey : TsgcSign_KeyProvider_Windows;
begin
oKey := TsgcSign_KeyProvider_Windows.Create(nil);
oKey.CertificateThumbprint := 'a1b2c3d4...';
oSigner := TsgcSignPDF.Create(nil);
try
oSigner.KeyProvider := oKey;
oSigner.Profile := 'PAdES-B-LT';
oSigner.SignFile(
'C:\docs\contract.pdf',
'C:\docs\contract.signed.pdf');
Writeln('Signed: ', oSigner.LastSignatureId);
finally
oSigner.Free;
oKey.Free;
end;
end;