Beispiel #1
0
        protected Object _extensionNameValue; //cs_extensionNameValue

        protected WitsmlWellboreGeometrySection(WitsmlServer server,
                                                String id, String name,
                                                WitsmlObject parent, String parentId)

            : base(server, WITSML_TYPE, id, name, parent, parentId)
        {
        }
Beispiel #2
0
        /// <summary>
        /// Return child of the given class and parent with the given ID from this server.
        /// </summary>
        /// <typeparam name="T">Type of the Class to return. Non-null.</typeparam>
        /// <param name="witsmlQuery"> Query to apply. Non-null.</param>
        /// <param name="id">ID of instance to get. Non-null.</param>
        /// <param name="parent">Parent instance of child to get. Non-null</param>
        /// <returns>The requested instance, or null if not found.</returns>
        public T getOne <T>(WitsmlQuery witsmlQuery, String id, WitsmlObject parent) where T : WitsmlObject
        {
            if (witsmlQuery == null)
            {
                throw new ArgumentNullException("witsmlQuery cannot be null");
            }

            if (id == null)
            {
                throw new ArgumentNullException("id cannot be null");
            }

            if (parent == null)
            {
                throw new ArgumentNullException("parent cannot be null");
            }

            List <T> objects = get <T>(witsmlQuery, id, parent);

            if (objects.Count > 1)
            {
                throw new WitsmlServerException("Multiple instances with ID = " + id, null);
            }

            return(objects.Count == 0 ? default(T) : objects[0]);
        }
        protected String azimuthReference;                                                                  // aziRef

        /**
         * Create a trajectory object with specified ID and parent.
         *
         * @param id        ID of this trajectory.
         * @param wellbore  Parent wellbore of this trajectory.
         */
        protected WitsmlTrajectory(WitsmlServer server,
                                   String id, String name,
                                   WitsmlObject parent, String parentId)

            : base(server, WITSML_TYPE, id, name, parent, parentId)
        {
        }
Beispiel #4
0
        /// <summary>
        /// Return all children of the given class from the specified parent instance.
        /// </summary>
        /// <typeparam name="T">Type of the Class to return. Non-null.</typeparam>
        /// <param name="witsmlQuery">Query to apply. Non-null.</param>
        /// <param name="parent">Parent instance. May be null, to indicate root-level.</param>
        /// <returns>Requested instances. Never null.</returns>
        public List <T> get <T>(WitsmlQuery witsmlQuery, WitsmlObject parent) where T : WitsmlObject
        {
            if (witsmlQuery == null)
            {
                throw new ArgumentNullException("witsmlQuery cannot be null");
            }

            return(get <T>(witsmlQuery, null, parent));
        }
Beispiel #5
0
        /// <summary>
        /// Get ancestor IDs from the specified instance and up the hierarchy.
        /// </summary>
        /// <param name="instance">Instance to start with. Non-null.</param>
        /// <returns>IDs starting with ID of given instance and upwards.</returns>
        private static String[] getIds(WitsmlObject instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance cannot be null");
            }

            List <String> ids = new List <String>();

            WitsmlObject p = instance;

            while (p != null)
            {
                ids.Add(p.getId());
                p = p.getParent();
            }

            return(ids.ToArray());
        }
Beispiel #6
0
        /** {@inheritDoc} */

        //public int hashCode() {
        //    return id != null ? id.hashCode() : base.hashCode();
        //}

        /**
         * Check if the specified object is equal to this instance.
         * The two are equal if they are the same instance or if their ID matches.
         *
         * @param object  Object to check against. May be null.
         * @return        True if this and the specified object are equal, false otherwise.
         */
        public override bool Equals(Object @object)
        {
            if (@object == this)
            {
                return(true);
            }
            if (@object == null)
            {
                return(false);
            }
            if (!(@object is WitsmlObject))
            {
                return(false);
            }

            WitsmlObject witsmlObject = (WitsmlObject)@object;

            return(id == null ? @object == this : id.Equals(witsmlObject.id));
        }
Beispiel #7
0
        protected CommonData commonData;  //Common data of this instance. May be null

        /// <summary>
        /// Create a new WITSML object with specified properties.
        /// </summary>
        /// <param name="server">Server backing this instance. Non-null.</param>
        /// <param name="type">WITSML type of this instance. Non-null.</param>
        /// <param name="id">ID of this instance. Null if ID is not supported for this type.</param>
        /// <param name="name">Name of this instance. May be null if not loaded or not suppoerted for this type.</param>
        /// <param name="parent"></param>
        /// <param name="parentId"></param>
        protected WitsmlObject(WitsmlServer server,
                               String type, String id, String name, WitsmlObject parent,
                               String parentId)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server cannot be null");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type cannot be null");
            }

            this.server   = server;
            this.type     = type;
            this.id       = id;
            this.name     = name;
            this.parent   = parent;
            this.parentId = parent != null?parent.getId() : parentId;
        }
Beispiel #8
0
 public override String ToString()
 {
     return("\n" + WitsmlObject.ToString(this, 2));
 }
Beispiel #9
0
        /**
         * Create a well object with specified ID.
         *
         * @param id  ID of this well.
         */
        protected WitsmlWell(WitsmlServer server, String id, String name,
                             WitsmlObject parent)

            : base(server, WITSML_TYPE, id, name, parent, null)
        {
        }
        protected Int32?reportNumber; //numReport

        protected WitsmlFluidsReport(WitsmlServer server, String id, String name,
                                     WitsmlObject parent, String parentId)

            : base(server, WITSML_TYPE, id, name, parent, parentId)
        {
        }
Beispiel #11
0
        /// <summary>
        /// Create a realtime object with specified parent.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="id"></param>
        /// <param name="parent"></param>
        /// <param name="parentId"></param>
        protected WitsmlRealtime(WitsmlServer server, String id, WitsmlObject parent, String parentId)

            : base(server, WITSML_TYPE, id, null, parent, parentId)
        {
        }
Beispiel #12
0
        /**
         * Delete the specified instance from the WITSML server.
         *
         * @param instance  Instance to delete. Non-null.
         * @throws ArgumentException If instance is null.
         * @throws WitsmlServerException  If the server access failed for some reason.
         */
        public void delete(WitsmlObject instance)
        { //throws WitsmlServerException {
            if (instance == null)
            {
                throw new ArgumentException("instance cannot be null");
            }

            String wsdlFunction = "WMLS_DeleteFromStore";

            long requestTime = DateTime.Now.Ticks;// System.currentTimeMillis();

            String queryXml    = "";
            String responseXml = null;

            String type = instance.getWitsmlType();
            //Class<? extends WitsmlObject>
            var actualClass = getActualClass(version, type);

            String id       = instance.getId();
            String parentId = instance.getParentId() != null?instance.getParentId() : "";

            try
            {
                // Find the getQuery() method
                // Method getQueryMethod = instance.getClass().getDeclaredMethod("getQuery",
                //                                                             String.class,
                //                                                           String[].class);
                MethodInfo getQueryMethod = instance.GetType().GetMethod("getQuery"); //
                //getQueryMethod.setAccessible(true);

                // This is the complete query for the class
                queryXml = (String)getQueryMethod.Invoke(null, new Object[] { id, parentId });// (null, id, new String[] {parentId});

                // Filter the ID part only
                WitsmlQuery query = new WitsmlQuery();
                query.includeElement("name");
                queryXml = query.apply(queryXml);

                Console.WriteLine(queryXml); // System.out.println(queryXml);

                // Send the query to the WITSML server and pick the response
                WitsmlResponse response = accessor.delete(type, queryXml);

                notify(wsdlFunction, type, requestTime, queryXml, null,
                       response.getStatusCode(),
                       response.getServerMessage(),
                       null);
            }
            catch (MissingMethodException exception)
            { // NoSuchMethodException exception) {
              // Programmer error
              //Debug.Assert(false : "Method not found: " + instance;
            }
            catch (AccessViolationException exception)
            {// IllegalAccessException exception) {
             // Programmer error
             //Debug.Assert(false : "Unable to invoke: " + instance;
            }
            catch (TargetInvocationException exception)
            { // InvocationTargetException exception) {
                // Wrapped exception from the invocation such as WitsmlParseException
                notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
                       exception.InnerException);                                   //.getCause());
                String message = "Exception thrown by " + actualClass + ".newInstance()";
                throw new WitsmlServerException(message, exception.InnerException); //.getCause());
            }
            //catch (RemoteException exception) {
            //    // Connection problems.
            //    notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
            //           exception);
            //    String message = "Unable to connect to WITSML server: " + this;
            //    throw new WitsmlServerException(message, exception);
            //}
            catch (IOException exception)
            {
                // Unable to read response XML
                notify(wsdlFunction, type, requestTime, queryXml, null, null, null,
                       exception);
                String message = "Unable to read response XML: " + responseXml;
                throw new WitsmlServerException(message, exception);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Update the specified WITSML instance by making a new fetch from the server.
        /// </summary>
        /// <param name="witsmlObject">Instance to update. Non-null.</param>
        /// <param name="witsmlQuery"> Query to apply. Non-null.</param>
        public void update(WitsmlObject witsmlObject, WitsmlQuery witsmlQuery)
        {
            if (witsmlObject == null)
            {
                throw new ArgumentException("witsmlObject cannot be null");
            }

            if (witsmlQuery == null)
            {
                throw new ArgumentException("witsmlQuery cannot be null");
            }

            String wsdlFunction = "WMLS_GetFromStore";
            long   requestTime  = DateTime.Now.Ticks;
            String witsmlType   = witsmlObject.getWitsmlType();

            String queryXml    = null;
            String responseXml = null;

            try
            {
                // Find the getQuery() method
                //Method getQueryMethod = witsmlObject.getClass().getDeclaredMethod("getQuery",
                //                                                                  String.class,
                //                                                                  String[].class);
                //getQueryMethod.setAccessible(true);
                MethodInfo getQueryMethod = witsmlObject.GetType().GetMethod("getQuery");

                // This is the complete query for the class
                //        String id = witsmlObject.getId() != null ? witsmlObject.getId() : "";
                //queryXml = (String) getQueryMethod.invoke(null, id,
                //                                          new String[] {witsmlObject.getParentId()});
                queryXml = getQueryMethod.Invoke(null, new object[] { witsmlObject.getParentId() }) as string;

                // Apply nodifications as specified by the WitsmlQuery instance
                queryXml = witsmlQuery.apply(queryXml);

                // Call server and capture the response
                WitsmlResponse response = accessor.get(witsmlType, queryXml);
                responseXml = response.getResponse();

                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml,
                       response.getStatusCode(),
                       response.getServerMessage(),
                       null);


                //
                // Build DOM document from response
                //
                //SAXBuilder builder = new SAXBuilder();
                //Document document = XDocument.Load(new StringReader(responseXml));
                XDocument document = XDocument.Load(new StringReader(responseXml));

                XElement root    = document.Root;                                                    //.getRootElement();
                XElement element = root.Element(root.Name.Namespace + witsmlObject.getWitsmlType()); //.Element(witsmlObject.getWitsmlType(),
                //root.getNamespace());

                //
                // Find the update() method on the target class
                //
                if (element != null)
                {
                    MethodInfo updateMethod = witsmlObject.GetType().GetMethod("update");//.getClass().getDeclaredMethod("update",

                    //Element.class);
                    //updateMethod.setAccessible(true);

                    // Call update on the instance
                    updateMethod.Invoke(witsmlObject, new object[] { element });
                }
            }
            catch (MissingMethodException exception)
            { // NoSuchMethodException exception) {
                // Programming error
                // exception.printStackTrace();
                Console.Write(exception.StackTrace);
                //Debug.Assert(false : "update() not found: " + witsmlObject.getClass();
            }
            catch (AccessViolationException exception)
            {// IllegalAccessException exception) {
                // Programming error
                //exception.printStackTrace();
                Console.Write(exception.StackTrace);
                //Debug.Assert(false : "Unable to invoke update(): " + witsmlObject.getClass();
            }
            catch (TargetInvocationException exception)
            { // InvocationTargetException exception) {
                // Wrapped exception from the invocation such as WitsmlParseException
                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
                       exception);
                String message = "Exception thrown on reflective call on: " + witsmlObject;
                throw new WitsmlServerException(message, exception.InnerException); //.getCause());
            }
            //catch (RemoteException exception) {
            //    // Connection problems.
            //    notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
            //           exception);
            //    String message = "Unable to connect to WITSML server at " + getUrl();
            //    throw new WitsmlServerException(message, exception);
            //}
            catch (IOException exception)
            {
                // Unable to read response XML
                notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
                       exception);
                String message = "Unable to read response XML: " + responseXml;
                throw new WitsmlServerException(message, exception);
            }
            //catch (JDOMException exception) {
            //    // Unable to parse response XML
            //    notify(wsdlFunction, witsmlType, requestTime, queryXml, responseXml, null, null,
            //           exception);
            //    String message = "Unable to parse response XML: " + responseXml;
            //    throw new WitsmlServerException(message, exception);
            //}
        }
Beispiel #14
0
        /// <summary>
        /// Return instances from this WITSML server.
        /// </summary>
        /// <typeparam name="T">Type of the Class to return. Non-null.</typeparam>
        /// <param name="witsmlQuery">Query to apply. Non-null.</param>
        /// <param name="id">ID of instance to get, or null to indicate all.</param>
        /// <param name="parent">arent object. Null to indicate root-level or if  parent IDs are specified instead.</param>
        /// <param name="parentIds"> ID of parent(s). Closest parent first. Null to indicate root-level or if parent instance is specified instead.</param>
        /// <returns>List of Requested instances. Never null.</returns>
        private List <T> get <T>(WitsmlQuery witsmlQuery,
                                 String id, WitsmlObject parent,
                                 params String[] parentIds) where T : WitsmlObject
        {
            if (witsmlQuery == null)
            {
                throw new ArgumentException("witsmlQuery cannot be null");
            }

            if (parent != null && parentIds != null && parentIds.Length > 0)
            {
                throw new ArgumentException("Both parent and parentIds can't be set");
            }

            String wsdlFunction = "WMLS_GetFromStore";

            // Prepare the return structure
            List <T> instances = new List <T>();

            String actualId = id != null ? id : "";

            String[] parentId;
            if (parent != null)
            {
                parentId = getIds(parent);
            }
            else if (parentIds != null)
            {
                parentId = parentIds;
            }
            else
            {
                parentId = new String[] { "" }
            };

            long requestTime = DateTime.Now.Ticks;

            String queryXml    = "";
            String responseXml = null;

            String type = WitsmlServer.getWitsmlType(typeof(T));

            var actualClass = getActualClass(version, type);

            try
            {
                var getQueryMethod = actualClass.GetMethod("getQuery", BindingFlags.NonPublic | BindingFlags.Static);
                queryXml = (string)getQueryMethod.Invoke(null, new object[] { actualId, parentId });
                //// Find the getQuery() method
                //Method getQueryMethod = actualClass.getDeclaredMethod("getQuery",
                //                                                      String.class,
                //                                                      String[].class);
                //getQueryMethod.setAccessible(true);

                //// This is the complete query for the class
                //queryXml = (String) getQueryMethod.invoke(null, actualId, parentId);

                //// Apply nodifications as specified by the WitsmlQuery instance

                queryXml = witsmlQuery.apply(queryXml);

                // Send the query to the WITSML server and pick the response
                WitsmlResponse response = accessor.get(type, queryXml);
                responseXml = response.getResponse();


                notify(wsdlFunction, type, requestTime, queryXml, responseXml,
                       response.getStatusCode(),
                       response.getServerMessage(),
                       null);

                // If nothing was returned we leave here
                if (responseXml == null || responseXml.Length == 0)
                {
                    return(instances);
                }

                //
                // Build DOM document
                //
                //SAXBuilder builder = new SAXBuilder();
                XDocument document = XDocument.Load(new StringReader(responseXml));
                //Document document = XDocument.Load(new StringReader(responseXml));
                XElement rootElement = document.Root;
                //Element rootElement = document.getRootElement();

                //
                // Find the newInstance() method
                //
                MethodInfo newInstanceMethod = actualClass.GetMethod("newInstance", BindingFlags.NonPublic | BindingFlags.Static); //.getDeclaredMethod("newInstance",

#if DEBUG
                if (newInstanceMethod == null)
                {
                    throw new NotImplementedException("newInstance method is not implemented for the classe " + actualClass.Name);
                }
#endif

                //WitsmlServer.class,
                // WitsmlObject.class,
                // Element.class);
                //newInstanceMethod.setAccessible(true);

                //
                // Loop over the elements and create instances accordingly
                //
                var elements = rootElement.Elements(rootElement.Name.Namespace + type); //.getChildren(type, rootElement.getNamespace());
                foreach (Object element in elements)
                {
                    WitsmlObject instance = (WitsmlObject)newInstanceMethod.Invoke(null, new object[] { this, parent, element }); //.invoke(null, this, parent, element);
                    instances.Add(instance as T);                                                                                 // baseClass.cast(instance));
                }

                return(instances);
            }
            catch (MissingMemberException exception)
            {// NoSuchMethodException exception) {
                // Programmer error
                //Debug.Assert(false : "Method not found: " + actualClass;
                return(null);
            }
            catch (AccessViolationException exception)
            {// IllegalAccessException exception) {
                // Programmer error
                //Debug.Assert(false : "Unable to invoke: " + actualClass;
                return(null);
            }
            catch (TargetInvocationException exception)
            {// InvocationTargetException exception) {
             // Wrapped exception from the invocation such as WitsmlParseException

                //TODO re-implement this
                notify(wsdlFunction, type, requestTime, queryXml, responseXml, null, null,
                       exception.InnerException);                                   //.getCause());
                String message = "Exception thrown by " + actualClass + ".newInstance()";
                throw new WitsmlServerException(message, exception.InnerException); //.getCause());
            }
            //catch ( RemoteException exception) {
            //    // Connection problems.
            //    //TODO
            //    //notify(wsdlFunction, type, requestTime, queryXml, responseXml, null, null,
            //    //       exception);
            //    String message = "Unable to connect to WITSML server: " + this;
            //    throw new WitsmlServerException(message, exception);
            //}
            catch (IOException exception)
            {
                // Unable to read response XML

                //TODO
                //notify(wsdlFunction, type, requestTime, queryXml, responseXml, null, null,
                //       exception);
                String message = "Unable to read response XML: " + responseXml;
                throw new WitsmlServerException(message, exception);
            }
            //catch ( JDOMException exception) {
            //    // Unable to parse response XML
            //    notify(wsdlFunction, type, requestTime, queryXml, responseXml, null, null,
            //           exception);
            //    String message = "Unable to parse response XML: " + responseXml;
            //    throw new WitsmlServerException(message, exception);
            //}
        }
        protected String description;                 // description

        protected WitsmlFormationMarker(WitsmlServer server, String id, String name,
                                        WitsmlObject parent, String parentId)
            : base(server, WITSML_TYPE, id, name, parent, parentId)
        {
        }