152 lines
4.4 KiB
C#
152 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.Text;
|
|
|
|
namespace Intel.Management.Wsman
|
|
{
|
|
class WsmanFault : IWsmanFault
|
|
{
|
|
|
|
XmlDocument _fault;
|
|
XmlNamespaceManager _ns;
|
|
|
|
|
|
|
|
private WsmanFault(XmlDocument doc, XmlNamespaceManager ns)
|
|
{
|
|
_fault = doc;
|
|
_ns = ns;
|
|
|
|
}
|
|
|
|
public static IWsmanFault GetXmlFault(XmlDocument doc)
|
|
{
|
|
|
|
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
|
|
ns.AddNamespace("s", "http://www.w3.org/2003/05/soap-envelope");
|
|
ns.AddNamespace("wsman", "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd");
|
|
ns.AddNamespace("wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
|
|
ns.AddNamespace("wsen", "http://schemas.xmlsoap.org/ws/2004/09/enumeration");
|
|
ns.AddNamespace("wse", "http://schemas.xmlsoap.org/ws/2004/08/eventing");
|
|
ns.AddNamespace("wxf", "http://schemas.xmlsoap.org/ws/2004/09/transfer");
|
|
|
|
|
|
|
|
IWsmanFault f = new WsmanFault(doc, ns);
|
|
string value = f.Code;
|
|
value = f.Subcode;
|
|
value = f.Detail;
|
|
value = f.Reason;
|
|
value = f.Xml;
|
|
|
|
return f;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static IWsmanFault GetXmlFault(string fault)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.LoadXml(fault);
|
|
return GetXmlFault(doc);
|
|
}
|
|
|
|
protected bool GetSoapFault(XmlNode node,out string fault, out string value)
|
|
{
|
|
if (node != null)
|
|
{
|
|
char[] splits={':'};
|
|
if (node.InnerText != null)
|
|
{
|
|
string[] tokens = node.InnerText.Split(splits, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (tokens.Length > 1)
|
|
{
|
|
string[] faults = { "s", "wsa", "wsman", "wsen", "wse", "wxf" };
|
|
foreach (string faultType in faults)
|
|
if (_ns.LookupNamespace(faultType).Equals(
|
|
_fault.DocumentElement.GetNamespaceOfPrefix(tokens[0])))
|
|
{
|
|
fault = faultType;
|
|
value = tokens[1];
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
fault = null;
|
|
value=null;
|
|
return false;
|
|
|
|
}
|
|
|
|
public string Code
|
|
{
|
|
get
|
|
{
|
|
XmlNode node = _fault.SelectSingleNode("s:Envelope/s:Body/s:Fault/s:Code/s:Value", _ns);
|
|
if (node != null)
|
|
{
|
|
string value;
|
|
string type;
|
|
if (GetSoapFault(node,out type,out value))
|
|
return value;
|
|
return node.InnerText;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string Subcode
|
|
{
|
|
get
|
|
{
|
|
XmlNode node = _fault.SelectSingleNode("s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", _ns);
|
|
if (node != null)
|
|
{
|
|
string value;
|
|
string type;
|
|
if (GetSoapFault(node, out type, out value))
|
|
return value;
|
|
return node.InnerText;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string Detail
|
|
{
|
|
get
|
|
{
|
|
XmlNode node = _fault.SelectSingleNode("s:Envelope/s:Body/s:Fault/s:Detail", _ns);
|
|
if (node != null)
|
|
return node.InnerText;
|
|
return null;
|
|
}
|
|
}
|
|
public string Reason
|
|
{
|
|
get
|
|
{
|
|
XmlNode node = _fault.SelectSingleNode("s:Envelope/s:Body/s:Fault/s:Reason", _ns);
|
|
if (node != null)
|
|
return node.InnerText;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string Xml
|
|
{
|
|
get
|
|
{
|
|
XmlNode node = _fault.SelectSingleNode("s:Envelope/s:Body", _ns);
|
|
if (node != null)
|
|
return node.InnerXml;
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|
|
}
|