Last active
December 24, 2015 01:49
-
-
Save holyketzer/6726580 to your computer and use it in GitHub Desktop.
SCOM DataQuerySample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.ComponentModel.Composition; | |
using System.Linq; | |
using System.Net; | |
using System.Windows.Controls; | |
using System.Windows.Documents; | |
using System.Windows.Ink; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Animation; | |
using System.Windows.Shapes; | |
using Microsoft.EnterpriseManagement.CompositionEngine; | |
using Microsoft.EnterpriseManagement.Monitoring.UnitComponents.Data; | |
using Microsoft.EnterpriseManagement.Presentation.DataAccess; | |
using Microsoft.Practices.Unity; | |
namespace Microsoft.SystemCenter.Visualization.Component.Library.Queries | |
{ | |
[Export] | |
[PartCreationPolicy(CreationPolicy.NonShared)] | |
[ComponentBuildUpRequired] | |
public class GetMonitorsForEntity : BaseDataSource | |
{ | |
public GetMonitorsForEntity() : base(true) | |
{ | |
} | |
protected override void DoWork() | |
{ | |
this.FilterPropertiesToDataSourceAndDetail(); | |
this.FetchData(); | |
} | |
[Dependency] | |
public IDataGateway Gateway { get; set; } | |
private IDataObject _target; | |
public object Target | |
{ | |
get { return _target; } | |
set | |
{ | |
var list = value as IEnumerable<IDataObject>; | |
if (list != null) | |
{ | |
_target = list.First(); | |
} | |
else | |
{ | |
_target = value as IDataObject; | |
} | |
StartWork(); | |
} | |
} | |
/// <summary> | |
/// Fetch data | |
/// </summary> | |
private void FetchData() | |
{ | |
if (!this.IsReadyToFetchData) | |
{ | |
return; | |
} | |
try | |
{ | |
var cmd = new AsyncDataCommand<IDataObject>("Microsoft.SystemCenter.Visualization.Component.Library.DataProviders!MonitorDataProvider/GetMonitorsForEntity"); | |
cmd.Parameters.Add("target", _target); | |
cmd.CommandCompleted += FetchDataCommandCompleted; | |
IsFetchingData = true; | |
Gateway.ExecuteAsync(cmd); | |
} | |
catch (Exception e) | |
{ | |
HandleFetchDataError("FailedToFetchData", e); | |
} | |
} | |
protected override void FetchDataCompleted(IDataObjectCollection result) | |
{ | |
if (result != null) | |
{ | |
SetOutput(result); | |
} | |
} | |
/// <summary> | |
/// Returns true if we are in a state where we can call FetchData | |
/// </summary> | |
private bool IsReadyToFetchData | |
{ | |
get | |
{ | |
if (!this.IsNotified) | |
{ | |
return false; | |
} | |
if (this.IsFetchingData) | |
{ | |
return false; | |
} | |
if (_target == null) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} | |
protected override void ReInitialize() | |
{ | |
this.DisplayStringsProcessed = false; | |
this.DisplayStrings = null; | |
SetOutput(null); | |
this.NotifyPropertyChanged("Output"); | |
} | |
} | |
protected override void TriggerRefresh() | |
{ | |
this.StartWork(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Property Name="Refresh" Type="xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.ActionTypes/RefreshAction" BindingDirection="In" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment