Ejemplo n.º 1
0
        public void OnStreamClosed()
        {
            EnsureNotDisposed();

            // do not allow to process twice
            if (isClosed)
            {
                return;
            }

            // compute hash of last part
            ComputeCurrentPartHash();

            // trim last data file
            if (currentPart != null)
            {
                long lastDataFileLength = currentPart.FileStream.Position;
                currentPart.FileStream.SetLength(lastDataFileLength);
            }

            // dispose all
            DisposeCurrentPart();

            // build result
            var sequenceInfo = new PackageSequenceInfo(sequenceBaseInfo, totalSize);

            packageId = new Dto.PackageHashes(version, segmentHashes, cryptoProvider, sequenceInfo);
            logger.LogDebug($"Closed package data files. Written {SizeFormatter.ToString(totalSize)}. Hash is {packageId.PackageId:s}.");
            isClosed = true;
        }
Ejemplo n.º 2
0
        /// <param name="nestedStream">Can be null if you just want to validate hashes.</param>
        public ValidatePackageDataStreamController(ILoggerFactory loggerFactory, CryptoProvider cryptoProvider, PackageSequenceBaseInfo sequenceBaseInfo, Dto.PackageHashes hashes, IEnumerable <PackageDataStreamPart> partsToValidate, Stream nestedStream)
        {
            logger = (loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory))).CreateLogger <WritePackageDataStreamController>();
            this.cryptoProvider   = cryptoProvider ?? throw new ArgumentNullException(nameof(cryptoProvider));
            this.sequenceBaseInfo = sequenceBaseInfo ?? throw new ArgumentNullException(nameof(sequenceBaseInfo));
            this.hashes           = hashes ?? throw new ArgumentNullException(nameof(hashes));
            parts  = (partsToValidate ?? throw new ArgumentNullException(nameof(partsToValidate))).ToArray();
            Length = parts.Sum(p => p.PartLength);

            // where to write validated data?
            this.nestedStream   = nestedStream;
            writeToNestedStream = nestedStream != null;
            if (writeToNestedStream)
            {
                memStream = new MemoryStream(capacity: (int)sequenceBaseInfo.SegmentLength);
            }
        }
Ejemplo n.º 3
0
 public LocalPackageInfo(PackageReference reference, PackageDownloadInfo downloadStatus, Dto.PackageHashes hashes, Dto.PackageMeta metadata, PackageSequenceInfo sequence)
 {
     LockProvider    = new PackageLocks();
     DownloadMeasure = new MeasureItem(MeasureType.Throughput);
     UploadMeasure   = new MeasureItem(MeasureType.Throughput);
     Reference       = reference ?? throw new ArgumentNullException(nameof(reference));
     DownloadStatus  = downloadStatus ?? throw new ArgumentNullException(nameof(downloadStatus));
     Hashes          = hashes ?? throw new ArgumentNullException(nameof(hashes));
     Metadata        = metadata ?? throw new ArgumentNullException(nameof(metadata));
     Sequence        = sequence ?? throw new ArgumentNullException(nameof(sequence));
     if (!Reference.Id.Equals(DownloadStatus.PackageId))
     {
         throw new ArgumentException("Invalid hash.", nameof(downloadStatus));
     }
     if (!Reference.Id.Equals(Hashes.PackageId))
     {
         throw new ArgumentException("Invalid hash.", nameof(hashes));
     }
     if (!Reference.Id.Equals(Metadata.PackageId))
     {
         throw new ArgumentException("Invalid hash.", nameof(metadata));
     }
     if (!Metadata.PackageSize.Equals(Sequence.PackageSize))
     {
         throw new ArgumentException("Invalid size of package sequence.", nameof(sequence));
     }
 }
Ejemplo n.º 4
0
        private void UpdateHashes(Dto.PackageHashes hashes, string directoryPath = null)
        {
            string path = Path.Combine(directoryPath ?? CreatePackagePath(hashes.PackageId), PackageHashesFileName);

            File.WriteAllBytes(path, app.MessageSerializer.Serialize(hashes));
        }