예제 #1
0
        /// <summary>
        /// Add function capabilities to this capabilities instance.
        /// Functions are a property of the server only and is not used
        /// with client capabilities.
        /// </summary>
        /// <param name="function">Function capabilties to add.</param>
        void addFunction(FunctionCapability function)
        {
            if (function == null)
            {
                throw new ArgumentException("function cannot be null");
            }

            if (_isServer)
            {
                functions.Add(function);
            }
            else
            {
                throw new Exception("functions are only supported for server capabilities");
            }
        }
예제 #2
0
        /// <summary>
        /// Create a capabilities instance by parsing the specified WITSML string.
        /// </summary>
        /// <param name="version">XML defining the capabilities.</param>
        /// <param name="xml"></param>
        internal Capabilities(WitsmlVersion version, String xml)
        {
            if (version == null)
            {
                throw new ArgumentException("version cannot be null.");
            }
            if (xml == null)
            {
                throw new ArgumentException("xml cannot be null");
            }

            String witsmlVersionTmp  = null;
            String contactNameTmp    = null;
            String contactEmailTmp   = null;
            String contactPhoneTmp   = null;
            String nameTmp           = null;
            String descriptionTmp    = null;
            String vendorTmp         = null;
            String programVersionTmp = null;

            //SAXBuilder builder = new SAXBuilder();

            try
            {
                XDocument document = XDocument.Load(new StringReader(xml));
                XElement  root     = document.Root; //.getRootElement();
                //Debug.Assert(root != null; //TODO: Can this happen? Throw illegal arg exception?

                XNamespace @namespace       = root.Name.Namespace;                    //.getNamespace();
                XElement   capServerElement = root.Element(@namespace + "capServer"); //, @namespace);
                XElement   capClientElement = root.Element(@namespace + "capClient"); //, @namespace);

                _isServer = capServerElement != null;
                functions = _isServer ? new List <FunctionCapability>() : null;

                XElement capElement = _isServer ? capServerElement : capClientElement;

                if (capElement != null)
                {
                    witsmlVersionTmp = capElement.Attribute("apiVers").Value;

                    XElement contactElement = capElement.Element(@namespace + "contact");//, @namespace);
                    if (contactElement != null)
                    {
                        contactNameTmp  = contactElement.Element(contactElement.Name.Namespace + "name").Value.Trim();  //, contactElement.Name.Namespace.getNamespace());
                        contactEmailTmp = contactElement.Element(contactElement.Name.Namespace + "email").Value.Trim(); //, contactElement.getNamespace());
                        contactPhoneTmp = contactElement.Element(contactElement.Name.Namespace + "phone").Value.Trim(); //, contactElement.getNamespace());
                    }

                    nameTmp           = capElement.Element(capElement.Name.Namespace + "name").Value;        //, capElement.getNamespace());
                    descriptionTmp    = capElement.Element(capElement.Name.Namespace + "description").Value; //, capElement.getNamespace());
                    vendorTmp         = capElement.Element(capElement.Name.Namespace + "vendor").Value;      //, capElement.getNamespace());
                    programVersionTmp = capElement.Element(capElement.Name.Namespace + "version").Value;     //, capElement.getNamespace());

                    var functionElements = capElement.Elements(@namespace + "function");                     //, @namespace);

                    foreach (XElement functionElement in functionElements)
                    {
                        String functionName    = functionElement.Attribute("name").Value;
                        String functionVersion = functionElement.Attribute("apiVers").Value;

                        FunctionCapability function = new FunctionCapability(functionName, functionVersion);

                        var dataObjectElements = functionElement.Elements(@namespace + "dataObject");

                        foreach (XElement dataObjectElement in dataObjectElements)
                        {
                            String dataObject = dataObjectElement.Value.Trim();
                            function.addWitsmlType(dataObject);
                        }
                        addFunction(function);
                    }
                }

                witsmlVersion  = witsmlVersionTmp;
                contactName    = contactNameTmp;
                contactEmail   = contactEmailTmp;
                contactPhone   = contactPhoneTmp;
                name           = nameTmp;
                description    = descriptionTmp;
                vendor         = vendorTmp;
                programVersion = programVersionTmp;
            }

            catch (IOException exception)
            {
                // Convert to a non-IO exception to hide implementation details of this class.
                throw new WitsmlParseException(xml, exception);
            }
            catch (Exception /*JDOMException */ exception)
            {
                // Convert to a non-JDOM exception to hide implementation details of this class.
                throw new WitsmlParseException(xml, exception);
            }
        }