Beispiel #1
0
 public IEnumerable <IShape> Load(Stream stream)
 {
     using (var unwrappedStream = wrapper_.Unwrap(stream))
     {
         return(loader_.Load(unwrappedStream));
     }
 }
Beispiel #2
0
 private ICollection <IShape> LoadShapesFromStream(IShapeLoader shapeLoader, Stream stream)
 {
     try
     {
         return(shapeLoader.Load(stream).ToList());
     }
     catch (Exception ex)
     {
         errorLabel.Text = ex.Message;
         return(null);
     }
 }
 public IEnumerable <IShape> Load(Stream stream)
 {
     using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true))
     {
         var entry = archive.Entries.FirstOrDefault();
         if (entry == null)
         {
             throw new ArgumentException("The package is invalid");
         }
         using (Stream zipStream = entry.Open())
         {
             return(loader_.Load(zipStream));
         }
     }
 }
        public IEnumerable <IShape> Load(Stream stream)
        {
            var hash = new byte[hash_.ByteLength];

            stream.Read(hash, 0, hash.Length);
            using (var memoryStream = new MemoryStream())
            {
                // TODO?: reset position in memoryStream
                stream.CopyTo(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                var actualHash = hash_.Compute(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                if (!AreHashesEqual(hash, actualHash))
                {
                    throw new ArgumentException("The file is corrupted.");
                }
                return(loader_.Load(memoryStream));
            }
        }