Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Hosting / AddInEnvironment.cs / 1305376 / AddInEnvironment.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: AddInEnvironment
**
** Purpose: Abstraction representing an AppDomain, Process and Machine
**
===========================================================*/
using System;
using System.AddIn.Contract;
using System.Runtime.Remoting;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
namespace System.AddIn.Hosting
{
public sealed class AddInEnvironment
{
private AddInProcess _process;
// for in process we have an appdomain.
private AppDomain _appDomain;
// for out-of-process we have this.
private AddInServerWorker _addInServerWorker;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="appDomain")]
public AddInEnvironment(AppDomain appDomain)
{
if (appDomain == null)
throw new ArgumentNullException("appDomain");
System.Diagnostics.Contracts.Contract.EndContractBlock();
if (appDomain != AppDomain.CurrentDomain && !Utils.HasFullTrust()) {
throw new SecurityException(Res.PartialTrustCannotActivate);
}
_appDomain = appDomain;
_process = AddInProcess.Current;
}
// This version is used when we have just created a new appdomain for this addin.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="appDomain")]
internal AddInEnvironment(AppDomain appDomain, bool skipDomainCheck)
{
if (appDomain == null)
throw new ArgumentNullException("appDomain");
System.Diagnostics.Contracts.Contract.EndContractBlock();
_appDomain = appDomain;
_process = AddInProcess.Current;
}
internal AddInEnvironment(AddInProcess process, AddInServerWorker worker)
{
_addInServerWorker = worker;
_process = process;
}
public AddInProcess Process
{
get { return _process; }
}
internal AppDomain AppDomain
{
get { return _appDomain; }
}
internal AddInServerWorker AddInServerWorker
{
get { return _addInServerWorker; }
}
//
//
//
//
[System.Security.SecuritySafeCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2129:SecurityTransparentCodeShouldNotReferenceNonpublicSecurityCriticalCode", Justification = "This is a SecurityRules.Level1 assembly, in which this rule is being incorrectly applied")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2128:SecurityTransparentCodeShouldNotAssert", Justification = "This is a SecurityRules.Level1 assembly, in which this rule is being incorrectly applied")]
internal void UnloadAppDomain()
{
if (Process.IsCurrentProcess)
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
permission.Assert();
AppDomain.Unload(AppDomain);
CodeAccessPermission.RevertAssert();
}
else
{
try
{
_addInServerWorker.UnloadAppDomain();
}
catch (AppDomainUnloadedException) { }
catch (RemotingException) { }
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: AddInEnvironment
**
** Purpose: Abstraction representing an AppDomain, Process and Machine
**
===========================================================*/
using System;
using System.AddIn.Contract;
using System.Runtime.Remoting;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
namespace System.AddIn.Hosting
{
public sealed class AddInEnvironment
{
private AddInProcess _process;
// for in process we have an appdomain.
private AppDomain _appDomain;
// for out-of-process we have this.
private AddInServerWorker _addInServerWorker;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="appDomain")]
public AddInEnvironment(AppDomain appDomain)
{
if (appDomain == null)
throw new ArgumentNullException("appDomain");
System.Diagnostics.Contracts.Contract.EndContractBlock();
if (appDomain != AppDomain.CurrentDomain && !Utils.HasFullTrust()) {
throw new SecurityException(Res.PartialTrustCannotActivate);
}
_appDomain = appDomain;
_process = AddInProcess.Current;
}
// This version is used when we have just created a new appdomain for this addin.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId="appDomain")]
internal AddInEnvironment(AppDomain appDomain, bool skipDomainCheck)
{
if (appDomain == null)
throw new ArgumentNullException("appDomain");
System.Diagnostics.Contracts.Contract.EndContractBlock();
_appDomain = appDomain;
_process = AddInProcess.Current;
}
internal AddInEnvironment(AddInProcess process, AddInServerWorker worker)
{
_addInServerWorker = worker;
_process = process;
}
public AddInProcess Process
{
get { return _process; }
}
internal AppDomain AppDomain
{
get { return _appDomain; }
}
internal AddInServerWorker AddInServerWorker
{
get { return _addInServerWorker; }
}
//
//
//
//
[System.Security.SecuritySafeCritical]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2129:SecurityTransparentCodeShouldNotReferenceNonpublicSecurityCriticalCode", Justification = "This is a SecurityRules.Level1 assembly, in which this rule is being incorrectly applied")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2128:SecurityTransparentCodeShouldNotAssert", Justification = "This is a SecurityRules.Level1 assembly, in which this rule is being incorrectly applied")]
internal void UnloadAppDomain()
{
if (Process.IsCurrentProcess)
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
permission.Assert();
AppDomain.Unload(AppDomain);
CodeAccessPermission.RevertAssert();
}
else
{
try
{
_addInServerWorker.UnloadAppDomain();
}
catch (AppDomainUnloadedException) { }
catch (RemotingException) { }
}
}
}
}
// 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
- RawStylusActions.cs
- ToolTipService.cs
- DataBoundControlAdapter.cs
- DependencyPropertyHelper.cs
- relpropertyhelper.cs
- DrawingContextWalker.cs
- VectorAnimation.cs
- TypeDescriptionProviderAttribute.cs
- PersistenceTypeAttribute.cs
- ColorPalette.cs
- AdornedElementPlaceholder.cs
- ContextBase.cs
- ShaderRenderModeValidation.cs
- UserControlCodeDomTreeGenerator.cs
- BamlResourceDeserializer.cs
- ParserStreamGeometryContext.cs
- XmlNode.cs
- CompilerParameters.cs
- WSFederationHttpSecurityElement.cs
- HttpChannelFactory.cs
- XmlSchemaObject.cs
- _LazyAsyncResult.cs
- ApplicationServicesHostFactory.cs
- AppDomainUnloadedException.cs
- EncryptedReference.cs
- NavigateEvent.cs
- _UriTypeConverter.cs
- UpdateEventArgs.cs
- ProcessModelInfo.cs
- SafeNativeMethods.cs
- JsonEncodingStreamWrapper.cs
- SuppressMergeCheckAttribute.cs
- EventWaitHandleSecurity.cs
- UnsafeNetInfoNativeMethods.cs
- RegexParser.cs
- DocumentReference.cs
- RemotingException.cs
- ResourcesGenerator.cs
- GrowingArray.cs
- MessageSecurityOverTcpElement.cs
- FilterableAttribute.cs
- XmlILModule.cs
- DataGridViewRowConverter.cs
- ComplexBindingPropertiesAttribute.cs
- HybridDictionary.cs
- HttpModuleCollection.cs
- WebScriptMetadataMessageEncoderFactory.cs
- XLinq.cs
- complextypematerializer.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- MimeWriter.cs
- HMACSHA512.cs
- EntityProxyFactory.cs
- SafeBitVector32.cs
- FacetValues.cs
- Parser.cs
- MobileControlBuilder.cs
- WebConfigurationManager.cs
- QilInvoke.cs
- ExternalFile.cs
- SystemKeyConverter.cs
- SelectedGridItemChangedEvent.cs
- TextSelectionProcessor.cs
- DialogDivider.cs
- ExecutionProperties.cs
- WebPartConnectVerb.cs
- DeviceContexts.cs
- RegexMatchCollection.cs
- WSDualHttpSecurityMode.cs
- BaseDataList.cs
- GridLength.cs
- KeyManager.cs
- StringInfo.cs
- UriTemplate.cs
- Baml2006SchemaContext.cs
- Clipboard.cs
- Substitution.cs
- SplitterCancelEvent.cs
- CompositeFontFamily.cs
- Stackframe.cs
- LinkConverter.cs
- CompiledELinqQueryState.cs
- QuaternionKeyFrameCollection.cs
- SqlGatherConsumedAliases.cs
- SerializationException.cs
- XPathNodeIterator.cs
- sitestring.cs
- SessionPageStateSection.cs
- PreloadHost.cs
- BindMarkupExtensionSerializer.cs
- SafeNativeMethodsOther.cs
- Stopwatch.cs
- CapabilitiesPattern.cs
- Metafile.cs
- SelectedDatesCollection.cs
- EntityContainer.cs
- DbMetaDataColumnNames.cs
- ObjectDataSourceSelectingEventArgs.cs
- RolePrincipal.cs
- InvalidAsynchronousStateException.cs