Compartilhar via


How to Use Context Objects

 

Applies To: System Center 2012 SP1

Context objects represent the object types that are selected by the console when an action add-in or view add-in is invoked.

When an action add-in is invoked, the code that is called by the Virtual Machine Manager (VMM) console will pass a collection of ContextObject class object instances. These object instances represent the current object types that are selected by the console when the ribbon button is clicked. This is especially useful when more than one type of object is assigned to the ribbon button. If the button is assigned a context type that was not selected in the console when the button was clicked, that context type will not be included in the collection.

When a view add-in is installed, and the user navigates the VMM console, the SetCurrentScope method is called in the add-in. The console will pass a ContextObject to this method, which represents the current object type that is selected by the console.

Example

The following code example demonstrates how to obtain VMContext instances when you work with an action add-in:

Note

The CheckpointWindow type in this example is a XAML window with a custom constructor. To be able to run this code, you must substitute the current object type and constructor with your own..

public override void PerformAction(IList<ContextObject> contextObjects)  
{  
    CheckpointWindow mainWindow = new CheckpointWindow(  
        this.PowerShellContext,   
        contextObjects.OfType<VMContext>());  
  
    mainWindow.Show();  
}  

Compiling the Code

Namespaces

Microsoft.SystemCenter.VirtualMachineManager.UIAddIns
System.AddIn

Assemblies

System.AddIn
Microsoft.SystemCenter.VirtualMachineManager.UIAddIns

See Also

Scenario: Create Managed Code Ribbon Actions
How to Create an Action Add-in
How to Define a Custom Action Add-in in the Manifest