void IPersistStream.Load(MS.Internal.Interop.IStream stream) { // Check argument. if (stream == null) { throw new ArgumentNullException("stream"); } // Only one of _package and _encryptedPackage can be non-null at a time. Invariant.Assert(_package == null || _encryptedPackage == null); // If there has been a previous call to Load, reinitialize everything. // Note closing a closed stream does not cause any exception. ReleaseResources(); _filter = null; _xpsFileName = null; try { _packageStream = new UnsafeIndexingFilterStream(stream); // different filter for encrypted package if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(_packageStream)) { // Open the encrypted package. _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream); _filter = new EncryptedPackageFilter(_encryptedPackage); } else { // Open the package. _package = Package.Open(_packageStream); _filter = new PackageFilter(_package); } } catch (IOException ex) { throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS); } catch (Exception ex) { throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT); } finally { // clean-up if we failed if (_filter == null) { ReleaseResources(); } } }
void IPersistStream.Load(MS.Internal.Interop.IStream stream) { // Check argument. if (stream == null) { throw new ArgumentNullException("stream"); } // Only one of _package and _encryptedPackage can be non-null at a time. Invariant.Assert(_package == null || _encryptedPackage == null); // If there has been a previous call to Load, reinitialize everything. // Note closing a closed stream does not cause any exception. ReleaseResources(); _filter = null; _xpsFileName = null; try { _packageStream = new UnsafeIndexingFilterStream(stream); // different filter for encrypted package if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(_packageStream)) { // Open the encrypted package. _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream); _filter = new EncryptedPackageFilter(_encryptedPackage); } else { // Open the package. _package = Package.Open(_packageStream); _filter = new PackageFilter(_package); } } catch (IOException ex) { throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS); } catch (Exception ex) { throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT); } finally { // clean-up if we failed if (_filter == null) { ReleaseResources(); } } }