using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using Intel.Management.Wsman; namespace Intel.Management.PSModule.Amt { public class AmtException : Exception { public AmtException(string message) : base(message) { } public static void ThrowInvokeError(IManagedInstance resultObj) { ThrowInvokeError(resultObj, null); } public static void ThrowInvokeError(IManagedInstance resultObj,string message) { StringBuilder builder = new StringBuilder(); builder.Append(resultObj.SimpleName); builder.Append(".ReturnValue="); builder.Append(resultObj.GetProperty("ReturnValue").ToString()); if (message != null) { builder.Append(" "); builder.Append(message); } throw new AmtException(builder.ToString()); } public static void CheckResult(IManagedInstance resultObj) { string returnValue = resultObj.GetProperty("ReturnValue").ToString(); if (!returnValue.Equals("0")) { StringBuilder message = new StringBuilder(); message.Append(resultObj.SimpleName); message.Append(".ReturnValue="); message.Append(returnValue); XmlDocument doc = new XmlDocument(); doc.LoadXml(Properties.Resources.StatusCodesXML); XmlNode node=doc.DocumentElement.SelectSingleNode( string.Format("StatusCode[@Code=\"{0}\"]",returnValue)); if (node != null) { message.Append(" "); message.Append(node.InnerText); } throw new AmtException(message.ToString()); } } } }