Save() публичный Метод

public Save ( Stream stream ) : void
stream Stream
Результат void
Пример #1
0
        public override void AddPackage(IPackage package)
        {
            // Starting from 2.1, we save the nuspec file into the subdirectory with the name as <packageId>.<version>
            // for example, for jQuery version 1.0, it will be "jQuery.1.0\\jQuery.1.0.nuspec"
            string   packageFilePath = GetManifestFilePath(package);
            Manifest manifest        = Manifest.Create(package);

            // The IPackage object doesn't carry the References information.
            // Thus we set the References for the manifest to the set of all valid assembly references

            manifest.Metadata.References = package.AssemblyReferences
                                           .Select(p => new ManifestReference()
            {
                File = p.Name
            })
                                           .Distinct()
                                           .ToList();

            FileSystem.AddFileWithCheck(packageFilePath, stream => manifest.Save(stream));

            // But in order to maintain backwards compatibility with older versions of NuGet,
            // we will save the .nupkg file too. This way, 2.1 will read the .nuspec file, and
            // pre 2.1 will read the .nupkg
            base.AddPackage(package);
        }
Пример #2
0
        private void WriteManifest(ZipArchive package, int minimumManifestVersion)
        {
            string path = Id + Constants.ManifestExtension;

            WriteOpcManifestRelationship(package, path);

            ZipArchiveEntry entry = package.CreateEntry(path, CompressionLevel.Optimal);

            using (Stream stream = entry.Open())
            {
                Manifest manifest = Manifest.Create(this);
                manifest.Save(stream, minimumManifestVersion);
            }
        }
Пример #3
0
        public void Save()
        {
            var id = "TestId";
            var version = new SemanticVersion("0.1.0");
            var authors = new string[] { "Alice", "Bob" };

            var manifest = new Manifest(new ManifestMetadata
            {
                Id = id,
                Version = version,
                Authors = authors
            });

            using (var mem = new MemoryStream())
            {
                manifest.Save(mem);

                mem.Position = 0;
                var xdoc = XDocument.Load(mem);
                var ns = xdoc.Root.GetDefaultNamespace();

                var xElemPackage = xdoc.Root;
                Assert.Equal("package", xElemPackage.Name.LocalName);
                Assert.Equal(1, xElemPackage.Elements().Count());

                var xElemMetadata = xElemPackage.Elements().Single();
                Assert.Equal("metadata", xElemMetadata.Name.LocalName);
                Assert.Equal(5, xElemMetadata.Elements().Count());

                var xElemId = xElemMetadata.Element(ns + "id");
                Assert.NotNull(xElemId);
                Assert.Equal(id, xElemId.Value);

                var xElemVersion = xElemMetadata.Element(ns + "version");
                Assert.NotNull(xElemVersion);
                Assert.Equal(version.ToString(), xElemVersion.Value);

                var xElemRequireLicense = xElemMetadata.Element(ns + "requireLicenseAcceptance");
                Assert.NotNull(xElemRequireLicense);
                Assert.Equal("false", xElemRequireLicense.Value);

                var xElemAuthors = xElemMetadata.Element(ns + "authors");
                Assert.NotNull(xElemAuthors);
                Assert.Equal(string.Join(",", authors), xElemAuthors.Value);

                var xElemOwners = xElemMetadata.Element(ns + "owners");
                Assert.NotNull(xElemOwners);
                Assert.Equal(string.Join(",", authors), xElemOwners.Value);
            }
        }
Пример #4
0
        private void WriteManifest(Package package)
        {
            Uri uri = UriUtility.CreatePartUri(Id + Constants.ManifestExtension);

            // Create the manifest relationship
            package.CreateRelationship(uri, TargetMode.Internal, Constants.SchemaNamespace + ManifestRelationType);

            // Create the part
            PackagePart packagePart = package.CreatePart(uri, DefaultContentType, CompressionOption.Maximum);

            using (Stream stream = packagePart.GetStream()) {
                Manifest manifest = Manifest.Create(this);
                manifest.Save(stream);
            }
        }
Пример #5
0
        private void WriteManifest(System.IO.Packaging.Package package, int minimumManifestVersion)
        {
            Uri uri = UriUtility.CreatePartUri(Id + Constants.ManifestExtension);

            // Create the manifest relationship
            package.CreateRelationship(uri, System.IO.Packaging.TargetMode.Internal, Constants.PackageRelationshipNamespace + ManifestRelationType);

            // Create the part
            var packagePart = package.CreatePart(uri, DefaultContentType, System.IO.Packaging.CompressionOption.Maximum);

            using (Stream stream = packagePart.GetStream())
            {
                Manifest manifest = Manifest.Create(this);
                manifest.Save(stream, minimumManifestVersion);
            }
        }
        private void WriteManifest(Package package, int minimumManifestVersion)
        {
            Uri uri = UriUtility.CreatePartUri(Id + Constants.ManifestExtension);

            // Create the manifest relationship
            package.CreateRelationship(uri, TargetMode.Internal,
                                       Constants.PackageRelationshipNamespace + ManifestRelationType);

            // Create the part
            PackagePart packagePart = package.CreatePart(uri, DefaultContentType, CompressionOption.Maximum);

            using (Stream stream = packagePart.GetStream())
            {
                Manifest manifest = Manifest.Create(this);
                //if (PackageAssemblyReferences.Any())
                //{
                //    manifest.Metadata.References = new List<ManifestReference>(
                //        PackageAssemblyReferences.Select(reference => new ManifestReference {File = reference.File}));
                //}
                manifest.Save(stream, minimumManifestVersion);
            }
        }
Пример #7
0
        /// <summary>
        /// Exports the page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="isRecursive">if set to <c>true</c> [should export children].</param>
        /// <returns>a <see cref="T:System.IO.MemoryStream"/> of the exported page package.</returns>
        public MemoryStream ExportPage( Page page, bool isRecursive )
        {
            // Create a temp directory to hold package contents in staging area
            string packageId = Guid.NewGuid().ToString();
            var packageDirectory = CreatePackageDirectory( page.InternalName, packageId );
            var webRootPath = HttpContext.Current.Server.MapPath( "~" );

            // Create a manifest for this page export...
            Manifest manifest = new Manifest();
            manifest.Metadata = new ManifestMetadata();
            manifest.Metadata.Authors = "PageExport";
            manifest.Metadata.Version = "0.0";
            manifest.Metadata.Id = packageId;
            manifest.Metadata.Description = ( string.IsNullOrEmpty( page.Description ) ) ? "a page export" : page.Description;
            manifest.Files = new List<ManifestFile>();

            // Generate the JSON from model data and write it to disk, then add it to the manifest
            var json = GetJson( page, isRecursive );
            using ( var file = new StreamWriter( Path.Combine( packageDirectory.FullName, "export.json" ) ) )
            {
                file.Write( json );
            }
            AddToManifest( manifest, packageDirectory.FullName, webRootPath, "export.json", SearchOption.TopDirectoryOnly );

            // * Find out from `page` which Blocks need to be packaged up (recursively if ExportChildren box is checked)
            // * Grab asset folders for each Block's code file uniquely (Scripts, Assets, CSS folders)
            // * Add them to the package manifest
            var blockTypes = new Dictionary<Guid, BlockType>();
            var uniqueDirectories = new Dictionary<string, string>();
            FindUniqueBlockTypesAndDirectories( page, isRecursive, blockTypes, uniqueDirectories );

            foreach ( var blockType in blockTypes.Values )
            {
                var sourcePath = HttpContext.Current.Server.MapPath( blockType.Path );
                var directory = sourcePath.Substring( 0, sourcePath.LastIndexOf( Path.DirectorySeparatorChar ) );
                var fileName = Path.GetFileNameWithoutExtension( sourcePath );
                var pattern = string.Format( "{0}.*", fileName );
                AddToManifest( manifest, directory, webRootPath, pattern, SearchOption.TopDirectoryOnly );
            }

            // Second pass through blocks. Determine which folders (by convention) need to be added
            // to the package manifest.
            foreach ( var dir in uniqueDirectories.Keys )
            {
                var sourcePath = HttpContext.Current.Server.MapPath( dir );
                // Are there any folders present named "CSS", "Scripts" or "Assets"?
                AddToManifest( manifest, Path.Combine( sourcePath, "CSS" ), webRootPath );
                AddToManifest( manifest, Path.Combine( sourcePath, "Scripts" ), webRootPath );
                AddToManifest( manifest, Path.Combine( sourcePath, "Assets" ), webRootPath );
            }

            // Save the manifest as "pageexport.nuspec" in the temp folder
            string basePath = packageDirectory.FullName;
            string manifestPath = Path.Combine( basePath, "pageexport.nuspec" );
            using ( Stream fileStream = File.Create( manifestPath ) )
            {
                manifest.Save( fileStream );
            }

            // Create a NuGet package from the manifest and 'save' it to a memory stream for the consumer...
            // BTW - don't use anything older than nuget 2.1 due to Manifest bug (http://nuget.codeplex.com/workitem/2813)
            // which will cause the PackageBuilder constructor to fail due to <Files> vs <files> being in the manifest.
            PackageBuilder packageBuilder = new PackageBuilder( manifestPath, basePath, NullPropertyProvider.Instance, false );

            var outputStream = new MemoryStream();
            packageBuilder.Save( outputStream );

            // Clean up staging area
            packageDirectory.Delete( recursive: true );
            return outputStream;
        }
Пример #8
0
        private bool IsDifferent(Manifest newManifest)
        {
            if (!File.Exists(OutputFileName))
                return true;

            var oldSource = File.ReadAllText(OutputFileName);
            var newSource = "";
            using (var stream = new MemoryStream())
            {
                newManifest.Save(stream);
                stream.Seek(0, SeekOrigin.Begin);
                newSource = Encoding.UTF8.GetString(stream.ToArray());
            }

            return oldSource != newSource;
        }
Пример #9
0
        public static string CreateManifest(List<ManifestFile> manifestFiles, string releaseNotes)
        {
            var manifest = new Manifest
            {
                Metadata = new ManifestMetadata
                {
                    Id = Options.NuspecId,
                    Version = "0.0.0", //overloaded by nuget pack cmd line parameters
                    Authors = "Sitecore NuGetPack Runner",
                    Description = string.Format("Sitecore NuGet Package, built on {0}", DateTime.Now.ToString("HH:mm dd/MM/yyyy")),
                    ReleaseNotes = releaseNotes
                },
                Files = manifestFiles
            };

            var manifestFilePath = Path.Combine(Options.TargetDir, Options.NuspecId + NuspecExt);
            using (var fsManifest = new FileStream(manifestFilePath, FileMode.Create))
            {
                manifest.Save(fsManifest, true);
            }
            return manifestFilePath;
        }
Пример #10
0
        private static Version SetPackageVersion(Options options, Manifest m)
        {
            Version v2;
            if (options.Version != null)
            {
                if (options.Version.StartsWith("+"))
                {
                    Version v = Version.Parse(m.Metadata.Version);
                    Version vinc = Version.Parse(options.Version.Substring(1));
                    v2 = new Version(v.Major + vinc.Major, v.Minor + vinc.Minor, v.Build + vinc.Build, 0);
                }
                else
                {
                    v2 = Version.Parse(options.Version);
                }
            }
            else
            {

                Assembly asm = FindAssembly(options, m);
                v2 = asm.GetName().Version;
            }

            m.Metadata.Version = v2.ToString();
            using (FileStream fileStream = File.Open(options.NuSpec, FileMode.Truncate))
                m.Save(fileStream, true);
            return v2;
        }