示例#1
0
        static List <string> UploadParts(string uploadID, AmazonGlacier client)
        {
            var  partChecksumList = new List <string>();
            long currentPosition  = 0;
            var  buffer           = new byte[Convert.ToInt32(partSize)];

            long fileLength = new FileInfo(BackupFilePath).Length;

            WriteFileUploadProgress(currentPosition, fileLength);
            using (var fileToUpload = new FileStream(BackupFilePath, FileMode.Open, FileAccess.Read))
            {
                while (fileToUpload.Position < fileLength)
                {
                    var uploadPartStream = GlacierUtils.CreatePartStream(fileToUpload, partSize);
                    var checksum         = TreeHashGenerator.CalculateTreeHash(uploadPartStream);
                    partChecksumList.Add(checksum);
                    // Upload part.
                    var uploadMPUrequest = new UploadMultipartPartRequest()
                    {
                        VaultName = VaultName,
                        Body      = uploadPartStream,
                        Checksum  = checksum,
                        UploadId  = uploadID
                    };
                    uploadMPUrequest.SetRange(currentPosition, currentPosition + uploadPartStream.Length - 1);
                    client.UploadMultipartPart(uploadMPUrequest);
                    currentPosition = currentPosition + uploadPartStream.Length;
                    WriteFileUploadProgress(currentPosition, fileLength);
                }
            }
            return(partChecksumList);
        }
示例#2
0
        private bool retryUpload(object f_object)
        {
            try
            {
                ThreadData    objData          = null;
                AmazonGlacier client           = null;
                Stream        uploadPartStream = null;

                objData = (ThreadData)f_object;

                string uploadID = objData.uploadID;
                client = objData.client;
                long currentPosition = objData.currentPosition;
                Form1.log.Info("Trying to upload Part :" + Convert.ToString(objData.currentPosition));

                //For the last one we need to make sure the buffer is the right size?
                //The uploadMPUrequest.SetRange probably takes care of this.

                int memoryBufferIndex = 0;                                      //The index into buffer at which the stream begin
                int memoryBuffercount = (int)(objData.uploadPartStream.Length); //The length of the stream in bytes.

                uploadPartStream = new MemoryStream(objData.buffer, memoryBufferIndex, memoryBuffercount);

                //To ensure that part data is not corrupted in transmission, you compute a SHA256 tree
                // hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash.
                //If these hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see Computing Checksums
                string checksum = TreeHashGenerator.CalculateTreeHash(uploadPartStream);

                SHA256ConcurrentQueue.Enqueue(checksum);

                UploadMultipartPartRequest uploadMPUrequest = new UploadMultipartPartRequest()
                {
                    VaultName = vaultName,
                    Body      = uploadPartStream,
                    Checksum  = checksum,
                    UploadId  = uploadID
                };

                uploadMPUrequest.SetRange(currentPosition, currentPosition + objData.uploadPartStream.Length - 1);

                UploadMultipartPartResponse mpr = client.UploadMultipartPart(uploadMPUrequest);
                Form1.log.Info("Retry Success " + Convert.ToString(mpr.ContentLength) + "bytes" + " for Part  :" + Convert.ToString(objData.currentPosition));
                return(true);
            }
            catch (Exception ex)
            {
                Form1.log.Error(ex.ToString());
                return(false);
            }
        }
示例#3
0
        private void ThreadUpload(object f_object)
        {
            ThreadData    objData          = null;
            AmazonGlacier client           = null;
            Stream        uploadPartStream = null;

            try
            {
                objData = (ThreadData)f_object;

                string uploadID = objData.uploadID;
                client = objData.client;
                long currentPosition = objData.currentPosition;
                Form1.log.Info("Trying to upload Part :" + Convert.ToString(objData.currentPosition));

                //For the last one we need to make sure the buffer is the right size?
                //The uploadMPUrequest.SetRange probably takes care of this.

                int memoryBufferIndex = 0;                                      //The index into buffer at which the stream begin
                int memoryBuffercount = (int)(objData.uploadPartStream.Length); //The length of the stream in bytes.

                uploadPartStream = new MemoryStream(objData.buffer, memoryBufferIndex, memoryBuffercount);

                //To ensure that part data is not corrupted in transmission, you compute a SHA256 tree
                // hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash.
                //If these hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see Computing Checksums
                string checksum = TreeHashGenerator.CalculateTreeHash(uploadPartStream);

                SHA256ConcurrentQueue.Enqueue(checksum);

                UploadMultipartPartRequest uploadMPUrequest = new UploadMultipartPartRequest()
                {
                    VaultName = vaultName,
                    Body      = uploadPartStream,
                    Checksum  = checksum,
                    UploadId  = uploadID
                };

                uploadMPUrequest.SetRange(currentPosition, currentPosition + objData.uploadPartStream.Length - 1);

                UploadMultipartPartResponse mpr = client.UploadMultipartPart(uploadMPUrequest);

                Form1.log.Info("Sent " + Convert.ToString(mpr.ContentLength) + "bytes" + " for Part  :" + Convert.ToString(objData.currentPosition));
            }
            catch (Exception e)
            {
                Form1.log.Error(e.ToString());
                Form1.log.Error(e.StackTrace);
                Form1.log.Info("Retrying Part " + Convert.ToString(objData.currentPosition));

                //Retrying up to 10 times - waiting longer each try
                {
                    int  fv = 0;
                    bool successfulPartUpload = false;
                    while (fv < 10 && successfulPartUpload == false)
                    {
                        successfulPartUpload = retryUpload(f_object);
                        Thread.Sleep(4000 * fv);
                    }
                }
            }
            finally
            {
                if (Interlocked.Decrement(ref ActiveWorkerCount) <= 0)
                {
                    AllWorkerCompletedEvent.Set();
                }

                uploadPartStream = null;
                f_object         = null;
                objData          = null;
                client           = null;
            }
        }
示例#4
0
        static List<string> UploadParts(string uploadID, AmazonGlacier client)
        {
            var partChecksumList = new List<string>();
            long currentPosition = 0;
            var buffer = new byte[Convert.ToInt32(partSize)];

            long fileLength = new FileInfo(BackupFilePath).Length;
            WriteFileUploadProgress(currentPosition, fileLength);
            using (var fileToUpload = new FileStream(BackupFilePath, FileMode.Open, FileAccess.Read))
            {
                while (fileToUpload.Position < fileLength)
                {
                    var uploadPartStream = GlacierUtils.CreatePartStream(fileToUpload, partSize);
                    var checksum = TreeHashGenerator.CalculateTreeHash(uploadPartStream);
                    partChecksumList.Add(checksum);
                    // Upload part.
                    var uploadMPUrequest = new UploadMultipartPartRequest()
                    {
                        VaultName = VaultName,
                        Body = uploadPartStream,
                        Checksum = checksum,
                        UploadId = uploadID
                    };
                    uploadMPUrequest.SetRange(currentPosition, currentPosition + uploadPartStream.Length - 1);
                    client.UploadMultipartPart(uploadMPUrequest);
                    currentPosition = currentPosition + uploadPartStream.Length;
                    WriteFileUploadProgress(currentPosition, fileLength);
                }
            }
            return partChecksumList;
        }