public AWSArchiveResult DownloadFile(AWSArchiveRquest request) { archiveRequest = request; using (manager = new ArchiveTransferManager(RegionEndpoint.USEast1)) { if (CheckRequiredFields()) { try { Form1.log.Info("Download Archive" + request.ArchiveID + " " + request.Description + " " + request.FileName); try { var options = new DownloadOptions(); options.StreamTransferProgress += OnProgress; // Download an archive. manager.Download(vaultName, request.ArchiveID, request.Description, options); if (request.Description.Contains(".tif")) { String outfileName = String.Empty; String fileName = request.Description; FileInfo fi = new FileInfo(fileName); fi.MoveTo(fileName + ".z"); fileName = fileName + ".z"; outfileName = fileName.Replace(".z", ""); FileStream inputFile = File.Open(fileName, FileMode.Open, FileAccess.Read); byte[] treeHash = Form1.ComputeSHA256TreeHash(inputFile); String zipChecksum = BitConverter.ToString(treeHash).Replace("-", "").ToLower(); Form1.log.Info(fileName + " Tree SHA 256 Checksum : " + zipChecksum); Form1.log.Info(fileName + " Original Injection Tree SHA 256 Checksum : " + request.ChecksumTreeSHA256Compressed); ParallelCompress.doNotUseTPL = false; ParallelCompress.compressStrictSeqential = false; ParallelCompress.UncompressFast(outfileName, fileName, true); inputFile = File.Open(outfileName, FileMode.Open, FileAccess.Read); treeHash = Form1.ComputeSHA256TreeHash(inputFile); String decompressedChecksum = BitConverter.ToString(treeHash).Replace("-", "").ToLower(); Form1.log.Info(outfileName + " Decmpressed Tree SHA 256 Checksum : " + zipChecksum); Form1.log.Info(outfileName + " Decmplressed Original Tree SHA 256 Checksum : " + request.ChecksumTreeSHA256Compressed); } } catch (AmazonGlacierException e) { Form1.log.Error(e.ToString()); } catch (AmazonServiceException e) { Form1.log.Error(e.ToString()); } catch (Exception e) { Form1.log.Error(e.ToString()); } } catch (AmazonGlacierException e) { Form1.log.Error(e.ToString()); } catch (AmazonServiceException e) { Form1.log.Error(e.ToString()); } } return(new AWSArchiveResult()); } }
private void archiveFile(String sinkDirectory, string sourceDirectory, string fileName, ArrayList awsDynamoFields, ArrayList awsDynamoVals) { try { log.Info("Moving " + sourceDirectory + fileName + " to " + sinkDirectory); awsDynamoFields.Add("sourceDirectory"); awsDynamoVals.Add(sourceDirectory); awsDynamoFields.Add("fileName"); awsDynamoVals.Add(fileName); awsDynamoFields.Add("awsVaultName"); awsDynamoVals.Add(awsVaultName); awsDynamoFields.Add("tarLogName"); awsDynamoVals.Add(tarLogName); String sha256TreeHash = String.Empty; File.Copy(sourceDirectory + "\\" + fileName, sinkDirectory + "\\" + fileName, true); sha256TreeHash = String.Empty; if (doCompress.Checked == true) { klDOTNETTimer kldnt = new klDOTNETTimer(); ParallelCompress.doNotUseTPL = false; ParallelCompress.compressStrictSeqential = false; String outfileName = String.Empty; String fileNameLoc = sinkDirectory + "\\" + fileName; FileStream inputFile = File.Open(fileNameLoc, FileMode.Open, FileAccess.Read); kldnt.Start(); byte[] treeHash = ComputeSHA256TreeHash(inputFile); String fileChecksum = BitConverter.ToString(treeHash).Replace("-", "").ToLower(); kldnt.Stop(); double itime = kldnt.Duration; log.Info("dt Compute SHA256 Tree Hash : " + fileName + " = " + Convert.ToString(itime)); sha256TreeHash = BitConverter.ToString(treeHash).Replace("-", "").ToLower(); log.Info("dt Compute SHA256 Hash : " + fileName + " = " + Convert.ToString(itime)); log.Info("SHA 256 Tree : " + fileName + " = " + sha256TreeHash); FileInfo fio = new System.IO.FileInfo(fileName); String shortName = fileName.Replace(fio.Extension, ""); outfileName = sinkDirectory + "\\" + shortName + ".z"; log.Info("Compressing " + fileName + "\\n"); ParallelCompress.CompressFast(outfileName, fileNameLoc, true); FileStream outputFileStream = File.Open(outfileName, FileMode.Open, FileAccess.Read); byte[] treeHashZipFile = ComputeSHA256TreeHash(outputFileStream); String sha256TreeHashZipFile = BitConverter.ToString(treeHashZipFile).Replace("-", "").ToLower(); TarEntry entry = TarEntry.CreateEntryFromFile(fileNameLoc); archive.WriteEntry(entry, true); log.Info("SHA256 Checksum : " + fileNameLoc + " = " + fileChecksum); tarLog.WriteLine(fileName + "," + fileChecksum + "," + shortName + ".z" + "," + sha256TreeHashZipFile); awsDynamoFields.Add("sha256TreeHashUncompressed"); awsDynamoVals.Add(sha256TreeHash); awsDynamoFields.Add("sha256TreeHashCompressed"); awsDynamoVals.Add(sha256TreeHashZipFile); File.Delete(fileNameLoc); } else { String fileNameLoc = sinkDirectory + "\\" + fileName; //For files less than 1MB this is the same as the simple checksum. FileStream inputFile = File.Open(fileNameLoc, FileMode.Open, FileAccess.Read); byte[] treeHash = ComputeSHA256TreeHash(inputFile); sha256TreeHash = BitConverter.ToString(treeHash).Replace("-", "").ToLower(); TarEntry entry = TarEntry.CreateEntryFromFile(fileNameLoc); archive.WriteEntry(entry, true); awsDynamoFields.Add("sha256TreeHashUncompressed"); awsDynamoVals.Add(sha256TreeHash); tarLog.WriteLine(fileNameLoc + "," + sha256TreeHash + "," + fileName + "," + "NoCompression"); log.Info("SHA256 Checksum : " + fileNameLoc + " = " + sha256TreeHash); File.Delete(fileNameLoc); } } catch (Exception ex) { log.Error(ex.ToString()); throw ex; } }