Compartilhar via


Base Classes

 

Applies To: System Center 2012 SP1

The add-in framework of the Virtual Machine Manager (VMM) console provides two base classes that define the basic functionality of your add-in: ActionAddInBase and ViewAddInBase. Both of these classes inherit from VmmAddInBase.

No matter which class your add-in inherits from, you will need to declare the T:System.Addin.AddinAttribute attribute for your class. The name that you provide for that attribute should match the name of an add-in that you define in the add-in package manifest file.

The VmmAddInBase class

The VmmAddInBase base class is provided by the framework, but not for your own add-ins. This class is the base class of the other add-in base classes that you will derive from. This class provides common functionality and helper object instances that you will use for your add-in.

This class provides multiple methods that you can override. The following table provides details about these overrides:

Method Description
OnLoad Called when the VMM console loads your add-in. This method is a good place to add initialization code.
OnUnload Called when the VMM console unloads your add-in. Any cleanup code can be added here.
GetButtonLabelString Returns a string for the ribbon button that represents this add-in. If a null string is returned, the text for the ribbon button will be loaded from the add-in manifest file.

This method will allow you to localize the ribbon button label. You can also use this method to make the ribbon button label dynamic.

The ActionAddInBase class

The ActionAddInBase base class defines an add-in that supplies custom code to be executed when it is invoked by the VMM console. When a user clicks the associated ribbon button, the PerformAction method is called, which you should override in your derived class. This method receives a list of context objects that represent the objects that were selected in the console when the ribbon button was clicked.

The CheckIfEnabledFor method is defined by the base class and is called when items are selected in the console. If this method returns true, the ribbon button will be enabled, and if it returns false, the button will be disabled. You can have your ribbon button appear for all objects of a specific type, but this method enables you to dictate when a user is allowed to click the button.

The ViewAddInBase class

The ViewAddInBase base class defines an add-in that supplies a view to the VMM console. This view is a Windows Presentation Foundation FrameworkElement class instance. The view is created when the ribbon button is first clicked. Then, the view is cached. A subsequent click does not recreate the view, but instead it shows the cached view. The CreateViewControl method should be overridden, and is responsible to create and return the FrameworkElement class instance to be displayed in the console. This method is only called once, the first time that the ribbon button is clicked.

The CurrentScopeType property is a E:Microsoft.SystemCenter.VirtualMachineManager.UIAddIns.ContextTypes.AddInContextType enumeration value. This property is set when the item that is selected by the console changes. It represents the type of object that is selected in the console.

Depending on the type of object that is identified by the CurrentScopeType property, the CurrentScopeObject property may be set to a context object that represents the VMM object that is selected in the console. However, the value can be null.

You can also override the OnShow and OnHide methods. These methods are called respectively when the view is shown or hidden from view.

See Also

Architecture Concepts
Manifests
Context Object Types