220 lines
9.3 KiB
C#
220 lines
9.3 KiB
C#
//----------------------------------------------------------------------------
|
||
//
|
||
// Copyright (c) Intel Corporation, 2011-2015 All Rights Reserved.
|
||
//
|
||
//----------------------------------------------------------------------------
|
||
|
||
using System;
|
||
using System.Collections.ObjectModel;
|
||
using Intel.Manageability;
|
||
using System.Xml;
|
||
using Intel.Manageability.Exceptions;
|
||
using Intel.Manageability.Events;
|
||
|
||
namespace WSEventingSample
|
||
{
|
||
class WSEventingFunctionality
|
||
{
|
||
/// <summary>
|
||
/// Regular Subscription to all events
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void Subscribe(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
if (amt.Events.WSEvents.supportedFilters.Contains(FilterName.All))
|
||
{
|
||
//Subscribe with the default (PUSH) delivery mode
|
||
//The address (FQDN or IP format) must begin with ‘http://’ ('https://' is also supported from AMT version 11.0 and above) and include the port.
|
||
Subscription subscription = new Subscription("http://192.168.0.15:12345", FilterName.All, SenderIDType.UUID);
|
||
//the SenderId will be added to ReferenceParameter, in Intel(R) AMT < 5.1 it will be added to the HTTPHeader
|
||
subscription.SenderIDPlacing = SenderIDPlacing.ReferenceParameter;
|
||
amt.Events.WSEvents.Subscribe(subscription, null, null);
|
||
Console.WriteLine("\nSubscription operation completed successfully.");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("\n" + "This filter is not supported by this version of Intel(R) AMT ");
|
||
}
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Subscribe With Reference Parameters
|
||
/// Reference parameters are limited by Intel AMT to a maximum length of 256 characters. This value includes tags and namespaces, and not just the values.
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void SubscribeWithReferenceParameters(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
//This XML will be sent with the event
|
||
//the XML must contain the namespace for the reference parameters and the content
|
||
XmlDocument doc = new XmlDocument();
|
||
XmlElement root = doc.CreateElement("m", "Free_XML", "http://www.RefParametersNamepsace.com");
|
||
//content of the reference parameters
|
||
root.InnerText = "this XML will be sent each event";
|
||
doc.AppendChild(root);
|
||
|
||
if (amt.Events.WSEvents.supportedFilters.Contains(FilterName.All))
|
||
{
|
||
//The address (FQDN or IP format) must begin with ‘http://’ ('https://' is also supported from AMT version 11.0 and above) and include the port.
|
||
Subscription subscription = new Subscription("http://myConsole.intel.com:12345", FilterName.All, SenderIDType.CurrentAddress);
|
||
//the SenderId will be added to ReferenceParameter, in Intel(R) AMT < 5.1 it will be added to the HTTPHeader
|
||
subscription.SenderIDPlacing = SenderIDPlacing.ReferenceParameter;
|
||
amt.Events.WSEvents.Subscribe(subscription, null, doc);
|
||
Console.WriteLine("\nSubscription operation completed successfully.");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("\n" + "This filter is not supported by this version of Intel(R) AMT ");
|
||
}
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Display all the current subscriptions
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void DisplayCurrentSubscription(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
Collection<Subscription> subscriptions = amt.Events.WSEvents.EnumerateSubscriptions();
|
||
|
||
Console.WriteLine("Subscriptions");
|
||
Console.WriteLine("-------------");
|
||
|
||
foreach (Subscription sub in subscriptions)
|
||
{
|
||
Console.WriteLine("\nListener address: {0}", sub.ListenerAddress);
|
||
Console.WriteLine("DeliveryMode: {0}", sub.DeliveryMode);
|
||
Console.WriteLine("Type of filter: {0}", sub.Filter);
|
||
Console.WriteLine("Sender address: {0}", sub.Sender);
|
||
}
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// UnSubscribe from a subscription
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void UnSubscribe(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
bool Unsubscribed = false;
|
||
Collection<Subscription> subscriptions = amt.Events.WSEvents.EnumerateSubscriptions();
|
||
foreach (Subscription sub in subscriptions)
|
||
{
|
||
//Delete all the subscriptions with listenerAddress == "http://192.168.0.16:12345", filter == All, DeliveryMode = Push
|
||
if ((sub.DeliveryMode == DeliveryMode.Push) && (sub.ListenerAddress == "http://192.168.0.15:12345") && (sub.Filter == FilterName.All))
|
||
{
|
||
amt.Events.WSEvents.UnSubscribe(sub);
|
||
Unsubscribed = true;
|
||
}
|
||
}
|
||
if (!(Unsubscribed))
|
||
{
|
||
Console.WriteLine("Subscription not found.");
|
||
return;
|
||
}
|
||
Console.WriteLine("\nUnSubscribe operation completed successfully.");
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
public static void SubscribeCILAEvent(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
if (amt.Events.WSEvents.supportedFilters.Contains(FilterName.Features))
|
||
{
|
||
amt.Events.EnableCILA(FastCallForHelp.Enable_OS_AND_BIOS);
|
||
//The address (FQDN or IP format) must begin with ‘http://’ ('https://' is also supported from AMT version 11.0 and above) and include the port.
|
||
Subscription subscription = new Subscription("http://192.168.0.17:12345", FilterName.Features, SenderIDType.None);
|
||
amt.Events.WSEvents.Subscribe(subscription, null, null);
|
||
Console.WriteLine("\nSubscription operation completed successfully.");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("\n" + "This filter is not supported by this version of Intel(R) AMT ");
|
||
}
|
||
|
||
}
|
||
catch (NotSupportedException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Unsubscribe all subscriptions
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void UnSubscribeAll(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
amt.Events.WSEvents.UnSubscribeAll();
|
||
Console.WriteLine("\nUnSubscription operation completed successfully.");
|
||
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Regular Subscription to ME_Presence events
|
||
/// </summary>
|
||
/// <param name="amt">The Intel AMT instance</param>
|
||
public static void SubscribeME_PresenceEvent(IAMTInstance amt)
|
||
{
|
||
try
|
||
{
|
||
if (amt.Events.WSEvents.supportedFilters.Contains(FilterName.ME_Presence))
|
||
{
|
||
//The address (FQDN or IP format) must begin with ‘http://’ ('https://' is also supported from AMT version 11.0 and above) and include the port.
|
||
Subscription subscription = new Subscription("http://192.168.0.12:12345", FilterName.ME_Presence, "MyAMT", DeliveryMode.Push);
|
||
//set the presence interval to be 20 minutes
|
||
subscription.PresenceInterval = 20;
|
||
amt.Events.WSEvents.Subscribe(subscription, null, null);
|
||
Console.WriteLine("\nSubscription operation completed successfully.");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("\n" + "This filter is not supported by this version of Intel(R) AMT ");
|
||
}
|
||
}
|
||
catch (ManageabilityException ex)
|
||
{
|
||
Console.WriteLine("\n" + ex.Message);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|