Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / Application / StreamProxy.cs / 1 / StreamProxy.cs
//------------------------------------------------------------------------------ //// Copyright (C) Microsoft Corporation. All rights reserved. // //// Implements the Proxy pattern from Design Patterns for Stream. The intended // usage is to control access to the Stream; specifically to allow one to // replace the underlying stream. The StreamProxy can also ensure, if // desired, that the underlying stream is readonly. // // // History: // 08/28/2005: [....]: Initial implementation. //----------------------------------------------------------------------------- using System; using System.IO; using System.Security; using System.Windows.TrustUI; namespace MS.Internal.Documents.Application { ////// Implements the Proxy pattern from Design Patterns for Stream. The intended /// usage is to control access to the Stream; specifically to allow one to /// replace the underlying stream. The StreamProxy can also ensure, if /// desired, that the underlying stream is readonly. /// internal class StreamProxy : Stream { #region Constructors //------------------------------------------------------------------------- // Constructors //------------------------------------------------------------------------- ////// Will construct a StreamProxy backed by the specified stream and leave /// the target modifiable. /// /// The stream that is backing the proxy. /// internal StreamProxy(Stream targetOfProxy) : this(targetOfProxy, false) { } ////// Will construct a StreamProxy backed by the specified stream and make /// the target read-only if so specified. /// /// The stream that is backing the proxy. /// /// Whether or not the target should be set /// to read-only. ////// Critical /// 1) Setting critical for set values _proxy & _isTargetReadOnly. /// TreatAsSafe /// 1) We only want to ensure that the user cannot circumvent using either /// the constructor or the Target property to set the proxy. Creating /// the StreamProxy itself is a safe operation. /// [SecurityCritical, SecurityTreatAsSafe] internal StreamProxy(Stream targetOfProxy, bool isTargetReadOnly) { _proxy.Value = targetOfProxy; _isTargetReadOnly.Value = isTargetReadOnly; } #endregion Constructors #region Stream Overrides //-------------------------------------------------------------------------- // Stream Overrides //------------------------------------------------------------------------- ////// public override bool CanRead { get { return _proxy.Value.CanRead; } } ////// /// public override bool CanSeek { get { return _proxy.Value.CanSeek; } } ////// /// public override bool CanTimeout { get { return _proxy.Value.CanTimeout; } } ////// /// public override bool CanWrite { get { return _proxy.Value.CanWrite; } } ////// /// public override void Close() { _proxy.Value.Close(); } ////// /// public override void Flush() { _proxy.Value.Flush(); } ////// /// public override long Length { get { return _proxy.Value.Length; } } ////// /// public override long Position { get { return _proxy.Value.Position; } set { _proxy.Value.Position = value; } } ////// /// public override int Read(byte[] buffer, int offset, int count) { return _proxy.Value.Read(buffer, offset, count); } ////// /// public override int ReadTimeout { get { return _proxy.Value.ReadTimeout; } set { _proxy.Value.ReadTimeout = value; } } ////// /// public override long Seek(long offset, SeekOrigin origin) { return _proxy.Value.Seek(offset, origin); } ////// /// public override void SetLength(long value) { _proxy.Value.SetLength(value); } ////// /// public override void Write(byte[] buffer, int offset, int count) { _proxy.Value.Write(buffer, offset, count); } ////// /// public override int WriteTimeout { get { return _proxy.Value.WriteTimeout; } set { _proxy.Value.WriteTimeout = value; } } ////// /// ////// /// Critical /// 1) Setting critical for set value _proxy. /// TreatAsSafe /// 1) Setting to known safe value null. /// [SecurityCritical, SecurityTreatAsSafe] protected override void Dispose(bool disposing) { try { // other operations like async methods in // our base class call us, we need them to // clean up before we release the proxy base.Dispose(disposing); } finally { if (disposing && _proxy.Value != null) { _proxy.Value.Dispose(); _proxy.Value = null; } } } #endregion Stream Overrides #region Object Overrides //-------------------------------------------------------------------------- // Object Overrides //-------------------------------------------------------------------------- ////// public override int GetHashCode() { return _proxy.Value.GetHashCode(); } ////// /// public override bool Equals(object obj) { return _proxy.Value.Equals(obj); } #endregion Object Overrides #region Internal Properties //------------------------------------------------------------------------- // Internal Properties //-------------------------------------------------------------------------- ////// /// Critical /// 1) Setting critical for set value _proxy. /// TreatAsSafe /// 1) It is safe to set the value as long as the StreamProxy was not /// created read-only. /// internal Stream Target { get { return _proxy.Value; } [SecurityCritical, SecurityTreatAsSafe] set { if (!_isTargetReadOnly.Value) { _proxy.Value = value; } else { throw new InvalidOperationException( SR.Get(SRID.FileManagementStreamProxyIsReadOnly)); } } } #endregion Internal Properties #region Private Fields //------------------------------------------------------------------------- // Private Fields //------------------------------------------------------------------------- SecurityCriticalDataForSet_proxy; SecurityCriticalDataForSet _isTargetReadOnly; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ZoneIdentityPermission.cs
- BidirectionalDictionary.cs
- HierarchicalDataBoundControlAdapter.cs
- DataConnectionHelper.cs
- ReachIDocumentPaginatorSerializer.cs
- KeyTime.cs
- TryExpression.cs
- HasCopySemanticsAttribute.cs
- ThemeDictionaryExtension.cs
- Int32Collection.cs
- SmiConnection.cs
- CodeSnippetCompileUnit.cs
- NotCondition.cs
- CursorConverter.cs
- TypeTypeConverter.cs
- EventSchemaTraceListener.cs
- LinearGradientBrush.cs
- DashStyle.cs
- WindowsTitleBar.cs
- IFlowDocumentViewer.cs
- ErrorRuntimeConfig.cs
- FixedTextView.cs
- ToolBarTray.cs
- ServiceManagerHandle.cs
- PointAnimation.cs
- TimeEnumHelper.cs
- SplayTreeNode.cs
- Tokenizer.cs
- ExpiredSecurityTokenException.cs
- KeyValueSerializer.cs
- Bezier.cs
- ExpressionConverter.cs
- NameTable.cs
- Literal.cs
- TextDecorationCollection.cs
- CodeTypeOfExpression.cs
- CodeDomLoader.cs
- MenuCommandsChangedEventArgs.cs
- LicFileLicenseProvider.cs
- CreateUserWizardStep.cs
- VariableBinder.cs
- NativeObjectSecurity.cs
- RecordBuilder.cs
- Pens.cs
- Config.cs
- TextEffectResolver.cs
- RootBrowserWindowProxy.cs
- DirectoryObjectSecurity.cs
- objectresult_tresulttype.cs
- TemplateParser.cs
- QuotedPrintableStream.cs
- ProjectionCamera.cs
- QueryCacheKey.cs
- PropertyCollection.cs
- PackageProperties.cs
- MsmqIntegrationBindingElement.cs
- CreateRefExpr.cs
- OracleSqlParser.cs
- SqlConnectionManager.cs
- X509ChainElement.cs
- XPathSingletonIterator.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- GeneralTransform3DTo2D.cs
- ConfigurationLoader.cs
- ExpandableObjectConverter.cs
- CheckBoxPopupAdapter.cs
- ObjectHelper.cs
- TokenizerHelper.cs
- DaylightTime.cs
- SvcMapFileLoader.cs
- ByteStreamMessageEncoderFactory.cs
- UrlPropertyAttribute.cs
- ExtenderProvidedPropertyAttribute.cs
- DesignerForm.cs
- SqlServer2KCompatibilityCheck.cs
- PingReply.cs
- UInt64.cs
- LiteralControl.cs
- PasswordRecovery.cs
- objectquery_tresulttype.cs
- TemplateBuilder.cs
- BaseWebProxyFinder.cs
- TypeDescriptorContext.cs
- FixedPage.cs
- SymbolEqualComparer.cs
- BrowserDefinitionCollection.cs
- TreeViewAutomationPeer.cs
- VectorValueSerializer.cs
- ProxySimple.cs
- RevocationPoint.cs
- User.cs
- XDRSchema.cs
- DynamicAttribute.cs
- StylesEditorDialog.cs
- TreeNodeBinding.cs
- EntityDesignerBuildProvider.cs
- WindowsUserNameCachingSecurityTokenAuthenticator.cs
- TypeListConverter.cs
- TreeNodeStyleCollection.cs
- MarshalDirectiveException.cs