105 lines
3.8 KiB
C#

//----------------------------------------------------------------------------
//
// Copyright (c) Intel Corporation, 2011 - 2015 All Rights Reserved.
//
//----------------------------------------------------------------------------
using System;
using System.IO;
using Intel.Manageability;
using Intel.Manageability.Exceptions;
using Common.Utils;
using System.Runtime.InteropServices;
namespace AgentPresenceRemoteSample
{
class Program
{
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetDefaultDllDirectories(int directoryFlags);
static void Main(string[] args)
{
// set default dll lookup directory to system
SetDefaultDllDirectories(0x00000800); //LOAD_LIBRARY_SEARCH_SYSTEM32
IAMTInstance amt = null;
ConnectionInfoEX ci = null;
try
{
// Check if JSON path was provided as an argument. If not, default path would be used.
try
{
ci = ProgramInput.DeserializeJsonToStruct(args.Length > 0 ? args[0] : null);
}
catch (IOException e)
{
Console.WriteLine($"Could not read argument file: {e.Message}");
return;
}
amt = AMTInstanceFactory.CreateEX(ci);
}
catch (ManageabilityException e)
{
ci?.Dispose();
Console.WriteLine(e.Message);
return;
}
try
{
// When creating an agent that is related to the EventManager feature, EventManager sends an event when Agent.eventOnTransition equals true.
// The event that was sent contains only the first 6 characters of the agent's name.
// Therefore, we recommend naming an agent with max length of 6 characters,
// otherwise the event that will be sent will include only the first part of the agent's name.
// Create Agent
AgentPresenceRemoteFunctionality.CreateOrUpdateAgent(amt, "Agent1");
// Create second Agent
AgentPresenceRemoteFunctionality.CreateOrUpdateAgent(amt, "Agent2");
// Get all Agents
AgentPresenceRemoteFunctionality.DisplayAgents(amt);
// Get Agent Presence capabilities
AgentPresenceRemoteFunctionality.DisplayCapabalities(amt);
// Get Agent by name
AgentPresenceRemoteFunctionality.GetAgent(amt, "Agent1");
// Set the policy for agent presence
AgentPresenceRemoteFunctionality.SetAgentPresencePolicy(amt);
// Get the policy from agent presence
AgentPresenceRemoteFunctionality.GetAgentPresencePolicy(amt);
// Remove the policy from agent presence
AgentPresenceRemoteFunctionality.RemoveAgentPresencePolicy(amt);
//Set expiration action on agent
AgentPresenceRemoteFunctionality.SetExpirationActionOnAgentPresenceWatchDog(amt, "Agent1");
// Delete specific agent
AgentPresenceRemoteFunctionality.DeleteAgent(amt, "Agent1");
// Delete specific agent
AgentPresenceRemoteFunctionality.DeleteAgent(amt, "Agent2");
// Delete all agents
AgentPresenceRemoteFunctionality.DeleteAllAgent(amt);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
amt?.Dispose();
}
}
}
}