Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / MS / Internal / IO / Packaging / PreloadedPackages.cs / 1 / PreloadedPackages.cs
//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation, 2005 // // File: PreloadedPackages.cs // // Description: Collection of preloaded packages to be used with // PackWebRequest. // //----------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.Collections; using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Packaging; using MS.Internal; using MS.Internal.PresentationCore; // for ExceptionStringTable namespace MS.Internal.IO.Packaging { ////// PreloadedPackages /// ///Note: we purposely didn't make this class a dictionary since it is an internal /// class and we won't be using even half of the dictionary functionalities. /// If this class becomes a public class which is strongly discouraged, this class /// needs to implement IDictionary. //// Critical: This class serves as a depository of all well-known pre-populated // packages. This class is marked as SecurityCritical to ensure that // 1. only trusted code can add/get/remove trusted packages into the depository // 2. a whole package will never be given out to the platform client // Note: it is OK to give out a part stream from a package instance but // the package related objects such as Package, PackagePart, // PackageRelationship should NEVER be given out to a client. // List of the trusted packages allowed: // 1. ResourceContainer // 2. SiteOfOriginContainer // 3. ZipPackage that is only instantiated by XPS Viewer // [SecurityCritical(SecurityCriticalScope.Everything)] [FriendAccessAllowed] internal static class PreloadedPackages { //----------------------------------------------------- // // Static Constructors // //----------------------------------------------------- static PreloadedPackages() { _globalLock = new Object(); } //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods ////// GetPackage given a uri /// /// uri to match on ///object if found - else null ///uri must be absolute internal static Package GetPackage(Uri uri) { bool ignored; return GetPackage(uri, out ignored); } ////// GetPackage given a uri /// /// uri to match on /// true if the returned package is threadsafe - undefined if null is returned ///object if found - else null ///uri must be absolute internal static Package GetPackage(Uri uri, out bool threadSafe) { ValidateUriKey(uri); lock (_globalLock) { Package package = null; threadSafe = false; if (_packagePairs != null) { PackageThreadSafePair packagePair = _packagePairs[uri] as PackageThreadSafePair; if (packagePair != null) { package = packagePair.Package; threadSafe = packagePair.ThreadSafe; } } return package; } } ////// AddPackage - default to non-thread-safe /// /// uri to use for matching /// package object to serve content from ///Adds a uri, content pair to the cache. If the uri is already /// in the cache, this removes the old content and replaces it. /// The object will not be subject to automatic removal from the cache internal static void AddPackage(Uri uri, Package package) { AddPackage(uri, package, false); } ////// AddPackage /// /// uri to use for matching /// package object to serve content from /// is package thread-safe? ///Adds a uri, content pair to the cache. If the uri is already /// in the cache, this removes the old content and replaces it. /// The object will not be subject to automatic removal from the cache internal static void AddPackage(Uri uri, Package package, bool threadSafe) { ValidateUriKey(uri); lock (_globalLock) { if (_packagePairs == null) { _packagePairs = new HybridDictionary(3); } _packagePairs.Add(uri, new PackageThreadSafePair(package, threadSafe)); } } ////// RemovePackage /// /// uri of the package that needs to be removed ///Removes the package corresponding to the uri from the cache. If a matching uri isn't found /// the status of the cache doesn't change and no exception is throwen /// internal static void RemovePackage(Uri uri) { ValidateUriKey(uri); lock (_globalLock) { if (_packagePairs != null) { _packagePairs.Remove(uri); } } } // Null the instance. Similar to Dispose, but not quite. internal static void Clear() { lock (_globalLock) { _packagePairs = null; } } private static void ValidateUriKey(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } if (!uri.IsAbsoluteUri) { throw new ArgumentException(SR.Get(SRID.UriMustBeAbsolute), "uri"); } } #endregion Internal Methods ////// Package-bool pair where the bool represents the thread-safety status of the package /// private class PackageThreadSafePair { //------------------------------------------------------ // // Internal Constructors // //------------------------------------------------------ internal PackageThreadSafePair(Package package, bool threadSafe) { Invariant.Assert(package != null); _package = package; _threadSafe = threadSafe; } //----------------------------------------------------- // // Internal Properties // //------------------------------------------------------ ////// Package /// internal Package Package { get { return _package; } } ////// True if package is thread-safe /// internal bool ThreadSafe { get { return _threadSafe; } } //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- private readonly Package _package; private readonly bool _threadSafe; } //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields // We are expect to have no more than 10 preloaded packages // per AppDomain for our scenarios // ListDictionary is the best fit for this scenarios; otherwise we should be using // Hashtable. HybridDictionary already has functionality of switching between // ListDictionary and Hashtable depending on the size of the collection static private HybridDictionary _packagePairs; static private Object _globalLock; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation, 2005 // // File: PreloadedPackages.cs // // Description: Collection of preloaded packages to be used with // PackWebRequest. // //----------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.Collections; using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Packaging; using MS.Internal; using MS.Internal.PresentationCore; // for ExceptionStringTable namespace MS.Internal.IO.Packaging { ////// PreloadedPackages /// ///Note: we purposely didn't make this class a dictionary since it is an internal /// class and we won't be using even half of the dictionary functionalities. /// If this class becomes a public class which is strongly discouraged, this class /// needs to implement IDictionary. //// Critical: This class serves as a depository of all well-known pre-populated // packages. This class is marked as SecurityCritical to ensure that // 1. only trusted code can add/get/remove trusted packages into the depository // 2. a whole package will never be given out to the platform client // Note: it is OK to give out a part stream from a package instance but // the package related objects such as Package, PackagePart, // PackageRelationship should NEVER be given out to a client. // List of the trusted packages allowed: // 1. ResourceContainer // 2. SiteOfOriginContainer // 3. ZipPackage that is only instantiated by XPS Viewer // [SecurityCritical(SecurityCriticalScope.Everything)] [FriendAccessAllowed] internal static class PreloadedPackages { //----------------------------------------------------- // // Static Constructors // //----------------------------------------------------- static PreloadedPackages() { _globalLock = new Object(); } //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods ////// GetPackage given a uri /// /// uri to match on ///object if found - else null ///uri must be absolute internal static Package GetPackage(Uri uri) { bool ignored; return GetPackage(uri, out ignored); } ////// GetPackage given a uri /// /// uri to match on /// true if the returned package is threadsafe - undefined if null is returned ///object if found - else null ///uri must be absolute internal static Package GetPackage(Uri uri, out bool threadSafe) { ValidateUriKey(uri); lock (_globalLock) { Package package = null; threadSafe = false; if (_packagePairs != null) { PackageThreadSafePair packagePair = _packagePairs[uri] as PackageThreadSafePair; if (packagePair != null) { package = packagePair.Package; threadSafe = packagePair.ThreadSafe; } } return package; } } ////// AddPackage - default to non-thread-safe /// /// uri to use for matching /// package object to serve content from ///Adds a uri, content pair to the cache. If the uri is already /// in the cache, this removes the old content and replaces it. /// The object will not be subject to automatic removal from the cache internal static void AddPackage(Uri uri, Package package) { AddPackage(uri, package, false); } ////// AddPackage /// /// uri to use for matching /// package object to serve content from /// is package thread-safe? ///Adds a uri, content pair to the cache. If the uri is already /// in the cache, this removes the old content and replaces it. /// The object will not be subject to automatic removal from the cache internal static void AddPackage(Uri uri, Package package, bool threadSafe) { ValidateUriKey(uri); lock (_globalLock) { if (_packagePairs == null) { _packagePairs = new HybridDictionary(3); } _packagePairs.Add(uri, new PackageThreadSafePair(package, threadSafe)); } } ////// RemovePackage /// /// uri of the package that needs to be removed ///Removes the package corresponding to the uri from the cache. If a matching uri isn't found /// the status of the cache doesn't change and no exception is throwen /// internal static void RemovePackage(Uri uri) { ValidateUriKey(uri); lock (_globalLock) { if (_packagePairs != null) { _packagePairs.Remove(uri); } } } // Null the instance. Similar to Dispose, but not quite. internal static void Clear() { lock (_globalLock) { _packagePairs = null; } } private static void ValidateUriKey(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } if (!uri.IsAbsoluteUri) { throw new ArgumentException(SR.Get(SRID.UriMustBeAbsolute), "uri"); } } #endregion Internal Methods ////// Package-bool pair where the bool represents the thread-safety status of the package /// private class PackageThreadSafePair { //------------------------------------------------------ // // Internal Constructors // //------------------------------------------------------ internal PackageThreadSafePair(Package package, bool threadSafe) { Invariant.Assert(package != null); _package = package; _threadSafe = threadSafe; } //----------------------------------------------------- // // Internal Properties // //------------------------------------------------------ ////// Package /// internal Package Package { get { return _package; } } ////// True if package is thread-safe /// internal bool ThreadSafe { get { return _threadSafe; } } //----------------------------------------------------- // // Private Fields // //----------------------------------------------------- private readonly Package _package; private readonly bool _threadSafe; } //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields // We are expect to have no more than 10 preloaded packages // per AppDomain for our scenarios // ListDictionary is the best fit for this scenarios; otherwise we should be using // Hashtable. HybridDictionary already has functionality of switching between // ListDictionary and Hashtable depending on the size of the collection static private HybridDictionary _packagePairs; static private Object _globalLock; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Request.cs
- CommandDevice.cs
- VectorAnimationBase.cs
- XmlIgnoreAttribute.cs
- Application.cs
- DiagnosticTraceSource.cs
- PeerObject.cs
- BitmapCodecInfo.cs
- SqlFunctionAttribute.cs
- Int64AnimationUsingKeyFrames.cs
- AutoResetEvent.cs
- EventSetter.cs
- AxisAngleRotation3D.cs
- PointAnimationUsingPath.cs
- CompensationHandlingFilter.cs
- DebugViewWriter.cs
- SafeSecurityHelper.cs
- MsmqChannelFactory.cs
- VirtualPath.cs
- MaskDescriptors.cs
- SqlNodeAnnotation.cs
- SqlClientWrapperSmiStreamChars.cs
- ProcessHost.cs
- SqlBuffer.cs
- Graphics.cs
- KeyPressEvent.cs
- AppDomainEvidenceFactory.cs
- MenuScrollingVisibilityConverter.cs
- UTF32Encoding.cs
- GroupBox.cs
- BridgeDataRecord.cs
- AuthenticationConfig.cs
- TdsRecordBufferSetter.cs
- XsltException.cs
- SoapReflector.cs
- ApplicationManager.cs
- TableCellsCollectionEditor.cs
- SyndicationDeserializer.cs
- MetadataItemCollectionFactory.cs
- HandlerBase.cs
- XmlSchemaType.cs
- BrushMappingModeValidation.cs
- MetafileHeaderWmf.cs
- StringFreezingAttribute.cs
- Exceptions.cs
- WebConfigurationManager.cs
- FileDialog_Vista_Interop.cs
- GraphicsPathIterator.cs
- PeerApplicationLaunchInfo.cs
- mediaeventshelper.cs
- TransactionContextManager.cs
- MetadataArtifactLoaderComposite.cs
- ObjectDataSource.cs
- GeometryGroup.cs
- DESCryptoServiceProvider.cs
- HandledMouseEvent.cs
- AttachedAnnotationChangedEventArgs.cs
- SafeEventLogReadHandle.cs
- AxHostDesigner.cs
- CheckedListBox.cs
- TailCallAnalyzer.cs
- CompiledQueryCacheEntry.cs
- BaseUriHelper.cs
- Atom10FormatterFactory.cs
- FixedSOMGroup.cs
- FacetValueContainer.cs
- DocumentGridContextMenu.cs
- RootProfilePropertySettingsCollection.cs
- MatrixAnimationUsingPath.cs
- XmlSchemaInfo.cs
- AttachmentCollection.cs
- HtmlTableRow.cs
- ManagementObject.cs
- NopReturnReader.cs
- NumericExpr.cs
- ParsedAttributeCollection.cs
- SqlDependencyUtils.cs
- UseLicense.cs
- SignerInfo.cs
- COM2Properties.cs
- safex509handles.cs
- LassoSelectionBehavior.cs
- StickyNoteHelper.cs
- TransactionContextManager.cs
- EntityContainerEntitySetDefiningQuery.cs
- PackageFilter.cs
- GestureRecognitionResult.cs
- TrackBarRenderer.cs
- Expander.cs
- MemberRelationshipService.cs
- embossbitmapeffect.cs
- xml.cs
- UICuesEvent.cs
- DesignerSelectionListAdapter.cs
- StorageAssociationTypeMapping.cs
- CharStorage.cs
- BasePattern.cs
- DataSourceDesigner.cs
- SerializableReadOnlyDictionary.cs
- DbProviderConfigurationHandler.cs