AddInToken.Activate Method

Definition

Activates an add-in.

Overloads

Activate<T>(AddInEnvironment)

Activates an add-in in the environment of another add-in.

Activate<T>(AddInSecurityLevel)

Activates an add-in with a specified trust level in a new application domain.

Activate<T>(AppDomain)

Activates an add-in in an existing application domain.

Activate<T>(PermissionSet)

Activates an add-in with a specified permission set in a new application domain.

Activate<T>(AddInProcess, AddInSecurityLevel)

Activates an add-in in an external process, in a new application domain, and with a specified trust level.

Activate<T>(AddInProcess, PermissionSet)

Activates an add-in in an external process, in a new application domain, and with a specified permission set.

Activate<T>(AddInSecurityLevel, String)

Activates an add-in in a new application domain with a specified name and trust level.

Activate<T>(AddInEnvironment)

Activates an add-in in the environment of another add-in.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInEnvironment ^ environment);
public T Activate<T> (System.AddIn.Hosting.AddInEnvironment environment);
member this.Activate : System.AddIn.Hosting.AddInEnvironment -> 'T
Public Function Activate(Of T) (environment As AddInEnvironment) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

environment
AddInEnvironment

The application domain and process that contains the original add-in.

Returns

T

The host view of the add-in.

Examples

The following example activates one add-in in an automatically generated application domain with a specified security level. It then activates a second add-in in the same application domain and process as the first by using the first add-in's AddInEnvironment object.

// Get the AddInController of a 
// currently actived add-in (CalcAddIn).
AddInController aiController = AddInController.GetAddInController(CalcAddIn);

// Select another token.
AddInToken selectedToken2 = ChooseAddIn(tokens);

// Activate a second add-in, CalcAddIn2, in the same
// appliation domain and process as the first add-in by passing
// the first add-in's AddInEnvironment object to the Activate method.
AddInEnvironment aiEnvironment = aiController.AddInEnvironment;
Calculator CalcAddIn2 =
    selectedToken2.Activate<Calculator>(aiEnvironment);

// Get the AddInController for the second add-in to compare environments.
AddInController aiController2 = AddInController.GetAddInController(CalcAddIn2);
Console.WriteLine("Add-ins in same application domain: {0}", aiController.AppDomain.Equals(aiController2.AppDomain));
Console.WriteLine("Add-ins in same process: {0}", aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process));
' Get the AddInController of a 
' currently activated add-in (CalcAddIn).
Dim aiController As AddInController = AddInController.GetAddInController(CalcAddIn)

' Select another token.
Dim selectedToken2 As AddInToken = ChooseAddIn(tokens)

' Activate a second add-in, CalcAddIn2, in the same
' appliation domain and process as the first add-in by passing
' the first add-in's AddInEnvironment object to the Activate method.

Dim aiEnvironment As AddInEnvironment = aiController.AddInEnvironment
Dim CalcAddIn2 As Calculator = _
    selectedToken2.Activate(Of Calculator)(aiEnvironment)

' Get the AddInController for the second add-in to compare environments.
Dim aiController2 As AddInController = AddInController.GetAddInController(CalcAddIn2)

Console.WriteLine("Add-ins in same application domain: {0}", _
    aiController.AppDomain.Equals(aiController2.AppDomain))
Console.WriteLine("Add-ins in same process: {0}", _
    aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process))

Remarks

This method overload activates the add-in in the same application domain and process as the add-in from which environment was obtained.

See also

Activate<T>(AddInSecurityLevel)

Activates an add-in with a specified trust level in a new application domain.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInSecurityLevel trustLevel);
public T Activate<T> (System.AddIn.Hosting.AddInSecurityLevel trustLevel);
member this.Activate : System.AddIn.Hosting.AddInSecurityLevel -> 'T
Public Function Activate(Of T) (trustLevel As AddInSecurityLevel) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

trustLevel
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

Returns

T

The host view of the add-in.

Examples

The following example shows how to activate an add-in, identified by the chosen token, in an automatically generated application domain with a specified security level.

//Ask the user which add-in they would like to use.
AddInToken selectedToken = ChooseAddIn(tokens);

//Activate the selected AddInToken in a new
//application domain with the Internet trust level.
Calculator CalcAddIn = selectedToken.Activate<Calculator>(AddInSecurityLevel.Internet);
            
//Run the add-in using a custom method.
RunCalculator(CalcAddIn);
'Ask the user which add-in they would like to use.
Dim selectedToken As AddInToken = ChooseAddIn(tokens)
'Activate the selected AddInToken in a new
'application domain with the Internet trust level.
Dim CalcAddIn As Calculator = selectedToken.Activate(Of Calculator)(AddInSecurityLevel.Internet)
'Run the add-in using a custom method.
RunCalculator(CalcAddIn)

Remarks

This method overload loads the add-in into an automatically generated application domain. If you want to specify a name for the new application domain, use the Activate<T>(AddInSecurityLevel, String) overload.

This method sets the base directory for the application domain to be the location of the add-in assembly. It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

See also

Activate<T>(AppDomain)

Activates an add-in in an existing application domain.

public:
generic <typename T>
 T Activate(AppDomain ^ target);
public T Activate<T> (AppDomain target);
member this.Activate : AppDomain -> 'T
Public Function Activate(Of T) (target As AppDomain) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

target
AppDomain

The application domain that the add-in should be activated in.

Returns

T

The host view of the add-in.

Exceptions

Full-trust permission is demanded. A caller in the call chain does not have sufficient permission.

Examples

The following example activates an add-in in an application domain that is being used by another add-in. The code for the first add-in is provided in the AddInToken class.

// Get the application domain
// of an existing add-in (CalcAddIn).
AddInController aiCtrl = AddInController.GetAddInController(CalcAddIn);
AppDomain AddInAppDom = aiCtrl.AppDomain;

// Activate another add-in in the same application domain.
Calculator CalcAddIn3 =
    selectedToken2.Activate<Calculator>(AddInAppDom);

// Show that CalcAddIn3 was loaded
// into CalcAddIn's application domain.
AddInController aic = AddInController.GetAddInController(CalcAddIn3);
Console.WriteLine("Add-in loaded into existing application domain: {0}",
    aic.AppDomain.Equals(AddInAppDom));
' Get the application domain
' of an existing add-in (CalcAddIn).

Dim aiCtrl As AddInController = AddInController.GetAddInController(CalcAddIn)
Dim AddInAppDom As AppDomain = aiCtrl.AppDomain

' Activate another add-in in the same appliation domain.
Dim CalcAddIn3 As Calculator = selectedToken2.Activate(Of Calculator)(AddInAppDom)

' Show that the CalcAddIn3 was loaded
' into CalcCaddIn's application domain.
Dim aic As AddInController = AddInController.GetAddInController(CalcAddIn3)
Console.WriteLine("Add-in loaded into existing application domain: {0}", _
 aic.AppDomain.Equals(AddInAppDom))

Remarks

To activate an add-in in an automatically generated application domain, use the Activate<T>(AddInSecurityLevel) overload to generate a new application domain with a specified security level or the Activate<T>(AddInSecurityLevel, String) overload to include a friendly name for the application domain.

Activate<T>(PermissionSet)

Activates an add-in with a specified permission set in a new application domain.

public:
generic <typename T>
 T Activate(System::Security::PermissionSet ^ permissions);
public T Activate<T> (System.Security.PermissionSet permissions);
member this.Activate : System.Security.PermissionSet -> 'T
Public Function Activate(Of T) (permissions As PermissionSet) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

permissions
PermissionSet

The permissions granted for the add-in.

Returns

T

The host view of the add-in.

Exceptions

permissions is null.

Remarks

This method overload loads the add-in into an automatically generated application domain. It sets the base directory for the application domain to be the location of the add-in assembly. It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

Activate<T>(AddInProcess, AddInSecurityLevel)

Activates an add-in in an external process, in a new application domain, and with a specified trust level.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInProcess ^ process, System::AddIn::Hosting::AddInSecurityLevel level);
public T Activate<T> (System.AddIn.Hosting.AddInProcess process, System.AddIn.Hosting.AddInSecurityLevel level);
member this.Activate : System.AddIn.Hosting.AddInProcess * System.AddIn.Hosting.AddInSecurityLevel -> 'T
Public Function Activate(Of T) (process As AddInProcess, level As AddInSecurityLevel) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

process
AddInProcess

The external process in which to activate the add-in.

level
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

Returns

T

The host view of the add-in.

Examples

The following example creates a new process and activates an add-in in that process with a full trust security level.

// Create an external process.
AddInProcess pExternal = new AddInProcess();

// Activate an add-in in the external process
// with a full trust security level.
Calculator CalcAddIn4 =
    selectedToken.Activate<Calculator>(pExternal,
    AddInSecurityLevel.FullTrust);

// Show that the add-in is an external process
// by verifying that it is not in the current (host's) process.
AddInController AddinCtl = AddInController.GetAddInController(CalcAddIn4);
Console.WriteLine("Add-in in host's process: {0}",
    AddinCtl.AddInEnvironment.Process.IsCurrentProcess);
' Create an external process.
Dim pExternal As New AddInProcess()

' Activate an add-in in the external process
' with a full trust security level.
Dim CalcAddIn4 As Calculator = _
    selectedToken.Activate(Of Calculator)(pExternal, _
        AddInSecurityLevel.FullTrust)

' Show that the add-in is an external process
' by verifying that it is not in the current (host's) process.
Dim AddinCtl As AddInController = AddInController.GetAddInController(CalcAddIn4)
Console.WriteLine("Add-in in host's process: {0}", _
 AddinCtl.AddInEnvironment.Process.IsCurrentProcess)

Remarks

This method sets the base directory for the application domain to be the location of the add-in assembly. It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

Security

Demand
full trust for the immediate caller. This member cannot be used by partially trusted code.

Activate<T>(AddInProcess, PermissionSet)

Activates an add-in in an external process, in a new application domain, and with a specified permission set.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInProcess ^ process, System::Security::PermissionSet ^ permissionSet);
public T Activate<T> (System.AddIn.Hosting.AddInProcess process, System.Security.PermissionSet permissionSet);
member this.Activate : System.AddIn.Hosting.AddInProcess * System.Security.PermissionSet -> 'T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

process
AddInProcess

The external process in which to activate the add-in.

permissionSet
PermissionSet

The required permission set granted for the add-in.

Returns

T

The host view of the add-in.

Remarks

This method sets the base directory for the application domain to be the location of the add-in assembly. It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

Security

Demand
full trust for the immediate caller. This member cannot be used by partially trusted code.

Activate<T>(AddInSecurityLevel, String)

Activates an add-in in a new application domain with a specified name and trust level.

public:
generic <typename T>
 T Activate(System::AddIn::Hosting::AddInSecurityLevel trustLevel, System::String ^ appDomainName);
public T Activate<T> (System.AddIn.Hosting.AddInSecurityLevel trustLevel, string appDomainName);
member this.Activate : System.AddIn.Hosting.AddInSecurityLevel * string -> 'T
Public Function Activate(Of T) (trustLevel As AddInSecurityLevel, appDomainName As String) As T

Type Parameters

T

The interface or abstract base type that represents the host view of the add-in.

Parameters

trustLevel
AddInSecurityLevel

One of the enumeration values that specifies the trust level.

appDomainName
String

The friendly name to assign to the new application domain.

Returns

T

The host view of the add-in.

Remarks

If you do not need to specify an application domain name, use the Activate<T>(AddInSecurityLevel) overload.

This method sets the base directory for the application domain to be the location of the add-in assembly. It also looks for the configuration file [addinassemblyname].dll.config and, if found, sets it to be the configuration file for the new application domain.

Applies to