예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UniversalPackage"/> class.
        /// </summary>
        /// <param name="stream">Stream backed by the universal package. If this stream does not support seeking, a copy will be made.</param>
        /// <param name="leaveOpen">Value indicating whether to leave the underlying stream open when the instance is disposed. The default is false.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception>
        /// <exception cref="InvalidDataException">The stream does not contain a valid universal package.</exception>
        public UniversalPackage(Stream stream, bool leaveOpen)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanSeek)
            {
                var tempStream = new FileStream(Path.GetTempFileName(), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose);
                stream.CopyTo(tempStream);
                if (!leaveOpen)
                {
                    stream.Dispose();
                }

                tempStream.Position = 0;
                this.zip            = new ZipArchive(tempStream, ZipArchiveMode.Read, false);
            }
            else
            {
                this.zip = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen);
            }

            this.Entries  = new EntryCollection(this);
            this.metadata = this.ReadMetadata();
        }
        private void WriteMetadata(UniversalPackageMetadata metadata)
        {
            var entry = this.zip.CreateEntry("upack.json");

            using (var entryStream = entry.Open())
                using (var writer = new StreamWriter(entryStream, new UTF8Encoding(false)))
                    using (var jsonWriter = new JsonTextWriter(writer)
                    {
                        Formatting = Formatting.Indented
                    })
                    {
                        metadata.WriteJson(jsonWriter);
                    }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UniversalPackageBuilder"/> class.
        /// </summary>
        /// <param name="stream">Stream to write package to.</param>
        /// <param name="metadata">Metadata to write as the upack.json file.</param>
        /// <param name="leaveOpen">Value indicating whether to leave the underlying stream open when the instance is disposed. The default is false.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="metadata"/> is null.</exception>
        public UniversalPackageBuilder(Stream stream, UniversalPackageMetadata metadata, bool leaveOpen)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            try
            {
                this.zip = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen);
                this.WriteMetadata(metadata);
            }
            catch
            {
                this.zip?.Dispose();
                throw;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UniversalPackageBuilder"/> class.
 /// </summary>
 /// <param name="fileName">Full path of the .upack file to create.</param>
 /// <param name="metadata">Metadata to write as the upack.json file.</param>
 /// <exception cref="ArgumentNullException"><paramref name="fileName"/> is null or empty or <paramref name="metadata"/> is null.</exception>
 public UniversalPackageBuilder(string fileName, UniversalPackageMetadata metadata)
     : this(CreateFile(fileName), metadata)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UniversalPackageBuilder"/> class.
 /// </summary>
 /// <param name="stream">Stream to write package to.</param>
 /// <param name="metadata">Metadata to write as the upack.json file.</param>
 /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null or <paramref name="metadata"/> is null.</exception>
 public UniversalPackageBuilder(Stream stream, UniversalPackageMetadata metadata)
     : this(stream, metadata, false)
 {
 }
예제 #6
0
 private protected WrappedList(UniversalPackageMetadata owner) => this.Owner = owner;
예제 #7
0
 internal RepackageEntryList(UniversalPackageMetadata owner)
     : base(owner)
 {
 }
예제 #8
0
 internal TagList(UniversalPackageMetadata owner)
     : base(owner)
 {
 }
예제 #9
0
 internal DependencyList(UniversalPackageMetadata owner)
     : base(owner)
 {
 }