147 lines
3.9 KiB
C#
147 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using System.Xml;
|
|
|
|
namespace Intel.Management.PSModule.Amt
|
|
{
|
|
|
|
class MessageFormat : IFormatProvider
|
|
{
|
|
object _format;
|
|
|
|
public MessageFormat() {}
|
|
public object GetFormat(Type formatType)
|
|
{
|
|
if (formatType.Equals(typeof(AmtMessageLogEntry)))
|
|
{
|
|
if (_format == null)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.LoadXml(
|
|
Intel.Management.PSModule.Properties.Resources.EventDataXML);
|
|
|
|
_format = doc;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new FormatException();
|
|
}
|
|
|
|
return _format;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class AmtMessageLogEntry
|
|
{
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
|
|
internal struct AMT_EVENT_RECORD
|
|
{
|
|
|
|
public UInt32 TimeStamp; // little endian
|
|
public byte DeviceAddress;
|
|
public byte EventSensorType;
|
|
public byte EventType;
|
|
public byte EventOffset;
|
|
public byte EventSourceType;
|
|
public byte EventSeverity;
|
|
public byte SensorNumber;
|
|
public byte Entity;
|
|
public byte EntityInstance;
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
|
public byte[] EventData;
|
|
}
|
|
|
|
AMT_EVENT_RECORD _interalRec;
|
|
string _message;
|
|
string _source;
|
|
|
|
private AmtMessageLogEntry(AMT_EVENT_RECORD rec,string message,string source)
|
|
{
|
|
_interalRec = rec;
|
|
_message = message;
|
|
_source = source;
|
|
}
|
|
|
|
public string Severity
|
|
{
|
|
get
|
|
{
|
|
|
|
return _interalRec.EventSeverity.ToString();
|
|
}
|
|
}
|
|
|
|
public DateTime TimeStamp
|
|
{
|
|
get
|
|
{
|
|
DateTime time = new DateTime(1970, 1, 1);
|
|
//time.ToShortDateString
|
|
//time.ToShortTimeString()
|
|
return time.AddSeconds((double)_interalRec.TimeStamp);
|
|
}
|
|
}
|
|
|
|
public string Source
|
|
{
|
|
get
|
|
{
|
|
return _source;
|
|
}
|
|
}
|
|
|
|
public string Message
|
|
{
|
|
get
|
|
{
|
|
return _message;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public static XmlDocument LoadMessageData()
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.LoadXml(
|
|
Intel.Management.PSModule.Properties.Resources.EventDataXML);
|
|
|
|
return doc;
|
|
}
|
|
|
|
public static AmtMessageLogEntry CreateFromPtr(IntPtr ptr,IFormatProvider provider )
|
|
{
|
|
AMT_EVENT_RECORD rec = (AMT_EVENT_RECORD)Marshal.PtrToStructure(ptr, typeof(AMT_EVENT_RECORD));
|
|
string[] args = { rec.EventSensorType.ToString(),
|
|
rec.EventOffset.ToString(),
|
|
rec.EventData[1].ToString(), };
|
|
|
|
XmlDocument eventDoc = (XmlDocument)provider.GetFormat(typeof(AmtMessageLogEntry));
|
|
|
|
XmlNode srcNode = eventDoc.DocumentElement.SelectSingleNode( string.Format(
|
|
"EventSource[@Entity=\"{0}\"]",rec.Entity));
|
|
|
|
XmlNode msgNode = eventDoc.DocumentElement.SelectSingleNode( string.Format(
|
|
"EventData[@Type=\"{0}\" and @Offset=\"{1}\" and @Data2=\"{2}\"]",args));
|
|
|
|
string source = rec.EventSourceType.ToString();
|
|
string message = string.Empty;
|
|
|
|
if (srcNode != null)
|
|
source = srcNode.InnerText;
|
|
if (msgNode != null)
|
|
message = msgNode.InnerText;
|
|
|
|
return new AmtMessageLogEntry(rec, message,source);
|
|
}
|
|
}
|
|
}
|