public void Upload(TransferInfo transferInfo, Stream data)
        {
            // Compute how much will be left over for the last chunk
            long dataLength = data.Length;
            long chunkSize = SendChunkSize == 0 ? 256000 : SendChunkSize;
            long remainder = dataLength % chunkSize;
            long chunkCount = dataLength / chunkSize;

            // Handle the case of small files
            if (chunkSize >= dataLength)
            {
                chunkSize = dataLength;
                remainder = 0;
                chunkCount = 1;
            }

            string sessionId = m_Proxy.BeginUploadSession(transferInfo);
            for (long index = 0; index < chunkCount; index++)
            {
                byte[] chunk = new byte[chunkSize];
                data.Read(chunk, (int)(index * chunkSize), (int)chunkSize);
                m_Proxy.UploadChunk(sessionId, chunk);
            }
            if (remainder > 0)
            {
                byte[] chunk = new byte[remainder];
                data.Read(chunk, (int)(chunkCount * chunkSize), (int)remainder);
                m_Proxy.UploadChunk(sessionId, chunk);
            }
            m_Proxy.CompleteUpload(sessionId);

        }
Esempio n. 2
0
 string IFileTransferService.BeginUploadSession(TransferInfo uploadInfo)
 {
     Guid sessionId = Guid.NewGuid();
     lock (_BufferedSessions)
     {
         FileStream stream = File.OpenWrite(uploadInfo.FilePath);
         _BufferedSessions.Add(sessionId, new Tuple<TransferInfo,Stream>(uploadInfo,stream));
     }
     return sessionId.ToString();
 }
        public void Download(TransferInfo transferInfo, Stream stream)
        {
            DownloadSessionInfo sessionInfo = m_Proxy.StartDownload(transferInfo);

            for (int i = 0; i < sessionInfo.ChunkCount; i++)
            {
                byte[] chunk = m_Proxy.DownloadChunk(sessionInfo.SessionId, i);
                stream.Write(chunk, 0, chunk.Length);
            }
            m_Proxy.DownloadComplete(sessionInfo.SessionId);
        }
Esempio n. 4
0
 DownloadSessionInfo IFileTransferService.StartDownload(TransferInfo downloadInfo)
 {
     Guid sessionId = Guid.NewGuid();
     FileStream stream = File.OpenRead(downloadInfo.FilePath);
     long remainder;
     long chunkCount;
     long chunkSize;
     CalculateChunkCountSizeAndRemainder(stream.Length, out remainder, out chunkCount, out chunkSize);
     lock (_BufferedSessions)
     {
         _BufferedSessions.Add(sessionId, new Tuple<TransferInfo,Stream>(downloadInfo,stream));
     }
     DownloadSessionInfo downloadSessionInfo = new DownloadSessionInfo
     {
         ChunkCount = chunkCount + (remainder > 0 ? 1 : 0),
         SessionId = sessionId.ToString()
     };
     return downloadSessionInfo;
 }