Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Pipeline / ContractHandle.cs / 1305376 / ContractHandle.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: ContractHandle ** ** Purpose: ** ===========================================================*/ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.AddIn.Contract; using System.AddIn; using System.Runtime.Remoting.Lifetime; using System.Runtime.Remoting; using System.Runtime.Serialization; using System.Diagnostics.Contracts; namespace System.AddIn.Pipeline { ////// public class ContractHandle : IDisposable { private IContract m_contract; private int? m_token; internal const string s_appDomainOwner = "System.AddIn_Owner_Contract"; public ContractHandle(IContract contract) { if (contract == null) throw new ArgumentNullException("contract"); System.Diagnostics.Contracts.Contract.EndContractBlock(); m_contract = contract; m_token = m_contract.AcquireLifetimeToken(); } public IContract Contract { get { return m_contract; } } ~ContractHandle() { Dispose(false); } protected virtual void Dispose(bool disposing) { if (disposing) { // managed cleanup would go here } if (m_token != null) { try { // See comments in AddInController for why its OK to call into the // transparentProxy from this objects Finalize member. m_contract.RevokeLifetimeToken((int)m_token); } catch (AppDomainUnloadedException) { } catch (RemotingException) { } catch (SerializationException) {} finally { m_token = null; m_contract = null; } } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="AppDomain")] public static bool ContractOwnsAppDomain(IContract contract, AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); if (contract == null) throw new ArgumentNullException("contract"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return domain.GetData(s_appDomainOwner) == contract; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="AppDomain")] public static IContract AppDomainOwner(AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return (IContract)domain.GetData(s_appDomainOwner); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: ContractHandle ** ** Purpose: ** ===========================================================*/ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.AddIn.Contract; using System.AddIn; using System.Runtime.Remoting.Lifetime; using System.Runtime.Remoting; using System.Runtime.Serialization; using System.Diagnostics.Contracts; namespace System.AddIn.Pipeline { ////// public class ContractHandle : IDisposable { private IContract m_contract; private int? m_token; internal const string s_appDomainOwner = "System.AddIn_Owner_Contract"; public ContractHandle(IContract contract) { if (contract == null) throw new ArgumentNullException("contract"); System.Diagnostics.Contracts.Contract.EndContractBlock(); m_contract = contract; m_token = m_contract.AcquireLifetimeToken(); } public IContract Contract { get { return m_contract; } } ~ContractHandle() { Dispose(false); } protected virtual void Dispose(bool disposing) { if (disposing) { // managed cleanup would go here } if (m_token != null) { try { // See comments in AddInController for why its OK to call into the // transparentProxy from this objects Finalize member. m_contract.RevokeLifetimeToken((int)m_token); } catch (AppDomainUnloadedException) { } catch (RemotingException) { } catch (SerializationException) {} finally { m_token = null; m_contract = null; } } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="AppDomain")] public static bool ContractOwnsAppDomain(IContract contract, AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); if (contract == null) throw new ArgumentNullException("contract"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return domain.GetData(s_appDomainOwner) == contract; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="AppDomain")] public static IContract AppDomainOwner(AppDomain domain) { if (domain == null) throw new ArgumentNullException("domain"); System.Diagnostics.Contracts.Contract.EndContractBlock(); return (IContract)domain.GetData(s_appDomainOwner); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- InputScopeAttribute.cs
- HMACSHA1.cs
- HttpModuleCollection.cs
- GenericWebPart.cs
- XmlHelper.cs
- MultipleViewProviderWrapper.cs
- ParameterBinding.cs
- StrokeNodeOperations.cs
- XmlArrayItemAttributes.cs
- ResourceManagerWrapper.cs
- translator.cs
- BroadcastEventHelper.cs
- ModelUtilities.cs
- ExceptionAggregator.cs
- DataGridViewCellValidatingEventArgs.cs
- Point3DKeyFrameCollection.cs
- TimerElapsedEvenArgs.cs
- Activity.cs
- CreationContext.cs
- UpdateExpressionVisitor.cs
- PackWebRequestFactory.cs
- TextServicesDisplayAttributePropertyRanges.cs
- XmlDigitalSignatureProcessor.cs
- BitmapEncoder.cs
- RightsManagementInformation.cs
- ReflectionHelper.cs
- AdornerHitTestResult.cs
- UiaCoreProviderApi.cs
- XmlSchemaDatatype.cs
- CopyAttributesAction.cs
- _ConnectOverlappedAsyncResult.cs
- AnnouncementEndpointElement.cs
- WebConvert.cs
- ServiceNotStartedException.cs
- String.cs
- WebServiceResponse.cs
- SmiMetaDataProperty.cs
- NegotiateStream.cs
- SystemFonts.cs
- MemberAssignmentAnalysis.cs
- _CommandStream.cs
- ListViewItemMouseHoverEvent.cs
- DataSourceControlBuilder.cs
- DictionaryContent.cs
- MatchingStyle.cs
- CorrelationRequestContext.cs
- ColorAnimationUsingKeyFrames.cs
- Stack.cs
- IPEndPoint.cs
- ZoomingMessageFilter.cs
- DesignerForm.cs
- ApplicationFileParser.cs
- EmissiveMaterial.cs
- XmlSignificantWhitespace.cs
- TrimSurroundingWhitespaceAttribute.cs
- FontFamilyValueSerializer.cs
- StateFinalizationDesigner.cs
- TimelineClockCollection.cs
- PropertyDescriptorComparer.cs
- RenderData.cs
- SocketPermission.cs
- LocatorBase.cs
- PathSegmentCollection.cs
- CounterSample.cs
- Function.cs
- PropagatorResult.cs
- ToolStripSeparator.cs
- OutputCacheProfileCollection.cs
- FontUnitConverter.cs
- Slider.cs
- OdbcEnvironmentHandle.cs
- MeshGeometry3D.cs
- SimpleType.cs
- ThrowHelper.cs
- Win32.cs
- PartialList.cs
- NameValueCache.cs
- XmlUrlEditor.cs
- TrustManagerPromptUI.cs
- CodeDefaultValueExpression.cs
- CircleHotSpot.cs
- OlePropertyStructs.cs
- CapiSafeHandles.cs
- StringInfo.cs
- SolidBrush.cs
- XmlEncodedRawTextWriter.cs
- SBCSCodePageEncoding.cs
- ListenerConnectionDemuxer.cs
- MethodBuilderInstantiation.cs
- ContractMapping.cs
- IncomingWebResponseContext.cs
- NumberSubstitution.cs
- COM2PictureConverter.cs
- ExpressionBuilderCollection.cs
- XmlComplianceUtil.cs
- DataGridLinkButton.cs
- XXXInfos.cs
- EntityConnection.cs
- DateTimeHelper.cs
- DefaultTextStoreTextComposition.cs