예제 #1
0
        /// <summary>
        /// 处理下载文件块
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="fileName">下载文件名</param>
        /// <param name="chunkNumber">块号</param>
        /// <returns>文件块信息</returns>
        async Task <FileChunkInfo> IFileGrain.DownloadFileChunk(string message, string fileName, int chunkNumber)
        {
            if (chunkNumber <= 0)
            {
                return(null);
            }

            string sourcePath = Path.Combine(DownloadPath, fileName);

            if (!File.Exists(sourcePath))
            {
                throw new InvalidOperationException(String.Format("不存在下载文件: {0}", fileName));
            }

            await using (FileStream sourceStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                FileChunkInfo result = await FileChunkInfo.CreateAsync(sourceStream, fileName, chunkNumber, MaxChunkSize);

                if (result.Done && _service != null)
                {
                    await _service.AfterDownloadFile(message, sourcePath);
                }
                return(result);
            }
        }