unit Livetrack;
interface
uses IdFTP, IdHTTP, Classes, DateUtils, SysUtils, windows, dialogs;
//(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;
FData : 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;
const Flugregel :
string;
const Flugart :
string;
const SID :
String;
const InitialClimb :
String;
const Zeit :
String;
const Runway :
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(pchar(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;
const Flugregel :
string;
const Flugart :
string;
const SID :
String;
const InitialClimb :
String;
const Zeit :
String;
const Runway :
String);
begin
self.FInfoDaten.add(CallSign + '
:' + Departure_Airport + '
:' + Arrival_Airport + '
:' + Current_Speed + '
:' + Current_Altitude + '
:' + Current_Waypoint + '
:' + Planned_Route + '
:' + Squawk + '
:' + Aircraft + '
:' + WakeTurbulanceClass + '
:' + Flugregel + '
:' + Flugart + '
:' + SID + '
:' + InitialClimb + '
:' + Zeit + '
:' + Runway);
end;
function TLiveTrack.UploadInfoDaten(TimeOut : Integer) : boolean;
var Stream : TMemoryStream;
begin
result := false;
if (self.FVID = '
none')
or (Self.FVID = '
')
then
exit;
Stream := TMemoryStream.Create;
self.FInfoDaten.SaveToStream(Stream);
self.FFTP.Port := 21;
if not self.FFTP.Connected
then
begin
self.FFTP.Connect(true,TimeOut);
if self.FFTPDirectory <> '
'
then
self.FFTP.ChangeDir(self.FFTPDirectory);
end;
try
self.FFTP.Put(Stream, self.VID + '
.csv' , false);
finally
result := true;
end;
self.FInfoDaten.Clear;
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;
var Time : TDateTime;
systime : tsystemtime;
begin
getSystemtime(systime);
Time := systemtimetodatetime(systime);
result := inttostr(DateTimeToUnix(Time));
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 Index, i : integer;
FileName :
string;
TimeStamp :
string;
begin
result := false;
FileName := self.FCacheDirectory + '
\' + self.FFileName;
//if (self.FVID = 'none') or (Self.FVID = '') then
// exit;
try
Index := datainList(self.FData);
TimeStamp := createTimeStamp;
if Index = -1
then
self.FData.add(self.FVID + '
:' + TimeStamp + '
:' + RealName + '
:' + ATC_Position + '
:' + Tool)
else
self.FData.strings[
Index] := self.FVID + '
:' + TimeStamp + '
:' + RealName + '
:' + ATC_Position + '
:' + Tool;
finally
result := true;
end;
end;
function TLivetrack.upload(TimeOut : Integer) : boolean;
var Stream : TMemoryStream;
begin
result := false;
self.FFTP.Port := 21;
// if (self.FVID = 'none') or (Self.FVID = '') then
// exit;
if not self.FFTP.Connected
then
begin
self.FFTP.Connect(true,TimeOut);
if self.FFTPDirectory <> '
'
then
self.FFTP.ChangeDir(self.FFTPDirectory);
end;
try
Stream := TMemoryStream.Create;
self.FData.SaveToStream(Stream);
self.FFTP.Put(Stream , self.FFileName , false);
finally
result := true;
end;
Stream.Free;
self.FData.clear;
self.FFTP.DisconnectSocket;
self.FFTP.Disconnect;
end;
function TLivetrack.download(TimeOut : Integer) : boolean;
var Inhalt :
String;
begin
result := false;
self.FData.clear;
if not self.FHTTP.Connected
then
self.FHTTP.Connect(TimeOut);
try
Inhalt := self.FHTTP.Get(self.FHTTPUrl + '
/' + self.FFileName);
self.FData.Text := Inhalt;
finally
result := true;
end;
self.FHTTP.DisconnectSocket;
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);
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 := '
none';
self.FInfoDaten.Create;
self.FData := TStringlist.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;
self.FData := TStringlist.create;
end;
// Ende Constructor
////////////////////////////////////////////////////////////////////////////////
{Destructor}
destructor TLivetrack.destroy;
begin
self.FFTP.Free;
self.FHTTP.free;
self.FInfoDaten.Free;
self.FData.Free;
inherited destroy;
end;
// Ende Destructor
////////////////////////////////////////////////////////////////////////////////
end.