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
- IIS7WorkerRequest.cs
- HashRepartitionEnumerator.cs
- WebDisplayNameAttribute.cs
- SoapIncludeAttribute.cs
- CacheEntry.cs
- AuthenticationSection.cs
- SchemaComplexType.cs
- PreProcessInputEventArgs.cs
- AsyncOperationLifetimeManager.cs
- ButtonColumn.cs
- DataServiceException.cs
- Brush.cs
- VarInfo.cs
- Executor.cs
- PanelDesigner.cs
- PermissionSetEnumerator.cs
- MemoryResponseElement.cs
- handlecollector.cs
- ManagedWndProcTracker.cs
- ContextDataSourceContextData.cs
- EntityDataSourceDataSelection.cs
- _NetworkingPerfCounters.cs
- VerticalAlignConverter.cs
- SqlTopReducer.cs
- NumberFormatInfo.cs
- EmptyEnumerator.cs
- BufferAllocator.cs
- PartialTrustHelpers.cs
- FixedSOMImage.cs
- TripleDES.cs
- DocumentsTrace.cs
- SmiMetaData.cs
- DataBindingExpressionBuilder.cs
- OracleCommandBuilder.cs
- Schedule.cs
- WriteTimeStream.cs
- InternalDuplexBindingElement.cs
- OleDbTransaction.cs
- WebServiceErrorEvent.cs
- InternalResources.cs
- AstTree.cs
- HtmlTextArea.cs
- PolicyException.cs
- InputLanguageSource.cs
- GroupJoinQueryOperator.cs
- TargetPerspective.cs
- EventTrigger.cs
- SmtpFailedRecipientsException.cs
- ExternalException.cs
- ErrorHandlerModule.cs
- BindToObject.cs
- Ray3DHitTestResult.cs
- ScrollBarRenderer.cs
- HttpCapabilitiesSectionHandler.cs
- EdmRelationshipRoleAttribute.cs
- MessageRpc.cs
- RemotingAttributes.cs
- GradientStopCollection.cs
- graph.cs
- QilXmlWriter.cs
- ProfileServiceManager.cs
- DataServices.cs
- ToolBarPanel.cs
- Converter.cs
- WebEvents.cs
- PropertiesTab.cs
- ClientSideQueueItem.cs
- RegexReplacement.cs
- ArithmeticException.cs
- dbdatarecord.cs
- PopOutPanel.cs
- GroupBoxAutomationPeer.cs
- PersistenceMetadataNamespace.cs
- RecognitionResult.cs
- TypeUtil.cs
- TableLayoutPanelResizeGlyph.cs
- PointAnimationUsingPath.cs
- DataGridColumnFloatingHeader.cs
- DllNotFoundException.cs
- GorillaCodec.cs
- StaticSiteMapProvider.cs
- SynchronizationLockException.cs
- WindowsListBox.cs
- StringResourceManager.cs
- PrintPreviewDialog.cs
- Font.cs
- EntityDesignPluralizationHandler.cs
- DesignerHierarchicalDataSourceView.cs
- InvokeBinder.cs
- ThreadWorkerController.cs
- SmiConnection.cs
- DecimalAnimationUsingKeyFrames.cs
- PersistenceProvider.cs
- BuildManager.cs
- FigureHelper.cs
- ImpersonateTokenRef.cs
- CompilerScopeManager.cs
- NumericUpDown.cs
- MediaEntryAttribute.cs
- PocoPropertyAccessorStrategy.cs