unit uVisualFrame_TPS_ChunkUploader;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.IOUtils,

  //myUnits

  uHTTP_ConnectionParams_TPS_ChunkUploader,
  uHTTPRequests_TPS_ChunkUploader,
  uDirectories_TPS_ChunkUploader,
  uSendFileInChunks_TPS_ChunkUploader,


  System.Actions, Vcl.ActnList

  ;


type

TFilesInterruptedNotUploaded=record

  FileNamesSL:TStringList;
  TempDirsOnClientSL:TStringList;
  TempDirsOnServerSL:TStringList;

end;

type
  TVisualFrame_TPS_ChunkUploader = class(TFrame)
    ActionList: TActionList;
    aSendFileInChunks: TAction;



    procedure aSendFileInChunksExecute(Sender: TObject);

  private
    { Private declarations }


    FFilesInterruptedNotUploaded:TFilesInterruptedNotUploaded;

    FFilePath:string;
    FChunkSize:Int64;

    FHTTP_ConnectionParams:THTTP_ConnectionParams_TPS_ChunkUploader;
    FHTTPRequests:THTTPRequests_TPS_ChunkUploader;
    FDirectories:TDirectories_TPS_ChunkUploader;
    FSendFileInChunks:TSendFileInChunks_TPS_ChunkUploader;
    FConnectionTimeoutHTTP:integer;
    FReadTimeoutHTTP:integer;

  public
    { Public declarations }

  constructor Create(AOwner: TComponent); override;
  destructor destroy(); override;

  procedure Test();

  property HTTP_ConnectionParams:THTTP_ConnectionParams_TPS_ChunkUploader
  read FHTTP_ConnectionParams write FHTTP_ConnectionParams;


  property HTTPRequests:THTTPRequests_TPS_ChunkUploader
  read FHTTPRequests write FHTTPRequests;


  property Directories:TDirectories_TPS_ChunkUploader read
  FDirectories write FDirectories;

  property SendFileInChunks:TSendFileInChunks_TPS_ChunkUploader read
  FSendFileInChunks write FSendFileInChunks;

  property ConnectionTimeoutHTTP:integer read FConnectionTimeoutHTTP write FConnectionTimeoutHTTP;
  property ReadTimeoutHTTP:integer read  FReadTimeoutHTTP write FReadTimeoutHTTP;

  property FilePath:string read FFilePath write FFilePath;
  property ChunkSize:Int64 read FChunkSize write FChunkSize;

  property FilesInterruptedNotUploaded:TFilesInterruptedNotUploaded read
  FFilesInterruptedNotUploaded write FFilesInterruptedNotUploaded;

//    FChunkSize:Int64;

  end;

implementation

{$R *.dfm}

{ TVisualFrame_TPS_ChunkUploader }

procedure TVisualFrame_TPS_ChunkUploader.aSendFileInChunksExecute(Sender: TObject);
begin

Assert(FFilePath<>'','Please fill FFilePath');
Assert(FChunkSize<>0,'Please fill ChunkSize');
FSendFileInChunks.SendFileInChunks(FFilePath,ChunkSize);

end;

constructor TVisualFrame_TPS_ChunkUploader.Create(AOwner: TComponent);
begin
  inherited;

  // HTTP Connection Params
   FHTTP_ConnectionParams:=THTTP_ConnectionParams_TPS_ChunkUploader.Create(Self);

  //HTTPRequests
   FHTTPRequests:=THTTPRequests_TPS_ChunkUploader.Create(Self);

   // Directories
   FDirectories:=TDirectories_TPS_ChunkUploader.Create(Self);

   // SendFileInChunks
   FSendFileInChunks:=TSendFileInChunks_TPS_ChunkUploader.Create(Self);


  with FFilesInterruptedNotUploaded do begin

  FileNamesSL:=TStringList.Create;
  TempDirsOnClientSL:=TStringList.Create;
  TempDirsOnServerSL:=TStringList.Create;

  end;



end;

destructor TVisualFrame_TPS_ChunkUploader.destroy;
begin

  with FFilesInterruptedNotUploaded do begin

  FreeAndNil(FileNamesSL);
  FreeAndNil(TempDirsOnClientSL);
  FreeAndNil(TempDirsOnServerSL);

  end;


  inherited;
end;

procedure TVisualFrame_TPS_ChunkUploader.Test;

var FileName:string;
    FS:TFileStream;

begin

FileName:='SomeTestFile.txt';

if not TFile.Exists(FileName) then

  begin
  FS:=TFile.Create(FileName);
  CloseHandle(FS.Handle);
  end;


TFile.WriteAllText(FileName,'SomeTestContent');
FSendFileInChunks.SendFileInChunks(FileName,1);

//CloseHandle(FS.Handle);
TFile.Delete('SomeTestFile.txt');


end;

end.
