ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/examples/services/BackupDlgUnit.pas
(Generate patch)

Comparing ibx/trunk/examples/services/BackupDlgUnit.pas (file contents):
Revision 143 by tony, Fri Feb 23 12:11:21 2018 UTC vs.
Revision 209 by tony, Wed Mar 14 12:48:51 2018 UTC

# Line 31 | Line 31 | unit BackupDlgUnit;
31   interface
32  
33   uses
34 <  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
35 <  Buttons, ExtCtrls, IBServices;
34 >  Classes, SysUtils, FileUtil, IBXServices, Forms, Controls, Graphics, Dialogs, ExtCtrls,
35 >  StdCtrls, Buttons;
36  
37   type
38  
# Line 42 | Line 42 | type
42      Bevel1: TBevel;
43      Button1: TButton;
44      Button2: TButton;
45 <    Edit1: TEdit;
46 <    Edit2: TEdit;
47 <    Edit3: TEdit;
48 <    IBBackupService1: TIBBackupService;
45 >    CSBackupService1: TIBXClientSideBackupService;
46 >    SSBackupService1: TIBXServerSideBackupService;
47 >    ServerName: TEdit;
48 >    DBName: TEdit;
49 >    BackupFilename: TEdit;
50      Label1: TLabel;
51      Label2: TLabel;
52      Label3: TLabel;
53 <    RadioButton1: TRadioButton;
54 <    RadioButton2: TRadioButton;
53 >    ServerSideBtn: TRadioButton;
54 >    ClientSideBtn: TRadioButton;
55      SaveDialog1: TSaveDialog;
56      SpeedButton1: TSpeedButton;
57      procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
58      procedure FormShow(Sender: TObject);
59      procedure SpeedButton1Click(Sender: TObject);
60 +    procedure SSBackupService1GetNextLine(Sender: TObject; var Line: string);
61    private
62      { private declarations }
63 +    FOutputLog: TStrings;
64 +    procedure RunBackup;
65    public
66      { public declarations }
67 <     procedure RunBackup;
67 >    function ShowModal(var aDBName: string; OutputLog: TStrings): TModalResult;
68   end;
69  
70   var
# Line 70 | Line 74 | implementation
74  
75   {$R *.lfm}
76  
73 uses MainFormUnit;
74
77   { TBackupDlg }
78  
79   procedure TBackupDlg.SpeedButton1Click(Sender: TObject);
80   begin
81    if SaveDialog1.Execute then
82 <    Edit3.Text := SaveDialog1.Filename;
82 >    BackupFilename.Text := SaveDialog1.Filename;
83   end;
84  
85 < procedure TBackupDlg.RunBackup;
86 < var bakfile: TFileStream;
85 <    BackupCount: integer;
85 > procedure TBackupDlg.SSBackupService1GetNextLine(Sender: TObject;
86 >  var Line: string);
87   begin
88 <  bakfile := nil;
89 <  MainForm.Memo1.Lines.Add('Starting Backup');
89 <  if IBBackupService1.BackupFileLocation = flClientSide then
90 <    bakfile := TFileStream.Create(IBBackupService1.BackupFile[0],fmCreate);
91 <  try
92 <    IBBackupService1.ServiceStart;
93 <    while not IBBackupService1.Eof do
94 <    begin
95 <      case IBBackupService1.BackupFileLocation of
96 <      flServerSide:
97 <        MainForm.Memo1.Lines.Add(IBBackupService1.GetNextLine);
98 <      flClientSide:
99 <        IBBackupService1.WriteNextChunk(bakfile);
100 <      end;
101 <      Application.ProcessMessages;
102 <    end;
103 <    if bakfile <> nil then
104 <      BackupCount := bakfile.Size;
105 <  finally
106 <    if bakfile <> nil then
107 <      bakfile.Free;
108 <  end;
88 >  Application.ProcessMessages;
89 > end;
90  
91 <  while IBBackupService1.IsServiceRunning do; {flush}
91 > function TBackupDlg.ShowModal(var aDBName: string; OutputLog: TStrings): TModalResult;
92 > begin
93 >  DBName.Text := aDBName;
94 >  FOutputLog := OutputLog;
95 >  Result := inherited ShowModal;
96 >  if Result = mrOK then
97 >  begin
98 >    RunBackup;
99 >    aDBName := DBName.Text;
100 >  end;
101 > end;
102  
103 <  {Report completion}
104 <  case IBBackupService1.BackupFileLocation of
105 <  flServerSide:
106 <    begin
107 <      MainForm.Memo1.Lines.Add('Backup Completed');
108 <      MessageDlg('Backup Completed',mtInformation,[mbOK],0);
109 <    end;
110 <  flClientSide:
111 <    begin
112 <      MainForm.Memo1.Lines.Add(Format('Backup Completed - File Size = %d bytes',[BackupCount]));
113 <      MessageDlg(Format('Backup Completed - File Size = %d bytes',[BackupCount]),mtInformation,[mbOK],0);
114 <    end;
103 > procedure TBackupDlg.RunBackup;
104 > var BackupCount: integer;
105 > begin
106 >  FOutputLog.Add('Starting Backup');
107 >  if ClientSideBtn.Checked then
108 >  begin
109 >    CSBackupService1.BackupToFile(BackupFilename.Text,BackupCount);
110 >    FOutputLog.Add(Format('Backup Completed - File Size = %d bytes',[BackupCount]));
111 >    MessageDlg(Format('Backup Completed - File Size = %d bytes',[BackupCount]),mtInformation,[mbOK],0);
112 >  end
113 >  else
114 >  begin
115 >    SSBackupService1.Execute(FOutputLog);
116 >    FOutputLog.Add('Backup Completed');
117 >    MessageDlg('Backup Completed',mtInformation,[mbOK],0);
118    end;
119   end;
120  
121   procedure TBackupDlg.FormShow(Sender: TObject);
122   begin
123 <  Edit1.Text := IBBackupService1.ServerName;
124 <  if IBBackupService1.BackupFileLocation = flServerSide then
131 <    RadioButton1.Checked := true
132 <  else
133 <    RadioButton2.Checked := true;
134 <  Edit2.Text := IBBackupService1.DatabaseName;
135 <  IBBackupService1.BackupFile.Clear;
123 >  ServerName.Text := CSBackupService1.ServicesConnection.ServerName;
124 >  SSBackupService1.BackupFiles.Clear;
125   end;
126  
127   procedure TBackupDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
128   begin
129    if ModalResult <> mrOK then Exit;
130 <  if Edit2.Text = '' then
130 >  if DBName.Text = '' then
131      raise Exception.Create('A Database Name must be given');
132 <  if Edit3.Text = '' then
132 >  if BackupFilename.Text = '' then
133      raise Exception.Create('A Backup File Name must be given');
134 <  IBBackupService1.DatabaseName := Edit2.Text;
135 <  IBBackupService1.BackupFile.Add(Edit3.Text);
136 <  if RadioButton1.Checked then
137 <     IBBackupService1.BackupFileLocation := flServerSide
149 <  else
150 <    IBBackupService1.BackupFileLocation := flClientSide;
134 >  CSBackupService1.DatabaseName := DBName.Text;
135 >  SSBackupService1.DatabaseName := DBName.Text;
136 >  if ServerSideBtn.Checked then
137 >    SSBackupService1.BackupFiles.Add(BackupFilename.Text);
138   end;
139  
140   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines