Пример #1
0
        /// <summary>
        /// Parses the About contract after a client successfully connects and downloads the lobby contract.
        /// </summary>
        /// <returns>kObixClientSuccess if the operation succeeded, another value otherwise.</returns>
        private ObixResult ParseAboutContract()
        {
            ObixResult <XElement> data  = null;
            ObixAbout             about = null;

            if (WebClient == null || AboutUri == null)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientInputError,
                                       "WebClient is nothing, or the oBIX:About URI could not be found from the lobby contract."));
            }

            data = ReadUriXml(AboutUri);
            if (data.ResultSucceeded == false)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLParseError,
                                       "ParseAboutContract received an error from ReadUriXml."));
            }

            about = ObixAbout.FromXElement(data.Result);
            if (about == null)
            {
                return(ErrorStack.Push(this.GetType(), ObixResult.kObixClientXMLParseError,
                                       "ParseAboutContract could not parse the obix:About contract."));
            }

            this.About = about;

            return(ObixResult.kObixClientSuccess);
        }
Пример #2
0
        /// <summary>
        /// Converts a provided obix:About XElement contract into an ObixAbout instance.
        /// </summary>
        /// <param name="parentElement">An instance an oBIX:About contract</param>
        /// <returns>An ObixAbout object if conversion succeeded, null if an error was encountered.</returns>
        public static ObixAbout FromXElement(XElement parentElement)
        {
            ObixAbout about          = null;
            string    name           = null;
            string    val            = null;
            string    version        = null;
            string    serverName     = null;
            string    serverTime     = null;
            string    serverBootTime = null;
            string    vendorName     = null;
            string    vendorUrl      = null;
            string    productName    = null;
            string    productVersion = null;
            string    productUrl     = null;

            if (parentElement == null ||
                parentElement.Name.LocalName != "obj" ||
                parentElement.Attribute("is") == null ||
                string.IsNullOrEmpty(parentElement.Attribute("is").Value) == true ||
                parentElement.Attribute("is").Value != "obix:About")
            {
                return(null);
            }

            foreach (XElement child in parentElement.Elements())
            {
                if (child.IsNullOrNullContract() || child.HasObixValue() == false ||
                    string.IsNullOrEmpty(child.ObixName()) == true)
                {
                    continue;
                }

                name = child.ObixName();
                val  = child.ObixValue();

                switch (name)
                {
                case "obixVersion":
                    version = val;
                    break;

                case "serverName":
                    serverName = val;
                    break;

                case "serverTime":
                    serverTime = val;
                    break;

                case "serverBootTime":
                    serverBootTime = val;
                    break;

                case "vendorName":
                    vendorName = val;
                    break;

                case "vendorUrl":
                    vendorUrl = val;
                    break;

                case "productName":
                    productName = val;
                    break;

                case "productVersion":
                    productVersion = val;
                    break;

                case "productUrl":
                    productUrl = val;
                    break;

                default: break;
                }
            }

            about = new ObixAbout()
            {
                ProductName    = productName,
                ProductUrl     = productUrl,
                ProductVersion = productVersion,
                ServerBootTime = serverBootTime,
                ServerName     = serverName,
                ServerTime     = serverTime,
                VendorName     = vendorName,
                VendorUrl      = vendorUrl,
                Version        = version
            };

            return(about);
        }
Пример #3
0
        /// <summary>
        /// Converts a provided obix:About XElement contract into an ObixAbout instance.
        /// </summary>
        /// <param name="parentElement">An instance an oBIX:About contract</param>
        /// <returns>An ObixAbout object if conversion succeeded, null if an error was encountered.</returns>
        public static ObixAbout FromXElement(XElement parentElement) {
            ObixAbout about = null;
            string name = null;
            string val = null;
            string version = null;
            string serverName = null;
            string serverTime = null;
            string serverBootTime = null;
            string vendorName = null;
            string vendorUrl = null;
            string productName = null;
            string productVersion = null;
            string productUrl = null;

            if (parentElement == null 
                || parentElement.Name.LocalName != "obj" 
                || parentElement.Attribute("is") == null 
                || string.IsNullOrEmpty(parentElement.Attribute("is").Value) == true 
                || parentElement.Attribute("is").Value != "obix:About") {
                return null;
            }

            foreach (XElement child in parentElement.Elements()) {
                if (child.IsNullOrNullContract() || child.HasObixValue() == false 
                    || string.IsNullOrEmpty(child.ObixName()) == true) {
                    continue;
                }

                name = child.ObixName();
                val = child.ObixValue();

                switch (name) {
                    case "obixVersion":
                        version = val;
                        break;
                    case "serverName":
                        serverName = val;
                        break;
                    case "serverTime":
                        serverTime = val;
                        break;
                    case "serverBootTime":
                        serverBootTime = val;
                        break;
                    case "vendorName":
                        vendorName = val;
                        break;
                    case "vendorUrl":
                        vendorUrl = val;
                        break;
                    case "productName":
                        productName = val;
                        break;
                    case "productVersion":
                        productVersion = val;
                        break;
                    case "productUrl":
                        productUrl = val;
                        break;
                    default: break;
                }
            }

            about = new ObixAbout() {
                ProductName = productName,
                ProductUrl = productUrl,
                ProductVersion = productVersion,
                ServerBootTime = serverBootTime,
                ServerName = serverName,
                ServerTime = serverTime,
                VendorName = vendorName,
                VendorUrl = vendorUrl,
                Version = version
            };

            return about;
        }