public async Task <DownloadLinkResult> getDownloadLinks(string updateIdentity, int revisionNumber, bool useMSAToken)
        {
            try
            {
                string request = buildDownloadLinkRequest(updateIdentity, revisionNumber, useMSAToken);
                string ret     = await doHttpRequest(SECURED_URL, request);

                Xml.Save("Result.xml", ret);
                XDocument          doc           = XDocument.Parse(ret);
                var                envelope      = Xml.first_node_or_throw(doc.Root, NAMESPACE_SOAP + "Envelope");
                var                body          = Xml.first_node_or_throw(envelope, NAMESPACE_SOAP + "Body");
                var                resp          = Xml.first_node_or_throw(body, NAMESPACE_WU_SERVICE + "GetExtendedUpdateInfo2Response");
                var                res           = Xml.first_node_or_throw(resp, NAMESPACE_WU_SERVICE + "GetExtendedUpdateInfo2Result");
                var                fileLocations = Xml.first_node_or_throw(res, NAMESPACE_WU_SERVICE + "FileLocations");
                DownloadLinkResult data;
                data.files = new List <FileLocation>();
                for (var it = Xml.first_node(fileLocations, NAMESPACE_WU_SERVICE + "FileLocation"); it != null; it = Xml.next_sibling(it, NAMESPACE_WU_SERVICE + "FileLocation"))
                {
                    FileLocation info;
                    info.url = Xml.first_node_or_throw(it, NAMESPACE_WU_SERVICE + "Url").Value;
                    data.files.Add(info);
                }
                return(data);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to Find Download Links", ex);
            }
        }
            public void addXmlInfo(string val)
            {
                var       rooted_val  = "<root>" + val + "</root>";
                XDocument xmlDocument = XDocument.Parse(rooted_val);

                if (xmlDocument == null)
                {
                    return;
                }

                var identity = Xml.first_node(xmlDocument.Root, "UpdateIdentity");

                if (identity == null)
                {
                    return;
                }
                var attr = Xml.first_attribute(identity, "UpdateID");

                if (attr != null)
                {
                    updateId = attr.Value;
                }

                var applicability = Xml.first_node(xmlDocument.Root, "ApplicabilityRules");
                var metadata      = applicability != null?Xml.first_node(applicability, "Metadata") : null;

                if (metadata != null)
                {
                    var metadataPkgAppx = Xml.first_node(metadata, "AppxPackageMetadata");
                    if (metadataPkgAppx != null)
                    {
                        var metadataAppx = Xml.first_node(metadataPkgAppx, "AppxMetadata");
                        if (metadataAppx != null)
                        {
                            attr = Xml.first_attribute(metadataAppx, "PackageMoniker");
                            if (attr != null)
                            {
                                packageMoniker = attr.Value;
                            }
                        }
                    }
                }
            }
        public async Task <SyncResult> syncVersion(CookieData cookie, bool useMSAToken)
        {
            string request = buildSyncRequest(cookie, useMSAToken);
            string ret     = await doHttpRequest(PRIMARY_URL, request);

            XDocument doc = XDocument.Parse(ret);

            try
            {
                var        envelope   = Xml.first_node_or_throw(doc.Root, NAMESPACE_SOAP + "Envelope");
                var        body       = Xml.first_node_or_throw(envelope, NAMESPACE_SOAP + "Body");
                var        resp       = Xml.first_node_or_throw(body, NAMESPACE_WU_SERVICE + "SyncUpdatesResponse");
                var        res        = Xml.first_node_or_throw(resp, NAMESPACE_WU_SERVICE + "SyncUpdatesResult");
                var        newUpdates = Xml.first_node_or_throw(res, NAMESPACE_WU_SERVICE + "NewUpdates");
                SyncResult data       = new SyncResult();
                for (var it = Xml.first_node(newUpdates, NAMESPACE_WU_SERVICE + "UpdateInfo"); it != null; it = Xml.next_sibling(it, NAMESPACE_WU_SERVICE + "UpdateInfo"))
                {
                    UpdateInfo info = new UpdateInfo();
                    info.serverId = Xml.first_node_or_throw(it, NAMESPACE_WU_SERVICE + "ID").Value;
                    info.addXmlInfo(Xml.first_node_or_throw(it, NAMESPACE_WU_SERVICE + "Xml").Value);
                    data.newUpdates.Add(info);
                }

                var newCookie = Xml.first_node(res, NAMESPACE_WU_SERVICE + "NewCookie");
                if (newCookie != null)
                {
                    data.newCookie.encryptedData = Xml.first_node_or_throw(newCookie, NAMESPACE_WU_SERVICE + "EncryptedData").Value;
                    data.newCookie.expiration    = Xml.first_node_or_throw(newCookie, NAMESPACE_WU_SERVICE + "Expiration").Value;
                }
                return(data);
            }
            catch (Exception e)
            {
                maybeThrowSOAPFault(doc);
                throw e;
            }
        }