Componentes.Terceros.RemObj.../internal/5.0.23.613/1/RemObjects SDK for Delphi/Samples/Extended File Transfer/ExtendedFileTransferService_Impl.pas
david d99a44999f - Modificación del paquete RemObjects_Core_D10 para que sea un paquete de runtime/designtime (antes era designtime sólo)
- Recompilación en Delphi10 de todos los paquetes de RO para generar las DCU's en Lib\D10

git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@7 b6239004-a887-0f4b-9937-50029ccdca16
2007-09-10 13:36:58 +00:00

105 lines
3.5 KiB
ObjectPascal

unit ExtendedFileTransferService_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:} Classes, SysUtils,
{RemObjects:} uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions, uRORemoteDataModule,
{Generated:} ExtendedFileTransferLibrary_Intf,
ExtendedFileTransferServerData;
type
{ TExtendedFileTransferService }
TExtendedFileTransferService = class(TRORemoteDataModule, IExtendedFileTransferService)
private
function getFileDirectory: string;
protected
{ IExtendedFileTransferService methods }
procedure downloadsequence(const filename: string; const sequence: Integer; out filedata: Binary; out filesize: Int64);
procedure uploadchunk(const isfirst: Boolean; const filename: string; const filedata: Binary);
procedure uploadfinished(const filename: string; const filesize: Int64);
end;
implementation
{$R *.dfm}
uses
{Generated:} ExtendedFileTransferLibrary_Invk;
procedure Create_ExtendedFileTransferService(out anInstance: IUnknown);
begin
anInstance := TExtendedFileTransferService.Create(nil);
end;
{ ExtendedFileTransferService }
procedure TExtendedFileTransferService.downloadsequence(const filename: string; const sequence: Integer; out filedata: Binary; out filesize: Int64);
const
Block: Integer = 65536;
var
Position: Int64;
MemStream: TFileStream;
localfilename: string;
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 TExtendedFileTransferService.getFileDirectory: string;
begin
result := ExtendedFileTransferServerData.uploadFolder;
end;
procedure TExtendedFileTransferService.uploadchunk(const isfirst: Boolean; const filename: string; const filedata: Binary);
var
NewFile: TFileStream;
localfilename: string;
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 TExtendedFileTransferService.uploadfinished(const filename: string; const filesize: Int64);
begin
(EventRepository as IFileEvents_Writer).OnNewFileAvailable(Session.SessionID, filename, filesize);
end;
initialization
TROClassFactory.Create('ExtendedFileTransferService', Create_ExtendedFileTransferService, TExtendedFileTransferService_Invoker);
finalization
end.