unit Livetrack;
interface
uses IdFTP, IdHTTP, Classes, DateUtils, SysUtils;
//(const CallSign : String; const Departure_Airport : String; const Arrival_Airport : String; const Current_Speed : String; Current_Altitude : String; const Current_Waypoint : String; const Planned_Route : String; const Squawk : String; const Aircraft : String ; const WakeTurbulanceClass : String) : boolean;
type TFTP =
class(TIDFTP)
end;
type THTTP =
class(TIDHTTP)
end;
type TLivetrack =
class(TObject)
private
{private Vars}
FHTTP : THTTP;
FFTP : TFTP;
FCacheDirectory :
string;
FFTPHost :
String;
FFTPDirectory :
String;
FFTPLoginName :
String;
FFTPPassword :
String;
FHTTPUrl :
String;
FFileName :
String;
FVID :
String;
FInfoDaten : TStringList;
{Set Procedures}
procedure SetFTPHost(Host :
String);
procedure SetFTPLoginName(LoginName :
String);
procedure SetFTPPassword(Password :
String);
procedure SetVID(VID :
String);
{get Functions}
function GetFTPHost :
String;
function GetFTPLoginName :
String;
function GetFTPPassword :
String;
public
{Functions}
constructor create(
const CacheDirectory :
String;
const FTPHost :
string;
const FTPDirectory :
string;
const FTPLoginName :
string;
const FTPPassword :
string;
const HTTPUrl :
String;
const FileName :
String;
const VID :
string);
overload;
constructor create(
const CacheDirectory :
String;
const FTPHost :
string;
const FTPDirectory :
string;
const FTPLoginName :
string;
const FTPPassword :
string;
const HTTPUrl :
String;
const FileName :
String);
overload;
destructor destroy ;
override;
{Normal Functions}
function download(TimeOut : Integer) : boolean;
function upload(TimeOut : Integer) : boolean;
function refresh (
const RealName :
String;
const ATC_Position :
String;
const Tool :
String): boolean;
{InfoDaten Functions and Procedures}
procedure AddInfoDaten(
const CallSign :
String;
const Departure_Airport :
String;
const Arrival_Airport :
String;
const Current_Speed :
String; Current_Altitude :
String;
const Current_Waypoint :
String;
const Planned_Route :
String;
const Squawk :
String;
const Aircraft :
String ;
const WakeTurbulanceClass :
String);
function UploadInfoDaten(TimeOut : Integer) : boolean;
procedure ClearInfoDaten;
{properties}
property CacheDirectory :
String read FCacheDirectory
write FCacheDirectory;
property FTPHost :
String read GetFTPHost
write SetFTPHost;
property FTPDirectory :
String read FFTPDirectory
write FFTPDirectory;
property FTPLoginName :
String read GetFTPLoginName
write SetFTPLoginName;
property FTPPassword :
String read GetFTPPassword
write SetFTPPassword;
property HTTPUrl :
String read FHTTPUrl
write FHTTPUrl;
property FileName :
String read FFileName
write FFileName;
property VID :
String read FVID
write SetVID;
end;
implementation
{Set Procedures}
procedure TLiveTrack.ClearInfoDaten;
begin
self.FInfoDaten.clear;
deleteFile(self.FCacheDirectory + '
\' + self.FVID + '
.csv');
end;
procedure TLiveTrack.AddInfoDaten(
const CallSign :
String;
const Departure_Airport :
String;
const Arrival_Airport :
String;
const Current_Speed :
String; Current_Altitude :
String;
const Current_Waypoint :
String;
const Planned_Route :
String;
const Squawk :
String;
const Aircraft :
String ;
const WakeTurbulanceClass :
String);
begin
self.FInfoDaten.add(CallSign + '
:' + Departure_Airport + '
:' + Arrival_Airport + '
:' + Current_Speed + '
:' + Current_Altitude + '
:' + Current_Waypoint + '
:' + Planned_Route + '
:' + Squawk + '
:' + Aircraft + '
:' + WakeTurbulanceClass);
end;
function TLiveTrack.UploadInfoDaten(TimeOut : Integer) : boolean;
begin
result := false;
self.FInfoDaten.SaveToFile(self.CacheDirectory + '
\' + self.VID + '
.csv');
self.FFTP.Port := 21;
self.FFTP.Connect(true,TimeOut);
if self.FFTPDirectory <> '
'
then
self.FFTP.ChangeDir(self.FFTPDirectory);
try
self.FFTP.Put(self.FCacheDirectory + '
\' + self.VID + '
.csv', self.VID + '
.csv' , false);
finally
result := true;
end;
self.FFTP.Disconnect;
end;
procedure TLivetrack.SetFTPHost(Host :
String);
begin
self.FFTP.Host := Host;
end;
procedure TLivetrack.SetFTPLoginName(LoginName :
String);
begin
if self.FFTP.Connected
then
exit;
self.FFTP.Username := LoginName;
end;
procedure TLivetrack.SetFTPPassword(Password :
String);
begin
if self.FFTP.Connected
then
exit;
self.FFTP.Password := Password;
end;
procedure TLivetrack.SetVID(VID :
String);
begin
self.FVID := VID;
end;
// Ende Set Procedures
////////////////////////////////////////////////////////////////////////////////
{Get Functions}
function TLivetrack.GetFTPHost :
String;
begin
result := self.FFTP.Host;
end;
function TLivetrack.GetFTPLoginName :
String;
begin
result := self.FFTP.Username;
end;
function TLivetrack.GetFTPPassword :
String;
begin
result := self.FFTP.Password;
end;
// Ende Get Functions
////////////////////////////////////////////////////////////////////////////////
{Normal Functions}
function createTimeStamp :
string;
begin
result := inttostr(DateTimeToUnix(now));
end;
// *.csv - Aufbau {VID : TimeStamp : RealName : ATC Position : Tool}
function TLivetrack.refresh(
const RealName :
String;
const ATC_Position :
String;
const Tool :
String) : boolean;
function datainlist(
const TList : TStringlist) : integer;
var i : Integer;
begin
result := -1;
if TList.Count = 0
then
exit;
for i := 0
to TList.Count - 1
do
if self.FVID = copy(TList.Strings[i],1,pos('
:',TList.strings[i]) - 1)
then
begin
result := i;
break;
end;
end;
var TList : Tstringlist;
Index : integer;
FileName :
string;
TimeStamp :
string;
begin
result := false;
TList := TStringlist.Create;
FileName := self.FCacheDirectory + '
\' + self.FFileName;
try
if Fileexists(FileName)
then
Tlist.LoadFromFile(FileName);
Index := datainList(TList);
TimeStamp := createTimeStamp;
if Index = -1
then
TList.add(self.FVID + '
:' + TimeStamp + '
:' + RealName + '
:' + ATC_Position + '
:' + Tool)
else
TList.strings[
Index] := self.FVID + '
:' + TimeStamp + '
:' + RealName + '
:' + ATC_Position + '
:' + Tool;
finally
result := true;
end;
TList.SaveToFile(FileName);
TList.Free;
end;
function TLivetrack.upload(TimeOut : Integer) : boolean;
begin
result := false;
self.FFTP.Port := 21;
self.FFTP.Connect(true,TimeOut);
if self.FFTPDirectory <> '
'
then
self.FFTP.ChangeDir(self.FFTPDirectory);
try
self.FFTP.Put(self.FCacheDirectory + '
\' + self.FFileName , self.FFileName , false);
finally
result := true;
end;
self.FFTP.Disconnect;
end;
function TLivetrack.download(TimeOut : Integer) : boolean;
var FileStream : TFileStream;
begin
result := false;
FileStream := TFileStream.create(self.FCacheDirectory + '
\' + self.FFileName,fmcreate);
self.FHTTP.Connect(TimeOut);
try
self.FHTTP.Get(self.FHTTPUrl + '
/' + self.FFileName , FileStream);
finally
result := true;
end;
FileStream.free;
self.FHTTP.Disconnect;
end;
// Ende Normal Functions
////////////////////////////////////////////////////////////////////////////////
{Constructor}
constructor TLivetrack.create(
const CacheDirectory :
String;
const FTPHost :
string;
const FTPDirectory :
string;
const FTPLoginName :
string;
const FTPPassword :
string;
const HTTPUrl :
String;
const FileName :
String);
begin
inherited create;
self.FFTP := TFTP.Create(
nil);
self.FHTTP := THTTP.Create(
nil);
// Setzen der Parameter für HTTP und FTP
self.CacheDirectory := CacheDirectory;
self.FTPHost := FTPHost;
self.FTPDirectory := FTPDirectory;
self.FTPLoginName := FTPLoginName;
self.FTPPassword := FTPPassword;
self.HTTPUrl := HTTPUrl;
self.FileName := FileName;
self.VID := '
none';
self.FInfoDaten.Create;
end;
constructor TLivetrack.create(
const CacheDirectory :
String;
const FTPHost :
string;
const FTPDirectory :
string;
const FTPLoginName :
string;
const FTPPassword :
string;
const HTTPUrl :
String;
const FileName :
String;
const VID :
string);
begin
inherited create;
self.FFTP := TFTP.Create(
nil);
self.FHTTP := THTTP.Create(
nil);
self.FInfoDaten := TSTringList.create;
// Setzen der Parameter für HTTP und FTP
self.CacheDirectory := CacheDirectory;
self.FTPHost := FTPHost;
self.FTPDirectory := FTPDirectory;
self.FTPLoginName := FTPLoginName;
self.FTPPassword := FTPPassword;
self.HTTPUrl := HTTPUrl;
self.FileName := FileName;
self.VID := VID;
self.FInfoDaten.Create;
end;
// Ende Constructor
////////////////////////////////////////////////////////////////////////////////
{Destructor}
destructor TLivetrack.destroy;
begin
self.FFTP.Free;
self.FHTTP.free;
self.FInfoDaten.Free;
inherited destroy;
end;
// Ende Destructor
////////////////////////////////////////////////////////////////////////////////
end.