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.