procedure TSingleSyncThread.Execute;
Procedure DownloadFolder(calledfrom, ARemoteFolder, ALocalFolder:
string);
var
SubFolders: TStringList;
I: Integer;
begin
ALocalFolder := IncludeTrailingPathDelimiter(ALocalFolder);
ForceDirectories(ALocalFolder);
SubFolders := TStringList.Create;
try
DM1.FTP1.ChangeDir(ARemoteFolder);
DM1.FTP1.List;
TSyncThread.Synchronize(
nil,
procedure
begin
CSITEDETFORM.xpbar.Max := DM1.FTP1.DirectoryListing.Count;
CSITEDETFORM.xpbar.Visible := True;
end);
for I := 0
to DM1.FTP1.DirectoryListing.Count-1
do
begin
if DM1.FTP1.DirectoryListing[I].ItemType = ditFile
then
begin
if (ExtractFileExt(DM1.FTP1.DirectoryListing[I].FileName) = '
.msg')
then Continue;
TSyncThread.Queue(
nil,
procedure
begin
CSITEDETFORM.xpbar.Value := i+1;
end);
DM1.FTP1.Get(DM1.FTP1.DirectoryListing[I].FileName, ALocalFolder + DM1.FTP1.DirectoryListing[I].FileName, True, false);
end
else if DM1.FTP1.DirectoryListing[I].ItemType = ditDirectory
then
begin
if (DM1.FTP1.DirectoryListing[I].FileName <> '
.')
and (DM1.FTP1.DirectoryListing[I].FileName <> '
..')
then
SubFolders.Add(DM1.FTP1.DirectoryListing[I].FileName);
CSITEDETFORM.xpbar.Value := i+1;
end;
end;
for I := 0
to SubFolders.Count-1
do
begin
DownloadFolder(calledfrom, ARemoteFolder + '
/' + SubFolders[I], ALocalFolder + SubFolders[I]);
end;
finally
SubFolders.Free;
TSyncThread.Queue(
nil,
procedure
begin
CSITEDETFORM.xpbar.Visible := false;
end);
end;
end;
var ... einige Variablen
begin
filestosync := TStringlist.Create;
try
CSITEDETFORM.SYNCBOX.Visible := True;
CSITEDETFORM.BTNSYNC.Enabled := false;
if not DM1.UniConnection1.Connected
then DM1.UniConnection1.Connect;
DM1.CSITESYNCQUERY.Close;
DM1.CSITESYNCQUERY.SQL.Text := '
SELECT * from documents WHERE DOC_CUSTFURN = ''
5''
AND DOC_REFID = ''
' + csitetoload + '
''
;';
DM1.CSITESYNCQUERY.Execute;
TSingleSyncThread.Synchronize(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := '
Dokumente';
end);
if DM1.CSITESYNCQUERY.RecordCount > 0
then //if there is data to sync
begin
sqlstring := '
INSERT INTO documents (DOC_REFID, DOC_CUSTFURN, DOC_FILENAME, DOC_PATH, DOC_REMARK, DOC_ADDEDDATE, DOC_PARENT, DOC_LEVEL, DOC_TYPE, DOC_NODEID, DOC_NEWSCAN) VALUES ';
while not DM1.CSITESYNCQUERY.Eof
do
begin
docfilename := StringReplace(DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
DOC_PATH').AsString), '
\','
/', [rfReplaceAll, rfIgnoreCase]);
docfilename := StringReplace(docfilename, '
//192.168.100.5/csitestore/docs/', '
', [rfReplaceAll, rfIgnoreCase]);
sqlstring := sqlstring + '
(''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_REFID').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_CUSTFURN').AsString + '
''
, ''
' + DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
DOC_FILENAME').AsString) + '
''
,'+
'
''
' + docfilename +
'
''
, ''
' + DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
DOC_REMARK').AsString) + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_ADDEDDATE').AsString + '
''
,' +
'
''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_PARENT').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_LEVEL').AsString + '
''
, '+
'
''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_TYPE').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_NODEID').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
DOC_NEWSCAN').AsString + '
''
),';
DM1.CSITESYNCQUERY.Next;
end;
sqlstring := Copy(sqlstring,1,(Length(sqlstring)-1));
//get rid of the last ,
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := '
DELETE FROM documents WHERE DOC_REFID = ''
' + csitetoload + '
''
;';
DM1.SQLITEQUERY.Execute;
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := sqlstring;
DM1.SQLITEQUERY.Execute;
ftpdirectory := '
csitestore/docs';
try
if not DM1.FTP1.Connected
then DM1.FTP1.Connect;
try
try
DM1.FTP1.ChangeDir(ftpdirectory + '
/' + csitetoload);
TSingleSyncThread.Synchronize(
nil,
procedure
begin
if DirectoryExists(TPath.GetTempPath + '
/' + csitetoload)
then TDirectory.Delete(TPath.GetTempPath + '
/' + csitetoload, True);
end);
DownloadFolder('
docs', '
/home/' + ftpdirectory + '
/' + csitetoload , TPath.GetTempPath + '
/' + csitetoload);
TSingleSyncThread.Synchronize(
nil,
procedure
begin
TDirectory.Copy(TPath.GetTempPath + '
/' + csitetoload, csitedocpath + '
/' + csitetoload);
end);
except
On E:
Exception do
begin
TThread.Synchronize(
nil,
procedure
begin
end);
end;
end;
finally
DM1.FTP1.Disconnect;
filestosync.clear;
end;
except
On E:
Exception do
begin
TThread.Synchronize(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := e.
Message;
end);
end;
end;
end
else
begin //if there is nothing to sync
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := '
DELETE FROM documents WHERE DOC_REFID = ''
' + csitetoload + '
''
;';
DM1.SQLITEQUERY.Execute;
end;
DM1.CSITESYNCQUERY.Close;
DM1.CSITESYNCQUERY.SQL.Text := '
SELECT * from consite_plans WHERE CSITEPLAN_CSITEID = ''
' + csitetoload + '
''
;';
DM1.CSITESYNCQUERY.Execute;
if DM1.CSITESYNCQUERY.RecordCount > 0
then //if there is data to sync
begin
TSingleSyncThread.Synchronize(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := '
Pläne';
end);
sqlstring := '
INSERT INTO consite_plans (CSITEPLAN_CSITEID, CSITEPLAN_PLAN, CSITEPLAN_PLAN_ORIGNAME, CSITEPLAN_DESCRIPTION, CSITEPLAN_DATE, CSITEPLAN_PARENT, '+
'
CSITEPLAN_LEVEL, CSITEPLAN_TYPE, CSITEPLAN_NODEID) VALUES ';
while not DM1.CSITESYNCQUERY.Eof
do
begin
docfilename := StringReplace(DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_PLAN').AsString), '
\','
/', [rfReplaceAll, rfIgnoreCase]);
docfilename := StringReplace(docfilename, '
//192.168.100.5/csitestore/plans/', '
', [rfReplaceAll, rfIgnoreCase]);
sqlstring := sqlstring + '
(''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_CSITEID').AsString + '
''
, ''
' + docfilename + '
''
, ''
' + DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_PLAN_ORIGNAME').AsString) + '
''
,'+
'
''
' + DM1.esc(DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_DESCRIPTION').AsString) + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_DATE').AsString + '
''
,' +
'
''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_PARENT').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_LEVEL').AsString + '
''
, '+
'
''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_TYPE').AsString + '
''
, ''
' + DM1.CSITESYNCQUERY.FieldbyName('
CSITEPLAN_NODEID').AsString + '
''
),';
DM1.CSITESYNCQUERY.Next;
end;
sqlstring := Copy(sqlstring,1,(Length(sqlstring)-1));
//get rid of the last ,
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := '
DELETE FROM consite_plans WHERE CSITEPLAN_CSITEID = ''
' + csitetoload + '
''
;';
DM1.SQLITEQUERY.Execute;
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := sqlstring;
DM1.SQLITEQUERY.Execute;
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := '
SELECT * FROM consite_plans WHERE CSITEPLAN_CSITEID = ''
' + csitetoload + '
''
AND CSITEPLAN_TYPE = ''
file''
;';
DM1.SQLITEQUERY.Execute;
if DM1.SQLITEQUERY.RecordCount > 0
then
begin
ftpdirectory := '
csitestore/plans';
try
if not DM1.FTP1.Connected
then DM1.FTP1.Connect;
try
try
DM1.FTP1.ChangeDir(ftpdirectory + '
/' + csitetoload);
TSingleSyncThread.Synchronize(
nil,
procedure
begin
if DirectoryExists(TPath.GetTempPath + '
/' + csitetoload)
then TDirectory.Delete(TPath.GetTempPath + '
/' + csitetoload, True);
end);
DownloadFolder('
plans', '
/home/' + ftpdirectory + '
/' + csitetoload , TPath.GetTempPath + '
/' + csitetoload);
TSingleSyncThread.Synchronize(
nil,
procedure
begin
TDirectory.Copy(TPath.GetTempPath + '
/' + csitetoload, csiteplanpath + '
/' + csitetoload);
end);
except
On E:
Exception do
begin
TSingleSyncThread.Queue(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := e.
Message;
end);
end;
end;
finally
DM1.FTP1.Disconnect;
filestosync.clear;
end;
except
On E:
Exception do
begin
TSingleSyncThread.Queue(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := e.
Message;
end);
end;
end;
end;
end
else
begin //if there is nothing to sync
DM1.SQLITEQUERY.Close;
DM1.SQLITEQUERY.SQL.Text := '
DELETE FROM consite_plans WHERE CSITEPLAN_CSITEID = ''
' + csitetoload + '
''
;';
DM1.SQLITEQUERY.Execute;
end;
except
On E:
Exception do
begin
TSingleSyncThread.Synchronize(
nil,
procedure
begin
CSITEDETFORM.SYNCLABEL.Text := e.
Message;
end);
end;
end;
finally
DM1.UniConnection1.Disconnect;
FreeandNil(filestosync);
end;