예제 #1
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());
        }
예제 #2
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;
        }
예제 #3
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);
            }
        }