130 lines
4.5 KiB
C#
130 lines
4.5 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011 - 2014 All Rights Reserved.
|
|
//
|
|
// File: UserConsentFunctionality.cs
|
|
//
|
|
// Contents: Demonstrate the UserConsent interface.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Reflection;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.Exceptions;
|
|
using Intel.Manageability.Power;
|
|
using Intel.Manageability.UserConsent;
|
|
|
|
namespace UserConsentSample2
|
|
{
|
|
class UserConsentFunctionality
|
|
{
|
|
public static void GetUserConsentSettings(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
UserConsentSettings userConsentSettings = amt.UserConsent.GetSettings();
|
|
PrintSettings(userConsentSettings);
|
|
}
|
|
catch (UserConsentManageabilityException e)
|
|
{
|
|
PrintException("GetUserConsentSettings", e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void SetUserConsentSettings(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
UserConsentSettings userConsentSettings = new UserConsentSettings(120, 300, FeaturesRequiringConsent.All);
|
|
amt.UserConsent.SetSettings(userConsentSettings);
|
|
Console.WriteLine("Set User Consent Settings successfully.");
|
|
}
|
|
catch (UserConsentManageabilityException e)
|
|
{
|
|
PrintException("SetUserConsentSettings", e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void GetSpriteLanguage(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
SpriteLanguageSettings spriteLanguageSettings = amt.UserConsent.Local.GetSpriteLanguage();
|
|
Console.WriteLine("Get Sprite Language successfully.");
|
|
}
|
|
catch (UserConsentManageabilityException e)
|
|
{
|
|
PrintException("GetSpriteLanguage", e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void SetSpriteLanguage(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
amt.UserConsent.Local.SetSpriteLanguage(SpriteLanguage.French, Fallback.PreviousLanguage);
|
|
Console.WriteLine("Set Sprite Language successfully.");
|
|
}
|
|
catch (UserConsentManageabilityException e)
|
|
{
|
|
PrintException("SetSpriteLanguage", e);
|
|
}
|
|
|
|
}
|
|
|
|
private static void PrintSettings(UserConsentSettings userConsentSettings)
|
|
{
|
|
string featuresName = GetEnumDescription(userConsentSettings.FeaturesRequiringConsent);
|
|
|
|
Console.WriteLine(" User Consent Settings:");
|
|
Console.WriteLine(" ======================");
|
|
Console.WriteLine(" Display Timeout : {0}", userConsentSettings.DisplayTimeout);
|
|
Console.WriteLine(" Session Timeout : {0}", userConsentSettings.SessionTimeout);
|
|
Console.WriteLine(" Interval : {0}", featuresName);
|
|
if (userConsentSettings.CanDisableUserConsent.HasValue)
|
|
Console.WriteLine(" Can Disabled User Consent : {0}", userConsentSettings.CanDisableUserConsent.Value.ToString());
|
|
Console.WriteLine();
|
|
}
|
|
|
|
static void PrintException(string methodName, UserConsentManageabilityException 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- Tip : {0}", e.Tip);
|
|
Console.Write("\n");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return the enum description attribute
|
|
/// </summary>
|
|
/// <param name="eValue"></param>
|
|
/// <returns></returns>
|
|
private static string GetEnumDescription(Enum eValue)
|
|
{
|
|
FieldInfo finfo = eValue.GetType().GetField(eValue.ToString());
|
|
DescriptionAttribute[] attr = (DescriptionAttribute[])finfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
if (attr.Length != 0)
|
|
{
|
|
return attr[0].Description;
|
|
}
|
|
else
|
|
{
|
|
return eValue.ToString();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|