Issue with uploading encrypted file

Apr 10, 2012 at 12:13 PM

1. I have uploaded an encrypted file without dividing the encrypted file into chuncks then the upload was successful.
2. I am storing the encrypted file in isolated storage and from there i am uploading the file into the cloud storage i am able to decrypt the file which i stored in the isolated  storage.
 
3. If I upload a single chunck at a time the upload is successful and i am able to decrypt the file.
 
4.If i upload the encrypted file in chuncks and using the parallel upload then I am facing problem.
 
the below is the code for chuncking the file into chuncks
       public Collection<DataPacket> TransformStreamToPackets(Stream sourceStream, int intThreadCount)
        {
            if (sourceStream != null && sourceStream.CanRead)
            {
                int bytesToRead = 0;
                int serialNumber = 1;
                long Packetsize = this.packetSize;
                intThreadCount = 600;
                byte[] buffer = new byte[Packetsize];
                var dataBlocks = new Collection<DataPacket>();
                while ((bytesToRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    var dataPacket = new DataPacket()
                    {
                        IsTransported = false,
                        RetryCount = 0,
                        SerialNumber = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "{0:D4}", serialNumber++)))
                    };
                    dataPacket.SetPayload(buffer);
                    dataBlocks.Add(dataPacket);
                }
                return dataBlocks;
            }
            return null;
        }
   
   The code for uploading chuncks is here
 public void StartUpload()
        {
            if (this.packets.Count > 1)
            {
                long concurrencyLevel = 0;

                this.allTasks = new Task[this.packets.Count];
                totalsize = this.packets.Count;
                while (new Func<bool>(() => { return packets.Count(packet => packet.IsTransported == false) > 0 ? true : false; })())
                {
                    if (concurrencyLevel < this.packets.Count)
                    {
                        var uploadBlock = (from uploadPacket in this.packets
                                           where uploadPacket.IsTransported == false
                                           select uploadPacket).FirstOrDefault();
                        uploadBlock.IsTransported = null;
                        this.allTasks[concurrencyLevel] = Task.Factory.StartNew(
                            () => this.UploadFileChunk(uploadBlock, this.file, this.request.GetBlockBlobUri(uploadBlock.SerialNumber)),
                            this.cancellationTokens.Token);
                        concurrencyLevel++;
                    }
                    else
                    {
                        try
                        {

                            Task.WaitAll(this.allTasks);
                            concurrencyLevel = 0;
                        }
                        catch (AggregateException ex)
                        {
                            this.NotifyClient(Constants.UploadCompleteReason.ErrorOccurred, ex.Message);
                        }
                    }
                 }
            }
            else
            {
                Task.Factory.StartNew(() => this.UploadFileChunk(this.packets.FirstOrDefault(), this.file), this.cancellationTokens.Token);
            }
        }

Kindly help me