/// <summary> /// Add the specified access listener to this server. The listener is called /// every time there is a remote call to the WITSML server. /// </summary> /// <param name="accessListener">Listener to add. If the listener is already /// added to this server, this call has no effect. Non-null. /// </param> public void addAccessListener(WitsmlAccessListener accessListener) { if (accessListener == null) { throw new ArgumentException("accessListener cannot be null"); } // Check if it is there already foreach (WeakReference reference in accessListeners) { if (accessListener.Equals(reference.Target)) { return; } } accessListeners.Add(new WeakReference(accessListener)); }
/// <summary> /// Remove the specified access listener from this server. /// </summary> /// <param name="accessListener"> /// Listener to remove. Non-null. If the instance /// has not been previously added as a listener /// to this server, this call has no effect. /// </param> public void removeAccessListener(WitsmlAccessListener accessListener) { if (accessListener == null) { throw new ArgumentException("accessListener cannot be null"); } foreach (var i in accessListeners) { WeakReference reference = i as WeakReference; WitsmlAccessListener listener = reference.Target as WitsmlAccessListener; if (listener.Equals(accessListener)) { accessListeners.Remove(i); break; } } }
/// <summary> /// Notify listeners about WITSML server access. /// </summary> /// <param name="wsdlFunction">The WSDL function being called. Non-null.</param> /// <param name="witsmlType">The WITSML type being accessed. Null if not applicable.</param> /// <param name="requestTime">Time of request.</param> /// <param name="request">The request string. Null if not applicable.</param> /// <param name="response">The response string. Null if not applicable or the call failed for some reason.</param> /// <param name="statusCode">The status code from the server. Null if not applicable for the WSDL function.</param> /// <param name="serverMessage">Message from the WITSML server. Null if not supplied or not applicable for the WSDL function.</param> /// <param name="throwable">Exception thrown. Null if none.</param> private void notify(String wsdlFunction, String witsmlType, long requestTime, String request, String response, Int32?statusCode, String serverMessage, Exception throwable) { if (wsdlFunction == null) { throw new ArgumentNullException("wsdlFunction cannot be null"); } // Create the event WitsmlAccessEvent @event = new WitsmlAccessEvent(this, wsdlFunction, witsmlType, requestTime, request, response, statusCode, serverMessage, throwable); foreach (WeakReference reference in accessListeners) { WitsmlAccessListener listener = reference.Target as WitsmlAccessListener; if (listener == null) { accessListeners.Remove(reference); } //TODO - what does this do //else // listener.accessPerformed(@event); } }