145 lines
4.9 KiB
C#
145 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Intel.Management.Wsman;
|
|
|
|
namespace Intel.Management.PSModule.Amt
|
|
{
|
|
class AlarmService : SettingsContainer
|
|
{
|
|
public AlarmService(DriveItem parent) :
|
|
base("AlarmClock", parent)
|
|
{
|
|
}
|
|
public TimeSpan AMTIntervalToTimeSpan(string AMTInterval)
|
|
{
|
|
|
|
TimeSpan ts = new TimeSpan();
|
|
if (AMTInterval.Length > 0)
|
|
{
|
|
AMTInterval = AMTInterval.ToUpper();
|
|
if (AMTInterval[0] == 'P')
|
|
{
|
|
AMTInterval = AMTInterval.Substring(1); //Eat the P
|
|
//Check for days
|
|
if (AMTInterval.Contains('D'))
|
|
{
|
|
string days = AMTInterval.Substring(0, AMTInterval.IndexOf('D'));
|
|
ts = ts.Add(new TimeSpan(int.Parse(days), 0, 0, 0));
|
|
AMTInterval = AMTInterval.Substring(AMTInterval.IndexOf('D') + 1); //Eat the D
|
|
}
|
|
|
|
if (AMTInterval.Contains('T'))
|
|
{
|
|
AMTInterval = AMTInterval.Substring(AMTInterval.IndexOf('T') + 1); //Eat the T
|
|
}
|
|
|
|
if (AMTInterval.Contains('H'))
|
|
{
|
|
string hours = AMTInterval.Substring(0, AMTInterval.IndexOf('H'));
|
|
ts = ts.Add(new TimeSpan(int.Parse(hours), 0, 0));
|
|
AMTInterval = AMTInterval.Substring(AMTInterval.IndexOf('H') + 1); //Eat the H
|
|
}
|
|
|
|
if (AMTInterval.Contains('M'))
|
|
{
|
|
string mins = AMTInterval.Substring(0, AMTInterval.IndexOf('M'));
|
|
ts = ts.Add(new TimeSpan(0, int.Parse(mins), 0));
|
|
AMTInterval = AMTInterval.Substring(AMTInterval.IndexOf('M') + 1); //Eat the M
|
|
}
|
|
}
|
|
}
|
|
return ts;
|
|
}
|
|
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
|
|
_settingsObj=null;
|
|
_refToSettings=null;
|
|
|
|
IWsmanEnumeration colObj = conn.ExecQuery("SELECT * FROM AMT_AlarmClockService");
|
|
foreach (IWsmanItem item in colObj)
|
|
{
|
|
if (item.Object.GetProperty("Name").ToString().Equals("Intel(r) AMT Alarm Clock Service"))
|
|
{
|
|
// writer.Add(new AlarmTime(this));
|
|
string NextExecTime = null;
|
|
IWsmanItem NextExecItem = item.Object.GetProperty("NextAMTAlarmTime");
|
|
if (!NextExecItem.IsNull)
|
|
{
|
|
NextExecTime = NextExecItem.Object.Text;
|
|
writer.Add(new DriveEntry("AlarmTime", DateTime.Parse(NextExecTime).ToString(), this));
|
|
}
|
|
else
|
|
{
|
|
writer.Add(new DriveEntry("AlarmTime", "[none set]", this));
|
|
}
|
|
|
|
|
|
TimeSpan intervalTime = new TimeSpan(0);
|
|
IWsmanItem IntervalItem = item.Object.GetProperty("AMTAlarmClockInterval");
|
|
if (!IntervalItem.IsNull)
|
|
{
|
|
string interval = IntervalItem.Object.Text;
|
|
intervalTime = AMTIntervalToTimeSpan(interval);
|
|
writer.Add(new DriveEntry("AlarmInterval", intervalTime.ToString(), this));
|
|
|
|
}
|
|
else
|
|
{
|
|
writer.Add(new DriveEntry("AlarmInterval", "[none set]", this));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class AlarmTime : SettingsItem
|
|
{
|
|
|
|
public AlarmTime(SettingsContainer parent)
|
|
: base("AlarmTime", parent)
|
|
{
|
|
DateTime dt;
|
|
if (!DateTime.TryParse(parent.GetSetting("AlarmTime"), out dt))
|
|
{
|
|
//Failed
|
|
_value = "Error Loading Value";
|
|
}
|
|
else
|
|
{
|
|
// int sec = int.Parse(parent.GetSetting("OptInPolicyTimeout"));
|
|
_value = dt;
|
|
}
|
|
|
|
_value = "Error Loading Value";
|
|
}
|
|
|
|
public override void SetItem(object values, DriveProvider provider)
|
|
{
|
|
|
|
AlarmService service = _parent as AlarmService;
|
|
|
|
DateTime dt = (DateTime)values;
|
|
|
|
//TimeSpan span = TimeSpan.Parse(values.ToString());
|
|
|
|
service.SetSetting("AlarmTime", "2011-12-25T23:35:00Z");
|
|
|
|
// _value = span;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}// end AlarmService
|
|
}
|