This walkthrough will show you how to build a data provider and corresponding query that can be used by an Operations Manager 2012 (OM12) Widget that can be used in a dashboard created in the Operations Console. In this walk through you will learn the following:
The DataProvider component contains:
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
Microsoft.EnterpriseManagement.Presentation.DataAccess;
namespace
SimpleDataProvider
{
[DataProvider]
public
class
SimpleProvider
}
Notable lines in this code include:
[DataCommand]
ICollection<
string
> GetStrings()
return
new
List<
> {
"Hello"
,
"World"
"a"
"b"
"c"
};
<
ManagementPackFragment
>
Categories
Category
ID
=
"Microsoft.EnterpriseManagement.Monitoring.DataProviders.Category"
Target
"SimpleDataProvider"
Value
"Visualization!Microsoft.SystemCenter.Visualization.DataProviderAssembly"
/>
</
Resources
Assembly
QualifiedName
"SimpleDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
FileName
"SimpleDataProvider.dll"
Accessibility
"Public"
HasNullStream
"false"
The query component, like the data provider component, provides no visualization. Its purpose is to pull data from a data provider. The data provider component runs on the server while the query component runs on the client.
System.ComponentModel.Composition;
System.ComponentModel;
Microsoft.EnterpriseManagement.CompositionEngine;
Microsoft.Practices.Unity;
[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
[ComponentBuildUpRequired]
SimpleQuery: INotifyPropertyChanged, INotifyInitialized
private
bool
initialized;
> output;
int
maxItemCount = -1;
event
PropertyChangedEventHandler PropertyChanged;
[Dependency]
IDataGateway Gateway {
get
;
set
; }
> Output
this
.output;
.output = value;
.OnPropertyChanged(
"Output"
);
MaxItemCount
.maxItemCount;
.maxItemCount = value;
.RunQuery();
"MaxItemCount"
void
OnPropertyChanged(
property)
if
(
.PropertyChanged !=
null
)
.PropertyChanged(
PropertyChangedEventArgs(property));
Notify()
.initialized =
true
RunQuery()
.initialized &&
.maxItemCount > 0)
//Data Access - Call DataProvider
var dataObjectsCommand =
AsyncDataCommand<
>(
"DemoDataProvider!SimpleProvider/GetStrings"
dataObjectsCommand.CommandCompleted += OnDataCommandComplete;
.Gateway.ExecuteAsync(dataObjectsCommand);
OnDataCommandComplete(
object
sender,
AsyncDataCommandCompletedEventArgs<IEnumerable<
>> args)
(args.Error ==
> list =
>();
count =
foreach
s
in
args.Result)
(count == 0)
break
list.Add(s);
count--;
.Output = list;
The Silverlight version of the SimpleQuery will share the xaml and code behind from the WPF project.
A user control is needed to display the data obtained from the data provider.
UserControl
x:Class
"TestWPF.TestControl"
xmlns
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
"http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
"http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
"d"
d:DesignHeight
"115"
d:DesignWidth
"395"
Grid
x:Name
"LayoutRoot"
Background
"White"
Height
"87"
Width
"372"
Grid.ColumnDefinitions
ColumnDefinition
"Auto"
"*"
TextBlock
Grid.Column
"0"
>List from SimpleDataProvider: </
ListBox
"listBox"
"1"
></
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;
TestWPF
partial
TestControl : UserControl, INotifyPropertyChanged
> _stringList;
> StringList
._stringList;
(value !=
._stringList = value;
.listBox.ItemsSource = value;
TestControl()
InitializeComponent();
protected
propertyName)
(PropertyChanged !=
PropertyChanged(
PropertyChangedEventArgs(propertyName));
The Silverlight version of the UserControl will share the xaml and code behind from the WPF project.
The management pack needs to define the following components:
SchemaVersion
"2.0"
xmlns:xsd
"http://www.w3.org/2001/XMLSchema"
Presentation
ComponentTypes
ComponentType
"MySimpleQuery"
Property
Name
Type
"xsd://string[]"
BindingDirection
"Out"
"xsd://int"
"In"
"SilverlightCategory"
"SilverlightAssembly"
"Visualization!Microsoft.SystemCenter.Visualization.SilverlightComponentAssembly"
ComponentImplementations
ComponentImplementation
TypeId
"MySimpleQuerySLImplementation"
Platform
"Silverlight"
Unit
ContractFactory
>SimpleQuerySL.SimpleQuery</
"SimpleQuerySL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"SimpleQuerySL.dll"
"SLUnitComponentsCategory"
"SLUnitComponentsAssembly"
"TestSL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"TestSL.dll"
"WPFCategory"
"WPFAssembly"
"Visualization!Microsoft.SystemCenter.Visualization.WpfComponentAssembly"
"MySimpleQueryWPFImplementation"
"Wpf"
>SimpleQueryWPF.SimpleQuery</
"SimpleQueryWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"SimpleQueryWPF.dll"
"WPFUnitComponentsCategory"
"WPFUnitComponentsAssembly"
"TestWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"TestWPF.dll"
"TestControl"
"StringList"
"TestControlHost"
ComponentReferences
ComponentReference
"TestControlHostReference"
TypeID
Parent
"SC!Microsoft.SystemCenter.Monitoring.ViewFolder.Root"
"TestControlImplementation"
"All"
>TestDataProviderControl.TestControl</
"TestControlHostImplementation"
Composite
Variable
Id
"SimpleData"
Component
"Visualization!Microsoft.SystemCenter.Visualization.ComponentContainer"
Binding
PropertyId
"Visual"
Reference
>$Variable/SimpleData$</
"Objects"
SimpleValue
"10"