96 lines
3.5 KiB
C#
96 lines
3.5 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using Intel.Manageability.Events;
|
|
using Intel.Manageability.Exceptions;
|
|
using Intel.Manageability;
|
|
|
|
namespace PETEventsSample
|
|
{
|
|
class GeneralEventsFunctionality
|
|
{
|
|
/// <summary>
|
|
/// Subscribe for events
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void Subscribe(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
//Subscribe for Power_Supply_Failed event
|
|
GeneralSubscription subscription = new GeneralSubscription("http://192.168.0.1:16997", Events.Power_Supply.Power_Supply_Failed, SenderIDType.UUID);
|
|
amt.Events.Subscribe(subscription);
|
|
Console.WriteLine("\nSubscription operation completed successfully");
|
|
}
|
|
catch (EventsManageabilityException e)
|
|
{
|
|
PrintException("Subscribe", e);
|
|
}
|
|
|
|
try
|
|
{
|
|
//Subscribe for Battery_added event
|
|
GeneralSubscription subscription = new GeneralSubscription("http://192.168.0.1:16997", Events.Battery.Battery_Added, "MyAMT");
|
|
amt.Events.Subscribe(subscription);
|
|
Console.WriteLine("\nSubscription operation completed successfully");
|
|
}
|
|
catch (EventsManageabilityException e)
|
|
{
|
|
PrintException("Subscribe", e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UnSubscribe for Power_Supply_Failed event
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void UnSubscribe(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
GeneralSubscription subscription = new GeneralSubscription("http://192.168.0.1:16997", Events.Power_Supply.Power_Supply_Failed, SenderIDType.UUID);
|
|
amt.Events.UnSubscribe(subscription);
|
|
Console.WriteLine("\nUnSubscribe operation completed successfully");
|
|
}
|
|
catch (EventsManageabilityException e)
|
|
{
|
|
PrintException("UnSubscribe", e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unsubscribe all existing subscriptions
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void UnSubscribeAll(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.Events.UnSubscribeAll();
|
|
Console.WriteLine("\nUnSubscribe all subscribers completed successfully");
|
|
}
|
|
catch (EventsManageabilityException e)
|
|
{
|
|
PrintException("UnSubscribeAll", e);
|
|
}
|
|
}
|
|
|
|
static void PrintException(string methodName, EventsManageabilityException e)
|
|
{
|
|
Console.WriteLine(methodName + " throw: " + e.Message);
|
|
Console.WriteLine("Details:");
|
|
Console.WriteLine("========");
|
|
Console.WriteLine("\t- Machine Origin : {0}", e.MachineOrigin);
|
|
Console.WriteLine("\t- HLAPI Source Function: {0}", e.Source);
|
|
if (e.PT_STATUS != null)
|
|
Console.WriteLine("\t- Return Value : {0}", e.PT_STATUS);
|
|
if (e.Tip != string.Empty)
|
|
Console.WriteLine("\t- Counsel : {0}", e.Tip);
|
|
}
|
|
}
|
|
}
|