Exemplo n.º 1
0
        public void Run()
        {
            short retries = 0;

            while (retries++ < NUM_RETRIES)
            {
                try
                {
                    GlacierFilePart part = new GlacierFilePart(ref data, checksum, start, end, uploadId);
                    api.UploadPart(part, OnTransferProgress);
                    metric.incrementTransferredParts();
                    return;
                }
                catch (Exception ex)
                {
                    // Remove what we've uploaded so far from the metrics just to be precise.
                    metric.removeTransferredBytes(lastBytesCount);

                    // Reset the last byte count to zero or we're going to mess things up later.
                    lastBytesCount = 0;

                    Console.WriteLine("Upload exception: " + ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        public void Download()
        {
            int retries = 0;

            while (retries++ < 3)
            {
                try
                {
                    ArchivePartInfo info = api.DownloadArchivePart(jobId, start, end);

                    Stream      stream      = info.Stream();
                    List <byte> dynamicData = new List <byte>();
                    int         data;
                    long        bytesRead = 0;
                    while ((data = stream.ReadByte()) != -1)
                    {
                        bytesRead = metric.incrementTransferredBytes(1);
                        dynamicData.Add((byte)data);
                    }

                    bucket.Initialize(dynamicData.Count);
                    dynamicData.CopyTo(bucket.Data());

                    using (Stream hashStream = new MemoryStream(bucket.Data(), 0, dynamicData.Count))
                    {
                        string checksum = Amazon.Glacier.TreeHashGenerator.CalculateTreeHash(hashStream);

                        if (checksum != info.Checksum())
                        {
                            metric.removeTransferredBytes(bytesRead);
                            throw new Exception("Checksum mismatch");
                        }

                        bucket.Checksum(checksum);
                        bucket.IsReady(true);

                        metric.incrementTransferredParts();
                    }

                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Downloader Exception: " + e.Message);
                }
            }

            Console.WriteLine("Download failed");
        }