示例#1
0
        /// <summary>
        /// Return the capabilities as reported by the server.
        /// </summary>
        /// <returns> The capabilities as reported by the server. Never null.</returns>
        public Capabilities getServerCapabilities()
        {
            String wsdlFunction = "WMLS_GetCap";
            long   requestTime  = DateTime.Now.Ticks;

            try
            {
                WitsmlResponse response    = accessor.getServerCapabilities();
                String         responseXml = response.getResponse();

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

                Capabilities capabilities = new Capabilities(version, responseXml);
                return(capabilities);
            }
            catch (WitsmlParseException exception)
            {
                notify(wsdlFunction, null, requestTime, null, null, null, null, exception);
                throw new WitsmlServerException(exception.Message, exception);
            }
            catch (Exception /* RemoteException */ exception)
            {
                notify(wsdlFunction, null, requestTime, null, null, null, null, exception);
                throw new WitsmlServerException(exception.Message, exception);
            }
        }
示例#2
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);
            }
        }
示例#3
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);
            //}
        }
示例#4
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);
            //}
        }