コード例 #1
0
ファイル: BaseFixturePackaging.cs プロジェクト: peters/snapx
        public SnapReleaseBuilder AddNuspecItem([NotNull] SnapReleaseBuilder releaseBuilder, int index)
        {
            if (releaseBuilder == null)
            {
                throw new ArgumentNullException(nameof(releaseBuilder));
            }
            var kv = releaseBuilder._nuspec.ElementAt(index);

            _nuspec.Add(kv.Key, kv.Value);
            return(this);
        }
コード例 #2
0
ファイル: BaseFixturePackaging.cs プロジェクト: peters/snapx
        internal async Task <BuildPackageContext> BuildPackageAsync([NotNull] SnapReleaseBuilder releaseBuilder, CancellationToken cancellationToken = default)
        {
            if (releaseBuilder == null)
            {
                throw new ArgumentNullException(nameof(releaseBuilder));
            }

            var(coreRunMemoryStream, _, _) =
                releaseBuilder.SnapEmbeddedResources.GetCoreRunForSnapApp(releaseBuilder.SnapApp, releaseBuilder.SnapFilesystem, releaseBuilder.CoreRunLib);
            coreRunMemoryStream.Dispose();

            var nuspecBaseDirectory = releaseBuilder.SnapFilesystem.PathCombine(releaseBuilder.NugetPackagingDirectory, "content");

            releaseBuilder.SnapFilesystem.DirectoryCreate(nuspecBaseDirectory);

            var snapPackDetails = new SnapPackageDetails
            {
                NuspecBaseDirectory = nuspecBaseDirectory,
                PackagesDirectory   = releaseBuilder.SnapAppPackagesDirectory,
                SnapApp             = releaseBuilder.SnapApp,
                SnapAppsReleases    = releaseBuilder.SnapAppsReleases
            };

            foreach (var kv in releaseBuilder.GetNuspecItems())
            {
                var targetPath           = kv.Key;
                var value                = kv.Value;
                var destinationFilename  = releaseBuilder.SnapFilesystem.PathCombine(snapPackDetails.NuspecBaseDirectory, targetPath);
                var destinationDirectory = releaseBuilder.SnapFilesystem.PathGetDirectoryName(destinationFilename);
                releaseBuilder.SnapFilesystem.DirectoryCreateIfNotExists(destinationDirectory);

                switch (value)
                {
                case AssemblyDefinition assemblyDefinition:
                    assemblyDefinition.Write(destinationFilename);
                    break;

                case MemoryStream memoryStream:
                    await releaseBuilder.SnapFilesystem.FileWriteAsync(memoryStream, destinationFilename, cancellationToken);

                    memoryStream.Seek(0, SeekOrigin.Begin);
                    break;

                default:
                    throw new NotSupportedException($"{targetPath}: {value?.GetType().FullName}");
                }
            }

            var(fullPackageMemoryStream, fullSnapApp, fullPackageSnapRelease, deltaPackageMemoryStream, deltaSnapApp, deltaSnapRelease) = await releaseBuilder.SnapPack
                                                                                                                                          .BuildPackageAsync(snapPackDetails, releaseBuilder.CoreRunLib, cancellationToken);

            var fullPackageAbsolutePath = await releaseBuilder.WritePackageAsync(fullPackageMemoryStream, fullPackageSnapRelease, cancellationToken);

            string deltaPackageAbsolutePath = null;

            if (deltaSnapApp != null &&
                deltaPackageMemoryStream != null &&
                deltaSnapRelease != null)
            {
                deltaPackageAbsolutePath = await releaseBuilder.WritePackageAsync(deltaPackageMemoryStream, deltaSnapRelease, cancellationToken);
            }

            return(new BuildPackageContext
            {
                FullPackageMemoryStream = fullPackageMemoryStream,
                FullPackageSnapApp = fullSnapApp,
                FullPackageSnapRelease = fullPackageSnapRelease,
                FullPackageAbsolutePath = fullPackageAbsolutePath,
                DeltaPackageMemoryStream = deltaPackageMemoryStream,
                DeltaPackageSnapApp = deltaSnapApp,
                DeltaPackageSnapRelease = deltaSnapRelease,
                DeltaPackageAbsolutePath = deltaPackageAbsolutePath
            });
        }