Пример #1
0
        private string ConsolidateFile(ResumableConfiguration configuration)
        {
            var path = GetFilePath(configuration);
            using (var destStream = File.Create(path, 15000))
            {
                for (int chunkNumber = 1; chunkNumber <= configuration.Chunks; chunkNumber++)
                {
                    var chunkFileName = GetChunkFileName(chunkNumber, configuration.Identifier);
                    using (var sourceStream = File.OpenRead(chunkFileName))
                    {
                        sourceStream.CopyTo(destStream);
                    }
                }
                destStream.Close();
            }

            return path;
        }
Пример #2
0
 private void DeleteChunks(ResumableConfiguration configuration)
 {
     for (int chunkNumber = 1; chunkNumber <= configuration.Chunks; chunkNumber++)
     {
         var chunkFileName = GetChunkFileName(chunkNumber, configuration.Identifier);
         File.Delete(chunkFileName);
     }
 }
Пример #3
0
 private bool AllChunksAreHere(ResumableConfiguration configuration)
 {
     for (int chunkNumber = 1; chunkNumber <= configuration.Chunks; chunkNumber++)
         if (!ChunkIsHere(chunkNumber, configuration.Identifier)) return false;
     return true;
 }
Пример #4
0
        private void TryAssembleFile(ResumableConfiguration configuration)
        {
            if (AllChunksAreHere(configuration))
            {
                // Create a single file
                var path = ConsolidateFile(configuration);

                // Rename consolidated with original name of upload
                RenameFile(path, Path.Combine(root, configuration.FileName));

                // Delete chunk files
                DeleteChunks(configuration);
            }
        }
Пример #5
0
 private string GetFilePath(ResumableConfiguration configuration)
 {
     return Path.Combine(root, configuration.Identifier);
 }