git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@68 b6239004-a887-0f4b-9937-50029ccdca16
105 lines
3.4 KiB
ObjectPascal
105 lines
3.4 KiB
ObjectPascal
unit FileBroadcastService_Impl;
|
|
|
|
{----------------------------------------------------------------------------}
|
|
{ This unit was automatically generated by the RemObjects SDK after reading }
|
|
{ the RODL file associated with this project . }
|
|
{ }
|
|
{ This is where you are supposed to code the implementation of your objects. }
|
|
{----------------------------------------------------------------------------}
|
|
|
|
interface
|
|
|
|
uses
|
|
{vcl:} Windows, Classes, SysUtils,
|
|
{RemObjects:} uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions, uRORemoteDataModule,
|
|
{Generated:} FileBroadcastLibrary_Intf,
|
|
FileBroadcastServerData;
|
|
|
|
type
|
|
{ TFileBroadcastService }
|
|
TFileBroadcastService = class(TRORemoteDataModule, IFileBroadcastService)
|
|
private
|
|
function getFileDirectory: Widestring;
|
|
protected
|
|
{ IFileBroadcastService methods }
|
|
procedure downloadsequence(const filename: Widestring; const sequence: Integer; out filedata: Binary; out filesize: Int64);
|
|
procedure uploadchunk(const isfirst: Boolean; const filename: Widestring; const filedata: Binary);
|
|
procedure uploadfinished(const filename: Widestring; const filesize: Int64);
|
|
end;
|
|
|
|
implementation
|
|
{$R *.dfm}
|
|
uses
|
|
{Generated:} FileBroadcastLibrary_Invk;
|
|
|
|
procedure Create_FileBroadcastService(out anInstance: IUnknown);
|
|
begin
|
|
anInstance := TFileBroadcastService.Create(nil);
|
|
end;
|
|
|
|
{ FileBroadcastService }
|
|
|
|
procedure TFileBroadcastService.downloadsequence(const filename: Widestring; const sequence: Integer; out filedata: Binary; out filesize: Int64);
|
|
const
|
|
Block: Integer = 65536;
|
|
var
|
|
Position: Int64;
|
|
MemStream: TFileStream;
|
|
localfilename: Widestring;
|
|
begin
|
|
fileData := Binary.Create;
|
|
localfilename := getFileDirectory + filename;
|
|
if not FileExists(localfilename) then exit;
|
|
MemStream := TFileStream.Create(localfilename, fmopenRead);
|
|
try
|
|
FileSize := MemStream.Size;
|
|
Position := Block * (Sequence - 1);
|
|
if Position <= FileSize then begin
|
|
MemStream.Position := Position;
|
|
if Position + Block > FileSize then
|
|
fileData.CopyFrom(MemStream, FileSize - Position)
|
|
else
|
|
fileData.CopyFrom(MemStream, Block);
|
|
end;
|
|
finally
|
|
MemStream.Free;
|
|
end;
|
|
end;
|
|
|
|
function TFileBroadcastService.getFileDirectory: Widestring;
|
|
begin
|
|
result := FileBroadcastServerData.uploadFolder;
|
|
end;
|
|
|
|
procedure TFileBroadcastService.uploadchunk(const isfirst: Boolean; const filename: Widestring; const filedata: Binary);
|
|
var
|
|
NewFile: TFileStream;
|
|
localfilename: Widestring;
|
|
begin
|
|
localfilename := getFileDirectory + filename;
|
|
if isfirst and Fileexists(localfilename) then DeleteFile(localfilename);
|
|
if FileExists(localfilename) then
|
|
NewFile := TFileStream.Create(localfilename, fmOpenReadWrite)
|
|
else
|
|
NewFile := TFileStream.Create(localfilename, fmCreate);
|
|
try
|
|
NewFile.Seek(0, soFromEnd);
|
|
filedata.SaveToStream(NewFile);
|
|
finally
|
|
NewFile.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TFileBroadcastService.uploadfinished(const filename: Widestring; const filesize: Int64);
|
|
begin
|
|
(EventRepository as IFileEvents_Writer).OnNewFileAvailable(Session.SessionID, filename, filesize);
|
|
end;
|
|
|
|
initialization
|
|
TROClassFactory.Create('FileBroadcastService', Create_FileBroadcastService, TFileBroadcastService_Invoker);
|
|
|
|
finalization
|
|
|
|
end.
|
|
|