コード例 #1
0
ファイル: Capabilities.cs プロジェクト: jstuyck/witsmllib
 /// <summary>
 /// Create a client capabilities object with the specified properties.
 /// </summary>
 /// <param name="version">WITSML version accepted by client. May be null.</param>
 /// <param name="contactName">Contact name. May be null.</param>
 /// <param name="contactEmail">Contact e-mail. May be null.</param>
 /// <param name="contactPhone">Contact phone number. May be null.</param>
 /// <param name="name">System product name. May be null.</param>
 /// <param name="description">System description. May be null.</param>
 /// <param name="vendor">System vendor. May be null.</param>
 /// <param name="programVersion">System version. May be null.</param>
 public Capabilities(WitsmlVersion version,
     String contactName,
     String contactEmail,
     String contactPhone,
     String name,
     String description,
     String vendor,
     String programVersion)
     : this(version, false, contactName, contactEmail, contactPhone,
          name, description, vendor, programVersion)
 {
 }
コード例 #2
0
ファイル: Capabilities.cs プロジェクト: jstuyck/witsmllib
        /// <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);
            }
        }
コード例 #3
0
ファイル: Capabilities.cs プロジェクト: jstuyck/witsmllib
 /// <summary>
 /// Create a capabilities object with the specified properties.
 /// </summary>
 /// <param name="version">WITSML version accepted by client. May be bull.</param>
 /// <param name="isServer">Indicates if this is a server (true) or client (false) capabilities instance.</param>
 /// <param name="contactName">Contact name for the site. May be null.</param>
 /// <param name="contactEmail">Contact e-mail for the site. May be null.</param>
 /// <param name="contactPhone">Contact phone for the site. May be null.</param>
 /// <param name="name">System product name. May be null.</param>
 /// <param name="description">System description. May be null.</param>
 /// <param name="vendor">System vendor. May be null.</param>
 /// <param name="programVersion">System version. May be null.</param>
 Capabilities(WitsmlVersion version,
     bool isServer,
     String contactName,
     String contactEmail,
     String contactPhone,
     String name,
     String description,
     String vendor,
     String programVersion)
 {
     this._isServer = isServer;
     this.functions = isServer ? new List<FunctionCapability>() : null;
     this.witsmlVersion = version != null ? version.getVersion() : null;
     this.contactName = contactName;
     this.contactEmail = contactEmail;
     this.contactPhone = contactPhone;
     this.name = name;
     this.description = description;
     this.vendor = vendor;
     this.programVersion = programVersion;
 }