/// <summary>
        /// Download a chunk of data
        /// </summary>
        /// <param name="logonId">Logon id of user</param>
        /// <param name="TransferId">Transfer id</param>
        /// <param name="StreamPosition">The start position of the data chunk</param>
        /// <returns></returns>
        public static FileChunkData DownloadChunk(Guid logonId, Guid TransferId, long StreamPosition)
        {
            FileTransferData FileTransferData = Host.GetFileTransferData(logonId);

            if (!FileTransferData.IsDownload)
            {
                throw new Exception("File download has not been started");
            }

            if (FileTransferData.TransferId != TransferId)
            {
                throw new Exception("Transfer id does not match");
            }

            if (FileTransferData.FileStream == null)
            {
                throw new Exception("File download has not been started or has timed out");
            }

            if (FileTransferData.FileStream.Position != StreamPosition)
            {
                FileTransferData.FileStream.Seek(StreamPosition, SeekOrigin.Begin);
            }

            FileChunkData FileChunkData = new FileChunkData();

            FileChunkData.Bytes     = new byte[Host.FileTransferChunkSize];
            FileChunkData.ChunkSize = FileTransferData.FileStream.Read(FileChunkData.Bytes,
                                                                       0, Host.FileTransferChunkSize);

            return(FileChunkData);
        }
Exemple #2
0
        /// <summary>
        /// Download a document chunk
        /// </summary>
        /// <param name="logonId"></param>
        /// <param name="TransferId">Transfer id obtained when starting the download</param>
        /// <param name="FilePosition">Position in the file to start downloading the chunk</param>
        /// <returns></returns>
        public DownloadChunkReturnValue DocumentDownloadChunk(Guid logonId, Guid TransferId, long FilePosition)
        {
            DownloadChunkReturnValue ReturnValue = new DownloadChunkReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    FileChunkData FileChunkData = FileTransfer.DownloadChunk(logonId, TransferId, FilePosition);

                    ReturnValue.ChunkSize = FileChunkData.ChunkSize;
                    ReturnValue.Bytes     = FileChunkData.Bytes;
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (Exception ex)
            {
                ReturnValue.Success = false;
                ReturnValue.Message = ex.Message;
            }

            return(ReturnValue);
        }