Reputation: 47
Embarcadero C++ Builder 11.2 Architect.
I trying to access the Multi-Tenant information in my RAD Server programmatically. Access is not provided via EMSInternalAPI to get at that information, so I tried the following:
The .dfm file, localhost is the remote server running IIS and Rad Server:
object TenantModuleResource: TTenantModuleResource
Height = 258
Width = 441
object qryTenants: TFDQuery
Connection = TenantConection
Left = 72
Top = 40
end
object FDStanStorageJSONLink: TFDStanStorageJSONLink
Left = 272
Top = 128
end
object FDPhysIBDriverLink: TFDPhysIBDriverLink
Left = 272
Top = 48
end
object TenantConection: TFDConnection
Params.Strings = (
'Server=localhost'
'User_Name=sysdba'
'Password=masterkey'
'Database=C:\Data\emsserver.ib'
'InstanceName=gds_db'
'Port=3050'
'DriverID=IB')
Left = 72
Top = 128
end
end
The code:
void TTenantModuleResource::Get(TEndpointContext* AContext, TEndpointRequest* ARequest, TEndpointResponse* AResponse)
{
std::unique_ptr<TMemoryStream> oStr(new TMemoryStream());
qryTenants->Close();
qryTenants->SQL->Text = "SELECT tenantid, tenantname FROM tenants";
qryTenants->Open();
qryTenants->SaveToStream(oStr.get(), TFDStorageFormat::sfJSON);
AResponse->Body->SetStream(oStr.release(), "application/json", true);
}
static void Register()
{
std::unique_ptr<TEMSResourceAttributes> attributes(new TEMSResourceAttributes());
attributes->ResourceName = "tenants";
RegisterResource(__typeinfo(TTenantModuleResource), attributes.release());
}
and ended getting a log error of unknown "...Win32 error 10060" which is a timeout from what I can tell. I've seen where the Interbase docs suggest that there is no client license when that error is thrown.
I have the RAD Server Site license, but not the client license, however I would like to have the ability to work with the tenant records without using the Multi-Tenant Console app.
My questions is does anyone know of a way to programmatically get to the Tenant data in the emserver.ib database?
Upvotes: 0
Views: 91
Reputation: 47
There are no Multi-Tenancy EMS samples for C++ Builder, and worse if you look through the docs you will find sparse information about it. So this is useful information.
You can use the TEMSClientAPI component to get the Tenant information. The TEMSClientApi has a property called ConnectionInfo. With this property you gain access to parameters such as MasterSecret, TenantSecret, TenantId, and more.
Below is the actual definition of the struct from REST.Backend.EMSApi.hpp, which can be found in your Embarcadero folder at "C:\Program Files (x86)\Embarcadero\Studio\22.0\include\windows\rtl"
Here's a small snippet that should get the current Tenant ID:
TEMSClientAPI* api = new TEMSClientAPI();
TEMSClientAPI::TConnectionInfo conf = api->ConnectionInfo;
String tenant_name = conf.TenantId;
From the header file.
struct DECLSPEC_DRECORD TConnectionInfo
{
public:
System::UnicodeString ApiVersion;
System::UnicodeString ApplicationId;
System::UnicodeString AppSecret;
System::UnicodeString MasterSecret;
System::UnicodeString UserName;
System::UnicodeString Password;
System::UnicodeString ProxyPassword;
int ProxyPort;
System::UnicodeString ProxyServer;
System::UnicodeString ProxyUsername;
System::UnicodeString BaseURL;
System::UnicodeString LoginResource;
System::Net::Urlclient::TValidateCertificateEvent OnValidateCertificate;
System::UnicodeString TenantId;
System::UnicodeString TenantSecret;
int ConnectTimeout;
int ReadTimeout;
static void __fastcall _op_Initialize(/* out */ TEMSClientAPI::TConnectionInfo &Dest);
__fastcall TConnectionInfo(const System::UnicodeString AApiVersion, const System::UnicodeString AApplicationID);
TConnectionInfo() {}
};
Upvotes: 0