RPC Broker Silent Login Example

From VistApedia
Revision as of 21:23, 3 July 2015 by Kdtop (talk | contribs)
Jump to: navigation, search

RPC Broker Help Home

Silent Login Examples

Silent Login

Example 1: lmAVCodes

Here is an example of how to use Silent Login by passing the Access and Verify codes to the TVistaLogin class.

   
   brkrRPCBroker1.KernelLogIn := False;
   brkrRPCBroker1.LogIn.Mode := lmAVCodes;
   brkrRPCBroker1.LogIn.AccessCode := ********;
   brkrRPCBroker1.LogIn.VerifyCodeCode := ********;
   brkrRPCBroker1.LogIn.PromptDivison := True;
   brkrRPCBroker1.LogIn.OnFailedLogin := myevent;
   try
     brkrRPCBroker1.Connected := True;
   except
     exit
   end;
   


If brkrRPCBroker1.Connected is True, then Silent Login has worked.

NOTE: For a demonstration using the lmAVCodes, please run the lmAVCodes_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory.

Example 2: lmAppHandle

Here is an example of how to use Silent Login by passing an Application Handle to the TVistaLogin class.

The lmAppHandle mode of the Silent Login is used when an application starts up a second application. If the second application tests for arguments on the command line, it is possible for this application to be started and make a connection to the VistA M Server without user interaction.

An example of a procedure for starting a second application with data on the command line to permit a Silent Login using the LoginHandle provided by the first application is shown below. This is followed by a procedure that can be called in the processing related to FormCreate to use this command line data to initialize the TRPCBroker component for Silent Login.

NOTE: It should be noted that the procedures shown here are included within the RpcSLogin unit, and can be used directly from there.

If the value for ConnectedBroker is nil, the application specified in ProgLine will be started and any command line included in ProgLine will be passed to the application.

In the second application, a call to the Broker should be made shortly after starting, since the LoginHandle passed in has a finite lifetime (approximately 20 seconds) during which it is valid for the Silent Login.

   
   procedure StartProgSLogin(const ProgLine: String; ConnectedBroker: TRPCBroker);
   var
     StartupInfo: TStartupInfo;
     ProcessInfo: TProcessInformation;
     AppHandle: String;
     CmndLine: String;
   begin
     FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
     with StartupInfo do begin
       cb := SizeOf(TStartupInfo);
       dwFlags := STARTF_USESHOWWINDOW;
       wShowWindow := SW_SHOWNORMAL;
     end;
     CmndLine := ProgLine;
     if ConnectedBroker <> nil then begin
       AppHandle := GetAppHandle(ConnectedBroker);
       CmndLine := CmndLine + ' s='+ConnectedBroker.Server + ' p='
       + IntToStr(ConnectedBroker.ListenerPort) + ' h='
       + AppHandle + ' d=' + ConnectedBroker.User.Division;
     end;
     CreateProcess(nil, Pchar(CmndLine), nil, nil, False,
                   NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
   end;
   

{btnStart is clicked to start the second application Test2.exe}

   
   procedure TForm1.btnStartClick(Sender: TObject);
   var
     CurDir: string;
   begin
     {Use Test2.exe and expecting it to be in the startup directory for the current application}
     CurDir := ExtractFilePath(ParamStr(0)) + 'Test2.exe';
     {Now start application with Silent Login}
     StartProgSLogin(CurDir, brkrRPCB1);
   end;
   


The following procedure (CheckCmdLine) would be called in the FormCreate code of the application being started to check for command line input, and if relevant to the Broker connection, to set it up.

This code assumes that s=, p=, d=, and h= are used in conjunction with the values for Server, ListenerPort, User.Division, and LoginHandle, respectively.

The command line might look like:

   
   ProgramName.exe s=DHCPSERVER p=9200 d=692 h=~1XM34XYYZZQQ_X
    


The TRPCB and RpcSLogin units would need to be included in the USES clause.

   procedure CheckCmdLine(brkrRPCB: TRPCBroker);
   var
   j: integer;
   
   begin
   // Iterate through possible command line arguments
   for j := 0 to 15 do begin
     if ParamStr(j) <>  then begin
       Form1.Memo1.Lines.Add(IntToStr(j) + ' ' + ParamStr(j));
     end;
     if Pos('p=',ParamStr(j)) > 0 then begin
       brkrRPCB.ListenerPort := StrToInt(Copy(ParamStr(j), (Pos('=',ParamStr(j))+1),length(ParamStr(j))));
     end;
     if Pos('s=',ParamStr(j)) > 0 then begin
       brkrRPCB.Server := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j)));
     end;
     if Pos('h=',ParamStr(j)) > 0 then begin
       brkrRPCB.Login.LoginHandle := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j)));
       if brkrRPCB.Login.LoginHandle <>  then begin
         brkrRPCB.KernelLogIn := False;
         brkrRPCB.Login.Mode := lmAppHandle;
       end;
     end;
     if Pos('d=',ParamStr(j)) > 0 then begin
       brkrRPCB.Login.Division := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j)));
     end;
   end;

For a demonstration using the lmAppHandle, please run the lmAppHandle_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory.