Exemplo n.º 1
0
        private static MethodFault GetVIServerFault(FaultException soapEx)
        {
            if (soapEx == null)
            {
                throw new ArgumentNullException("soapEx");
            }
            PropertyInfo property = soapEx.GetType().GetTypeInfo().GetProperty("Detail");

            VimApi_65.MethodFault methodFault;
            if (property != (PropertyInfo)null)
            {
                methodFault = property.GetValue((object)soapEx) as VimApi_65.MethodFault;
            }
            else
            {
                MessageFault  messageFault  = soapEx.CreateMessageFault();
                XmlSerializer xmlSerializer = FaultUtility.GetFaultSerializer();
                if (xmlSerializer == null)
                {
                    /* XElement xelement = (XElement)XNode.ReadFrom((XmlReader)messageFault.GetReaderAtDetailContents());
                     * System.Type type = typeof(VimApi_65.MethodFault).Assembly.GetType(string.Format("{0}.{1}", (object)typeof(VimApi_65.MethodFault).Namespace, (object)xelement.Attribute(XName.Get("type", "http://www.w3.org/2001/XMLSchema-instance")).Value));
                     * XmlRootAttribute xmlRootAttribute = new XmlRootAttribute(xelement.Name.LocalName);
                     * // ISSUE: variable of the null type
                     * __Null local1 = null;
                     * // ISSUE: variable of the null type
                     * __Null local2 = null;
                     * XmlRootAttribute root = xmlRootAttribute;
                     * string defaultNamespace = "urn:vim25";
                     * xmlSerializer = new XmlSerializer(type, (XmlAttributeOverrides)local1, (System.Type[])local2, root, defaultNamespace); */
                    XElement         xElement   = (XElement)XNode.ReadFrom(messageFault.GetReaderAtDetailContents());
                    XAttribute       xAttribute = xElement.Attribute(XName.Get("type", "http://www.w3.org/2001/XMLSchema-instance"));
                    string           name       = string.Format("{0}.{1}", typeof(VimApi_65.MethodFault).Namespace, xAttribute.Value);
                    Type             arg_D0_0   = typeof(VimApi_65.MethodFault).Assembly.GetType(name);
                    XmlRootAttribute root       = new XmlRootAttribute(xElement.Name.LocalName);
                    xmlSerializer = new XmlSerializer(arg_D0_0, null, null, root, "urn:vim25");
                }
                StringReader stringReader = new StringReader(messageFault.GetDetail <XElement>().ToString().Replace("xsd:", ""));
                using (XmlReader xmlReader = XmlReader.Create((TextReader)stringReader, new XmlReaderSettings()
                {
                    ConformanceLevel = ConformanceLevel.Fragment,
                    CloseInput = true
                }))
                {
                    int content = (int)xmlReader.MoveToContent();
                    methodFault = xmlSerializer.Deserialize(xmlReader) as VimApi_65.MethodFault;
                }
            }
            return(VIConvert.ToVim((object)methodFault) as MethodFault);
        }