Esempio n. 1
0
 /// <summary>
 /// Returns a collection of open streams of a specific type
 /// </summary>
 /// <param name="itemType"></param>
 /// <returns></returns>
 public IEnumerable <Stream> ExtractAll(ZipPackageItemType itemType)
 {
     foreach (var item in this.ItemManifest.Items)
     {
         if (item.Value == itemType)
         {
             yield return(this.Extract(item.Key));
         }
     }
 }
        /// <summary>
        /// Returns collection of items of a package type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<string> GetItemNames(ZipPackageItemType type)
        {
            var items = new List<string>();

            foreach (var item in this.Items)
                if (item.Value == type)
                    items.Add(item.Key);

            return items;
        }
Esempio n. 3
0
        /// <summary>
        /// Returns an open stream of the first instance of the item type
        /// </summary>
        /// <param name="itemType"></param>
        /// <returns></returns>
        public Stream Extract(ZipPackageItemType itemType)
        {
            foreach (var item in this.ItemManifest.Items)
            {
                if (item.Value == itemType)
                {
                    return(this.Extract(item.Key));
                }
            }

            throw new ApplicationException(string.Format("No package items of type \"{0}\" exist in imported file", itemType));
        }
        /// <summary>
        /// Returns collection of items of a package type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <string> GetItemNames(ZipPackageItemType type)
        {
            var items = new List <string>();

            foreach (var item in this.Items)
            {
                if (item.Value == type)
                {
                    items.Add(item.Key);
                }
            }

            return(items);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds an item to Items
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="item"></param>
        /// <param name="itemName"></param>
        /// <returns></returns>
        public void Add(ZipPackageItemType itemType, string itemName, Stream item)
        {
            if (this.TempZipFile)
            {
                throw new ApplicationException("ZipPackage is read-only when reading from temp directory");
            }

            using (var ms = new MemoryStream())
            {
                using (ZipFile zip = this.Items.Length == 0 ? new ZipFile() : ZipFile.Read(this.Items.Reset()))
                {
                    zip.AddEntry(itemName, item.Reset());
                    zip.Save(ms);
                }

                this.Items = new MemoryStream();
                ms.Reset().CopyTo(this.Items);
            }

            this.ItemManifest.Items.Add(new OfflineZipPackageItem <string, ZipPackageItemType>(itemName, itemType));

            this.UpdateItemManifest();
        }
 public bool Exists(ZipPackageItemType type)
 {
     return(this.Items.Any(item => item.Value == type));
 }
Esempio n. 7
0
 /// <summary>
 /// Returns a collection of open streams of a specific type
 /// </summary>
 /// <param name="itemType"></param>
 /// <returns></returns>
 public IEnumerable<Stream> ExtractAll(ZipPackageItemType itemType)
 {
     foreach (var item in this.ItemManifest.Items)
         if (item.Value == itemType)
             yield return this.Extract(item.Key);
 }
Esempio n. 8
0
        /// <summary>
        /// Returns an open stream of the first instance of the item type
        /// </summary>
        /// <param name="itemType"></param>
        /// <returns></returns>
        public Stream Extract(ZipPackageItemType itemType)
        {
            foreach (var item in this.ItemManifest.Items)
                if (item.Value == itemType)
                    return this.Extract(item.Key);

            throw new ApplicationException(string.Format("No package items of type \"{0}\" exist in imported file", itemType));
        }
Esempio n. 9
0
        /// <summary>
        /// Adds an item to Items
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="item"></param>
        /// <param name="itemName"></param>
        /// <returns></returns>
        public void Add(ZipPackageItemType itemType, string itemName, Stream item)
        {
            if (this.TempZipFile)
                throw new ApplicationException("ZipPackage is read-only when reading from temp directory");

            using (var ms = new MemoryStream())
            {
                using (ZipFile zip = this.Items.Length == 0 ? new ZipFile() : ZipFile.Read(this.Items.Reset()))
                {
                    zip.AddEntry(itemName, item.Reset());
                    zip.Save(ms);
                }

                this.Items = new MemoryStream();
                ms.Reset().CopyTo(this.Items);
            }

            this.ItemManifest.Items.Add(new OfflineZipPackageItem<string, ZipPackageItemType>(itemName, itemType));

            this.UpdateItemManifest();
        }
Esempio n. 10
0
 public bool Exists(ZipPackageItemType type)
 {
     return this.Items.Any(item => item.Value == type);
 }