88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.AgentPresence;
|
|
using Intel.Manageability.Exceptions;
|
|
|
|
namespace AgentPresenceLocalSample
|
|
{
|
|
static class AgentPresenceLocalFunctionality
|
|
{
|
|
public static void CreateOrUpdateAgent(IAMTInstance amt, string agentName)
|
|
{
|
|
// --------------------
|
|
// Create Agent
|
|
// --------------------
|
|
|
|
var actions = new List<AgentAction>
|
|
{
|
|
new AgentAction(AgentState.NotStarted, AgentState.Running, true, ActionSystemDefense.DeactivatePolicy,
|
|
false),
|
|
new AgentAction(AgentState.Stopped, AgentState.Expired | AgentState.Stopped, false,
|
|
ActionSystemDefense.ActivatePolicy, false)
|
|
};
|
|
|
|
Console.Write("Enter agent startup timeout in seconds (default is 120): ");
|
|
if (!ushort.TryParse(Console.ReadLine(), out var startupTimer))
|
|
startupTimer = 120;
|
|
Console.WriteLine();
|
|
|
|
Console.Write("Enter agent heartbeat timeout in seconds (default is 120): ");
|
|
if (!ushort.TryParse(Console.ReadLine(), out var intervalTimer))
|
|
intervalTimer = 120;
|
|
Console.WriteLine();
|
|
|
|
// Create policy and pass the action list as a parameter
|
|
Agent agent = new Agent(agentName, actions, startupTimer, intervalTimer);
|
|
|
|
// -------------------------------------------
|
|
// Add the agent to the Intel AMT instance
|
|
// -------------------------------------------
|
|
|
|
try
|
|
{
|
|
amt.AgentPresence.Remote.CreateOrUpdateAgent(agent);
|
|
Console.WriteLine("Create agent completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Create agent failed with exception: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Start(IAMTInstance amt, string applicationName)
|
|
{
|
|
CreateOrUpdateAgent(amt, applicationName);
|
|
Console.WriteLine("Starting presence. The heartbeats will block this program's thread.");
|
|
Console.WriteLine("For an unblocking solution use any of the other agent presence samples.");
|
|
try
|
|
{
|
|
amt.AgentPresence.Local.StartPresence(applicationName);
|
|
Console.WriteLine("Start presence completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Start presence failed with exception: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Shutdown(IAMTInstance amt, string applicationName)
|
|
{
|
|
try
|
|
{
|
|
amt.AgentPresence.Local.ShutdownPresence(applicationName);
|
|
Console.WriteLine("Shutdown presence completed successfully.");
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Shutdown presence failed with exception: " + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |