private static void UnmarshallResult(JsonUnmarshallerContext context, UploadMultipartPartResponse response) { if (context.ResponseData.GetHeaderValue("x-amz-sha256-tree-hash") != null) { response.Checksum = context.ResponseData.GetHeaderValue("x-amz-sha256-tree-hash"); } return; }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { UploadMultipartPartResponse response = new UploadMultipartPartResponse(); context.Read(); UnmarshallResult(context, response); return(response); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { UploadMultipartPartResponse response = new UploadMultipartPartResponse(); context.Read(); response.UploadMultipartPartResult = UploadMultipartPartResultUnmarshaller.GetInstance().Unmarshall(context); return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { UploadMultipartPartResponse response = new UploadMultipartPartResponse(); if (context.ResponseData.IsHeaderPresent("x-amz-sha256-tree-hash")) { response.Checksum = context.ResponseData.GetHeaderValue("x-amz-sha256-tree-hash"); } return(response); }
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); } }
public bool UploadPart(GlacierFilePart part, System.EventHandler <Amazon.Runtime.StreamTransferProgressArgs> progressCallback) { UploadMultipartPartRequest uploadRequest = new UploadMultipartPartRequest() { Body = new MemoryStream(part.Data), Checksum = part.Checksum, Range = part.Range, StreamTransferProgress = progressCallback, UploadId = part.UploadId, VaultName = _vault }; UploadMultipartPartResponse response = _amazonGlacierClient.UploadMultipartPart(uploadRequest); if (part.Checksum == response.UploadMultipartPartResult.Checksum) { return(true); } else { return(false); } }
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; } }