Exemplo n.º 1
0
 string Hash(string packageFilePath)
 {
     using (var stream = fileSystem.OpenFile(packageFilePath, FileMode.Open))
     {
         return(HashCalculator.Hash(stream));
     }
 }
Exemplo n.º 2
0
        void AddContent(Package package, PackageDefinition manifest, Uri partUri, string file)
        {
            var part =
                package.CreatePart(
                    PackUriHelper.CreatePartUri(partUri), System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);

            using (var partStream = part.GetStream())
                using (var fileStream = fileSystem.OpenFile(file, FileMode.Open))
                {
                    fileStream.CopyTo(partStream);
                    partStream.Flush();
                    fileStream.Position = 0;
                    var hashAlgorithm = new SHA256Managed();
                    hashAlgorithm.ComputeHash(fileStream);
                    manifest.Contents.Add(new ContentDefinition
                    {
                        Name        = partUri.ToString(),
                        Description =
                            new ContentDescription
                        {
                            DataStorePath = partUri,
                            LengthInBytes = (int)fileStream.Length,
                            HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256,
                            Hash          = Convert.ToBase64String(hashAlgorithm.Hash)
                        }
                    });
                }
        }
Exemplo n.º 3
0
        private IEnumerable <XElement> Read()
        {
            if (!fileSystem.FileExists(JournalPath))
            {
                yield break;
            }

            using (var file = fileSystem.OpenFile(JournalPath, FileAccess.Read))
            {
                var document = XDocument.Load(file);

                foreach (var element in document.Element("Deployments").Elements())
                {
                    yield return(element);
                }
            }
        }
Exemplo n.º 4
0
        public void DownloadPackage(
            string packageId,
            IVersion version,
            string feedId,
            Uri feedUri,
            ICredentials feedCredentials,
            bool forcePackageDownload,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff,
            out string downloadedTo,
            out string hash,
            out long size)
        {
            var cacheDirectory = PackageDownloaderUtils.GetPackageRoot(feedId);

            downloadedTo = null;
            if (!forcePackageDownload)
            {
                Log.Info("Attempting to get from cache");
                try
                {
                    downloadedTo = SourceFromCache(
                        packageId,
                        version,
                        cacheDirectory);
                }
                catch (Exception ex)
                {
                    Log.Info("SourceFromCache() failed");
                    Log.Info("Exception starts");
                    Log.Info(ex.ToString());
                    Log.Info(ex.StackTrace);
                    Log.Info("Exception ends");
                }
            }

            if (downloadedTo == null)
            {
                downloadedTo = DownloadPackage(
                    packageId,
                    version,
                    feedUri,
                    feedCredentials,
                    cacheDirectory,
                    maxDownloadAttempts,
                    downloadAttemptBackoff);
            }
            else
            {
                Log.VerboseFormat("Package was found in cache. No need to download. Using file: '{0}'", downloadedTo);
            }

            size = fileSystem.GetFileSize(downloadedTo);
            hash = downloadedTo
                   .Map(path => FunctionalExtensions.Using(
                            () => fileSystem.OpenFile(path, FileAccess.Read),
                            stream => HashCalculator.Hash(stream)));
        }
Exemplo n.º 5
0
        void ExtractPart(PackagePart part, string destinationPath)
        {
            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(destinationPath));

            using (var packageFileStream = part.GetStream())
                using (var destinationFileStream = fileSystem.OpenFile(destinationPath, FileMode.Create))
                {
                    packageFileStream.CopyTo(destinationFileStream);
                    destinationFileStream.Flush();
                }
        }
Exemplo n.º 6
0
        void ConvertPackage(string packagePath)
        {
            string newPackagePath = Path.Combine(Path.GetDirectoryName(packagePath), Path.GetFileNameWithoutExtension(packagePath) + "_new.cspkg");

            using (var packageStore = new OpcPackageStore(newPackagePath, FileMode.CreateNew, FileAccess.ReadWrite))
                using (var fileStream = fileSystem.OpenFile(packagePath, FileMode.Open))
                {
                    PackageConverter.ConvertFromLegacy(fileStream, packageStore);
                }

            fileSystem.OverwriteAndDelete(packagePath, newPackagePath);
        }
        public void ShouldUploadPackage()
        {
            const string packageFileName = "Acme.cspkg";
            var          packageFilePath = Path.Combine(stagingDirectory, packageFileName);

            variables.Set(SpecialVariables.Package.NuGetPackageVersion, "1.0.0");
            variables.Set(SpecialVariables.Action.Azure.CloudServicePackagePath, packageFilePath);
            fileSystem.EnumerateFiles(stagingDirectory, "*.cspkg")
            .Returns(new[] { packageFilePath });
            fileSystem.OpenFile(packageFilePath, Arg.Any <FileMode>())
            .Returns(new MemoryStream(Encoding.UTF8.GetBytes("blah blah blah")));

            var uploadedUri = new Uri("http://azure.com/wherever/my-package.cspkg");

            packageUploader.Upload(
                Arg.Is <SubscriptionCloudCredentials>(cred => cred.SubscriptionId == azureSubscriptionId),
                storageAccountName, packageFilePath, Arg.Any <string>())
            .Returns(uploadedUri);

            convention.Install(deployment);

            Assert.AreEqual(uploadedUri.ToString(), variables.Get(SpecialVariables.Action.Azure.UploadedPackageUri));
        }