|
ASTA has had an autoupgrade process since ASTA 1.X and which has
allowed ASTA users to register a current version of ASTA client
versions on ASTA servers. When a remote ASTA application logs into the
server a version check is performed and if there is a more current
version available, it is streamed back to the client, and the new
application is launched. The idea is that once you deploy, remote
clients will be guaranteed to have the most current version of the
ASTA client application.
This is all easy to do and takes no code, but the result is, for
servers that support many users, that the ASTA database server gets
occupied in streaming down 1+MB client EXE's when new releases are
made available. There is a tutorial on the standard ASTA autoupgrade
tecnnique that includes a word document detail the process.
A better solution is to make upgrades available from an http server
and the ASTA server merely sends down the location of the new version
to the remote ASTA client who then download that version from a
WebServer rather than the ASTA server, freeing up bandwidth of the
ASTA server to server database clients. This demo is available with
full source code and includes an ASTA Server, Client and even a
compiled client exe on the ASTA web site that can be used for testing.
Server Side
The example ASTA Server codes the
AstaServerSocket.OnAstaClientUpgradeDecide event. In the normal ASTA
upgrade process, the location of the client EXE on the server is
stored in the registry. Instead of doing that, this technique sets the
Var AllowUpgrade:Boolean to false to bypass the normal ASTA update
process and then sends a CodedParamList back to the remote client that
contains the Host where the new Version resides and the file location.
procedure TForm1.ServersocketAstaClientUpgradeDecide(Sender: TObject;
ClientSocket: TCustomWinSocket; AppName, OldVer, UserName: string;
var AllowUpgrade: Boolean);
var
p: TAstaParamList;
begin
AllowUpgrade := False;
memo1.lines.add(UserName + ' with ' + AppName + ' version ' + OldVer);
// right here we can send a message to the client with the file location
// for them to download it from an http site.
// the asta server is now out of the loop!
if OldVer > '1.0' then exit; //no upgrade available
p := TAstaParamList.Create;
try
p.FastAdd('Host', 'www.astatech.com');
p.FastAdd('File', 'files/examples/httpupgrade/AstaClientUpgrader.exe');
ServerSocket.SendCodedParamList(ClientSocket, 1000, p);
finally
p.free;
end;
memo1.lines.add('Upgrade info sent out');
end;
Client Side
On the client side, the client needs to login to the server of
course as the login process is what triggers the events on the server
to send back upgrade information. Make sure the
AstaClientSocket.AutoLoginDlg is set to anything other than
ltNoChallenge. The client must code the
AstaClientSocket.OnCodedParamList to respond to an upgrade message from
the server.
Procedure TForm1.AstaClientSocket1CodedParamList(Sender: TObject;
MsgID: Integer; Params: TAstaParamList);
var
i: Integer;
begin
for i := 0 to Params.count - 1 do
Memo1.lines.add(Params[i].Name + ':' + Params[i].AsString);
case msgid of
1000: GetUpdate(Params.ParamByName('Host').AsString,
Params.ParamByName('File').AsString);
end;
end;
This triggers the call to GetUpdate which calls UpgradeHttpDownload
which is included with full source in the tutorial zip file. It uses
the plain Borland TClienetSocket with a blocking call to grab the file
from a remote http server. After the file is download, a batch file
must be executed to stop the current application, rename the streamed
file to the current application's EXE name and relaunch it. The full
source for BatchFileForUpdate is included in the tutorial. The ultimate
solution is to combine this technique with some Binary Patch Technology
like the ASTA BinaryPatcher. This allows for Delta Patches to be
created and applied with small console EXE so that only the changes are
sent down to client applications. Zero Administration is an important
design goal for ASTA clients and by using these techniques, remote ASTA
clients, can always be assured to have the absolute most current
version fo their applications available. These same concepts are
available on all ASTA clients including Palm
and Wince Clients.
procedure TForm1.GetUpdate(Host, FileName: string);
var
List: TStringList;
begin
memo1.lines.add('download starting');
FAbortit:=False;
if UpgradeHttpDownload(Host, FileName, TempFileName, 80, ShowProgress) > 0 then
begin
memo1.lines.add('download complete');
List := BatchFileForUpdate(TempFileName);
memo1.lines.add('this is the batch file that will now run');
memo1.lines.add('----------------------------------------');
memo1.lines.addstrings(List);
list.free;
//Uncomment the 2 lines below to execute it
//ShellExecute(0, nil, PChar('Restart.bat'), nil, nil, SW_HIDE);
//Application.Terminate;
end
else
memo1.lines.add('download failed');
end;
|