How to: Use Qualification Data
You can assign qualification data to a pipeline segment for any purpose, by applying one or more QualificationDataAttribute attributes to the segment. Each attribute specifies a simple name/value pair of string data. For example, you might indicate that an add-in should be activated with full trust by specifying the name/value pair "Security" and "FullTrust". Similarly, you might indicate that a pipeline segment should be isolated in its own process by specifying the name/value pair "Isolation" and "NewProcess".
To apply qualification data to a pipeline segment
Use the QualificationDataAttribute attribute.
' This pipeline segment has ' two attributes: ' 1 - An AddInAttribute to identify ' this segment as an add-in. ' ' 2 - A QualificationDataAttribute to ' indicate that the add-in should ' be loaded into a new application domain. <AddIn("Calculator Add-in", Version:="2.0.0.0")> _ <QualificationData("Isolation", "NewAppDomain")> _ Public Class SampleV2AddIn
// This pipeline segment has // two attributes: // 1 - An AddInAttribute to identify // this segment as an add-in. // // 2 - A QualificationDataAttribute to // indicate that the add-in should // be loaded into a new application domain. [AddIn("Calculator Add-in",Version="2.0.0.0")] [QualificationData("Isolation", "NewAppDomain")] public class SampleV2AddIn : Calculator2 {
To determine the qualification data for a particular pipeline segment
Use the QualificationData property on an AddInToken object to get a dictionary of segments and their qualification data associated with the token, and then use the appropriate AddInSegmentType value to get a dictionary that contains the name/value pairs that comprise the qualification data for the desired segment.
' Use qualification data to control ' how an add-in should be activated. If selectedToken.QualificationData(AddInSegmentType.AddIn)("Isolation").Equals("NewProcess") Then ' Create an external process. Dim external As AddInProcess = New AddInProcess ' Activate an add-in in an automatically generated ' application domain with a full trust security level. Dim CalcAddin5 As Calculator = _ selectedToken.Activate(Of Calculator)(external, _ AddInSecurityLevel.FullTrust) Console.WriteLine("Add-in activated per qualification data.") Else Console.WriteLine("This add-in is not designated to be activated in a new process.") End If
// Use qualification data to control // how an add-in should be activated. if (selectedToken.QualificationData[AddInSegmentType.AddIn]["Isolation"].Equals("NewProcess")) { // Create an external process. AddInProcess external = new AddInProcess(); // Activate an add-in in the new process // with the full trust security level. Calculator CalcAddIn5 = selectedToken.Activate<Calculator>(external, AddInSecurityLevel.FullTrust); Console.WriteLine("Add-in activated per qualification data."); } else Console.WriteLine("This add-in is not designated to be activated in a new process.");
If there is no qualification data for a segment, its dictionary of name/value pairs is empty.
Note
The add-in model does not use qualification data that is applied to the host view of the add-in. As a result, the dictionary for AddInSegmentType.HostViewOfAddIn is always empty.
To list the qualification data for all pipeline segments
Enumerate the AddInToken object as if it were a collection of QualificationDataItem structures.
' Show the qualification data for each ' token in an AddInToken collection. For Each token As AddInToken In tokens For Each qdi As QualificationDataItem In token Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}", _ token.Name, qdi.Segment, qdi.Name, qdi.Value) Next Next
// Show the qualification data for each // token in an AddInToken collection. foreach (AddInToken token in tokens) { foreach (QualificationDataItem qdi in token) { Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}", token.Name, qdi.Segment, qdi.Name, qdi.Value); } }
Note
The add-in model does not use qualification data that is applied to the host view of the add-in. As a result, when you enumerate qualification data you will not find any items whose Segment property is AddInSegmentType.HostViewOfAddIn.