Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

How to: Activate Add-ins with Different Isolation and Security

You can activate an add-in by using different application domain and process configurations to suit your isolation and security requirements. The Activate method overloads of the AddInToken class provide the following choices for activating an add-in:

  • In its own application domain, which is automatically generated by the system.

  • In an existing application domain, with or without other add-ins.

  • In the same environment (application domain and process) as another add-in.

  • In a new, external process that is separate from the host's process. The new process can include other add-ins that share that process.

When you activate an add-in in a new application domain or process, you must specify a security level by using either an AddInSecurityLevel or a PermissionSet object. For more information about activating add-ins, see Add-in Activation.

The following procedures show how to implement these activation options by using the Activate method overloads. The examples assume that the pipeline segment and add-in caches have been built, and that one or more add-ins have been found and returned in an AddInToken collection named tokens. For more information about how to build the cache files and find add-ins, see Add-in Discovery.

To activate an add-in in a new application domain

  • Use the Activate(Of T)(AddInSecurityLevel) or Activate(Of T)(PermissionSet) method overload.

    '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)
    

To activate an add-in in the same application domain as another add-in

  • Use the Activate(Of T)(AppDomain) method overload.

    ' 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))
    

To activate an add-in in the same application domain and process as another add-in

  • Use the Activate(Of T)(AddInEnvironment) method overload.

    ' 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))
    

To activate an add-in in a new process

  • Use the Activate(Of T)(AddInProcess, AddInSecurityLevel) or Activate(Of T)(AddInProcess, PermissionSet) method overload.

    ' 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 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)
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.