Esempio n. 1
0
        /// <summary>
        /// Parses the lobby contract.
        /// </summary>
        /// <returns>kObixResultSuccess on success, another value otherwise.</returns>
        /// <param name="doc">An XDocument from the server.</param>
        private ObixResult ParseLobbyContract(XDocument doc)
        {
            XElement rootNode = null;
            XElement lobby    = null;

            if (doc == null)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientInputError,
                                       "ParseLobbyContract got passed a null document."));
            }

            rootNode = doc.Root;
            if (rootNode == null)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLParseError,
                                       "Could not locate the root element in the provided XML document."));
            }

            if (rootNode.Name.LocalName == "obj" && rootNode.ObixIs().Contains("obix:Lobby"))
            {
                lobby = rootNode;
            }

            foreach (XElement element in rootNode.Descendants())
            {
                XAttribute isAttr    = null;
                XAttribute hrefAttr  = null;
                string     isValue   = null;
                string     hrefValue = null;

                if (element == null || element.HasAttributes == false)
                {
                    continue;
                }

                isAttr = element.Attribute("is");
                if (isAttr == null || string.IsNullOrEmpty(isAttr.Value) == true)
                {
                    continue;
                }

                isValue  = isAttr.Value;
                hrefAttr = element.Attribute("href");

                if (hrefAttr != null && string.IsNullOrEmpty(hrefAttr.Value) == false)
                {
                    hrefValue = hrefAttr.Value;
                }

                if (string.IsNullOrEmpty(hrefValue) == false)
                {
                    if (isValue.Contains("obix:Lobby") == true)
                    {
                        lobby = element;
                    }
                    else if (isValue.Contains("obix:WatchService") == true)
                    {
                        WatchUri = LobbyUri.Concat(hrefValue);
                    }
                    else if (isValue.Contains("obix:About") == true)
                    {
                        AboutUri = LobbyUri.Concat(hrefValue);
                    }
                }
            }

            if (lobby == null)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLElementNotFoundError,
                                       "ParseLobbyContract could not find the oBIX Lobby in the response."));
            }

            foreach (XElement lobbyElement in lobby.Elements())
            {
                if (lobbyElement.HasAttributes && lobbyElement.ObixIn() == "obix:BatchIn" && lobbyElement.ObixOut() == "obix:BatchOut")
                {
                    BatchUri = LobbyUri.Concat(lobbyElement.ObixHref());
                }
            }

            //batchService = lobby.XPathSelectElement(".//op[@in=\"obix:BatchIn\" and @out=\"obix:BatchOut\"]");
            //if (batchService != null && batchService.Attribute("href") != null) {
            //    BatchUri = LobbyUri.Concat(batchService.Attribute("href").Value);
            //}

            if (BatchUri != null)
            {
                batchClient = new XmlBatchClient(this);
            }

            return(ObixResult.kObixClientSuccess);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses the lobby contract.
        /// </summary>
        /// <returns>kObixResultSuccess on success, another value otherwise.</returns>
        /// <param name="doc">An XDocument from the server.</param>
        private ObixResult ParseLobbyContract(XDocument doc) {
            XElement rootNode = null;
            XElement lobby = null;

            if (doc == null) {
                return ErrorStack.Push(this.GetType(), ObixResult.kObixClientInputError,
                    "ParseLobbyContract got passed a null document.");
            }

            rootNode = doc.Root;
            if (rootNode == null) {
                return ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLParseError,
                    "Could not locate the root element in the provided XML document.");
            }

            if (rootNode.Name.LocalName == "obj" && rootNode.ObixIs().Contains("obix:Lobby")) {
                lobby = rootNode;
            }

            foreach (XElement element in rootNode.Descendants()) {
                XAttribute isAttr = null;
                XAttribute hrefAttr = null;
                string isValue = null;
                string hrefValue = null;

                if (element == null || element.HasAttributes == false) {
                    continue;
                }

				isAttr = element.Attribute("is");
                if (isAttr == null || string.IsNullOrEmpty(isAttr.Value) == true) {
                    continue;
                }

                isValue = isAttr.Value;
                hrefAttr = element.Attribute("href");

                if (hrefAttr != null && string.IsNullOrEmpty(hrefAttr.Value) == false) {
                    hrefValue = hrefAttr.Value;
                }

                if (string.IsNullOrEmpty(hrefValue) == false) {
                    if (isValue.Contains("obix:Lobby") == true) {
                        lobby = element;
                    } else if (isValue.Contains("obix:WatchService") == true) {
                        WatchUri = LobbyUri.Concat(hrefValue);

                    } else if (isValue.Contains("obix:About") == true) {
                        AboutUri = LobbyUri.Concat(hrefValue);
                    }
                }
            }

            if (lobby == null) {
                return ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLElementNotFoundError,
                    "ParseLobbyContract could not find the oBIX Lobby in the response.");
            }

            foreach (XElement lobbyElement in lobby.Elements()) {
                if (lobbyElement.HasAttributes && lobbyElement.ObixIn() == "obix:BatchIn" && lobbyElement.ObixOut() == "obix:BatchOut") {
                    BatchUri = LobbyUri.Concat(lobbyElement.ObixHref());
                }
            }

            //batchService = lobby.XPathSelectElement(".//op[@in=\"obix:BatchIn\" and @out=\"obix:BatchOut\"]");
            //if (batchService != null && batchService.Attribute("href") != null) {
            //    BatchUri = LobbyUri.Concat(batchService.Attribute("href").Value);
            //}

            if (BatchUri != null) {
                batchClient = new XmlBatchClient(this);
            }

            return ObixResult.kObixClientSuccess;
        }