--- ibx/trunk/examples/DBAdmin/dlg/RestoreDlgUnit.pas 2018/04/16 09:24:55 208 +++ ibx/trunk/examples/DBAdmin/dlg/RestoreDlgUnit.pas 2018/03/14 12:48:51 209 @@ -23,7 +23,7 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, - StdCtrls, Buttons, ComCtrls, IBServices; + StdCtrls, Buttons, ComCtrls, IBXServices; type @@ -33,6 +33,8 @@ type Button1: TButton; Button2: TButton; DeActivateIndexes: TCheckBox; + IBXClientSideRestoreService1: TIBXClientSideRestoreService; + IBXServerSideRestoreService1: TIBXServerSideRestoreService; PageBuffers: TEdit; Label6: TLabel; NoShadow: TCheckBox; @@ -40,11 +42,10 @@ type OneRelationAtATime: TCheckBox; RestoreMetaDataOnly: TCheckBox; UseAllSpace: TCheckBox; - Edit1: TEdit; + ServerName: TEdit; DBName: TEdit; SourceArchive: TEdit; PageSize: TEdit; - IBRestoreService1: TIBRestoreService; Label1: TLabel; Label2: TLabel; Label3: TLabel; @@ -53,18 +54,21 @@ type Report: TMemo; OpenDialog1: TOpenDialog; PageControl1: TPageControl; - RadioButton1: TRadioButton; - RadioButton2: TRadioButton; + ServerSideBtn: TRadioButton; + ClientSideBtn: TRadioButton; SpeedButton1: TSpeedButton; SelectTab: TTabSheet; ReportTab: TTabSheet; procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormShow(Sender: TObject); + procedure IBXClientSideRestoreService1GetNextLine(Sender: TObject; + var Line: string); procedure ReportTabShow(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); private { private declarations } - procedure DoRestore(Data: PtrInt); + procedure DoClientRestore(Data: PtrInt); + procedure DoServerRestore(Data: PtrInt); public { public declarations } function ShowModal(DefaultPageSize, DefaultNumBuffers: integer): TModalResult; @@ -85,43 +89,62 @@ begin SourceArchive.Text := OpenDialog1.Filename; end; -procedure TRestoreDlg.DoRestore(Data: PtrInt); -var bakfile: TFileStream; - line: string; -begin - bakfile := nil; - if IBRestoreService1.BackupFileLocation = flClientSide then - bakfile := TFileStream.Create(IBRestoreService1.BackupFile[0],fmOpenRead); - Report.Lines.Add('Restore Started'); - try - IBRestoreService1.ServiceStart; - while not IBRestoreService1.Eof do - begin - case IBRestoreService1.BackupFileLocation of - flServerSide: - Report.Lines.Add(Trim(IBRestoreService1.GetNextLine)); - flClientSide: - begin - IBRestoreService1.SendNextChunk(bakfile,line); - if line <> '' then - Report.Lines.Add(line); - end; - end; - Application.ProcessMessages - end; - finally - if bakfile <> nil then - bakfile.Free; +procedure TRestoreDlg.DoClientRestore(Data: PtrInt); +begin + with IBXClientSideRestoreService1 do + begin + PageSize := StrToInt(self.PageSize.Text); + PageBuffers := StrToInt(self.PageBuffers.Text); + Options := [Replace]; + if DeactivateIndexes.Checked then + Options := Options + [IBXServices.DeactivateIndexes]; + if NoShadow.Checked then + Options := Options + [IBXServices.NoShadow]; + if NoValidityCheck.Checked then + Options := Options + [IBXServices.NoValidityCheck]; + if OneRelationAtATime.Checked then + Options := Options + [IBXServices.OneRelationAtATime]; + if RestoreMetaDataOnly.Checked then + Options := Options + [IBXServices.RestoreMetaDataOnly]; + if UseAllSpace.Checked then + Options := Options + [IBXServices.UseAllSpace]; + Report.Lines.Add('Restore Started'); + RestoreFromFile(SourceArchive.Text,Report.Lines); + Report.Lines.Add('Restore Completed'); + MessageDlg('Restore Completed',mtInformation,[mbOK],0); end; - while IBRestoreService1.IsServiceRunning do; {flush} - IBRestoreService1.ACtive := false; +end; - Report.Lines.Add('Restore Completed'); - MessageDlg('Restore Completed',mtInformation,[mbOK],0); +procedure TRestoreDlg.DoServerRestore(Data: PtrInt); +begin + with IBXServerSideRestoreService1 do + begin + PageSize := StrToInt(self.PageSize.Text); + PageBuffers := StrToInt(self.PageBuffers.Text); + Options := [Replace]; + if DeactivateIndexes.Checked then + Options := Options + [IBXServices.DeactivateIndexes]; + if NoShadow.Checked then + Options := Options + [IBXServices.NoShadow]; + if NoValidityCheck.Checked then + Options := Options + [IBXServices.NoValidityCheck]; + if OneRelationAtATime.Checked then + Options := Options + [IBXServices.OneRelationAtATime]; + if RestoreMetaDataOnly.Checked then + Options := Options + [IBXServices.RestoreMetaDataOnly]; + if UseAllSpace.Checked then + Options := Options + [IBXServices.UseAllSpace]; + BackupFiles.Clear; + BackupFiles.Add(SourceArchive.Text); + Report.Lines.Add('Restore Started'); + Execute(Report.Lines); + Report.Lines.Add('Restore Completed'); + MessageDlg('Restore Completed',mtInformation,[mbOK],0); + end; end; -function TRestoreDlg.ShowModal(DefaultPageSize, DefaultNumBuffers: integer - ): TModalResult; +function TRestoreDlg.ShowModal(DefaultPageSize, + DefaultNumBuffers: integer): TModalResult; begin PageSize.Text := IntToStr(DefaultPageSize); PageBuffers.Text := IntToStr(DefaultNumBuffers); @@ -131,16 +154,17 @@ end; procedure TRestoreDlg.FormShow(Sender: TObject); begin PageControl1.ActivePage := SelectTab; - Edit1.Text := IBRestoreService1.ServerName; - if IBRestoreService1.BackupFileLocation = flServerSide then - RadioButton1.Checked := true - else - RadioButton2.Checked := true; - DBName.Text := IBRestoreService1.DatabaseName[0]; - IBRestoreService1.BackupFile.Clear; + ServerName.Text := IBXClientSideRestoreService1.ServicesConnection.ServerName; + DBName.Text := IBXClientSideRestoreService1.DatabaseFiles[0]; SourceArchive.SetFocus; end; +procedure TRestoreDlg.IBXClientSideRestoreService1GetNextLine(Sender: TObject; + var Line: string); +begin + Application.ProcessMessages; +end; + procedure TRestoreDlg.ReportTabShow(Sender: TObject); begin Report.Lines.Clear; @@ -155,32 +179,11 @@ begin CloseAction := caNone; if SourceArchive.Text = '' then raise Exception.Create('A Backup File Name must be given'); - with IBRestoreService1 do - begin - if RadioButton1.Checked then - BackupFileLocation := flServerSide + if ServerSideBtn.Checked then + Application.QueueAsyncCall(@DoServerRestore,0) else - BackupFileLocation := flClientSide; - BackupFile.Add(SourceArchive.Text); - PageSize := StrToInt(self.PageSize.Text); - PageBuffers := StrToInt(self.PageBuffers.Text); - Options := [Replace]; - if DeactivateIndexes.Checked then - Options := Options + [IBServices.DeactivateIndexes]; - if NoShadow.Checked then - Options := Options + [IBServices.NoShadow]; - if NoValidityCheck.Checked then - Options := Options + [IBServices.NoValidityCheck]; - if OneRelationAtATime.Checked then - Options := Options + [IBServices.OneRelationAtATime]; - if RestoreMetaDataOnly.Checked then - Options := Options + [IBServices.RestoreMetaDataOnly]; - if UseAllSpace.Checked then - Options := Options + [IBServices.UseAllSpace]; - end; - + Application.QueueAsyncCall(@DoClientRestore,0); PageControl1.ActivePage := ReportTab; - Application.QueueAsyncCall(@DoRestore,0); end; end;