/// <summary> /// Opens a connection to the server and begins the session /// </summary> /// <param name="request">connection information, configure the SourceName you want to use</param> public void Open(ClientConnectRequest request) { this.clientRequest = request; try { Connect(); Proxy.Open(clientRequest); if (ProxyReady) { Proxy.ForceUpdate(); } } catch (Exception exc) { if (Factory != null) { if (Factory.State == CommunicationState.Opened) { Factory.Abort(); } } ErrorLogger.DumpToDebug(exc); throw new Exception("The microwave control is currently unavailable.", exc); } }
protected void CloseFactory() { if (Factory.State == CommunicationState.Opened) { try { Factory.Close(); } catch (TimeoutException /* timeout */) { Factory.Abort(); } catch (CommunicationException /* communicationException */) { Factory.Abort(); } } }
/// <summary> /// Aborts the proxy factory in the case that it is faulted, or otherwise worthless /// </summary> public virtual void Abort() { try { if (keepAliveTimer != null) { keepAliveTimer.Enabled = false; keepAliveTimer.Dispose(); keepAliveTimer = null; } if (Factory != null) { Factory.Abort(); } } catch (Exception ex) { ErrorLogger.DumpToDebug(ex); } }
/// <summary> /// Closes the factory or aborts it as needed. Ensures that the Closed event is raised. /// </summary> public virtual void Close() { if (keepAliveTimer != null) { keepAliveTimer.Enabled = false; keepAliveTimer.Dispose(); keepAliveTimer = null; } //close Proxy / Channel if (_proxy != null) { ProxyInterface.Faulted -= new EventHandler(Proxy_Faulted); ProxyInterface.Closed -= new EventHandler(Proxy_Faulted); try { if (ProxyInterface.State == CommunicationState.Opened) { ProxyInterface.Close(); } else if ((ProxyInterface.State != CommunicationState.Closing) && (ProxyInterface.State != CommunicationState.Closed)) { ProxyInterface.Abort(); } } catch (Exception ex) { ErrorLogger.DumpToDebug(ex); } Proxy = default(TContract); } //close Factory if (Factory != null) { try { if (Factory.State == CommunicationState.Opened) { Factory.Close(); } else if ((Factory.State != CommunicationState.Closing) && (Factory.State != CommunicationState.Closed)) { Factory.Abort(); } } catch (Exception ex) { ErrorLogger.DumpToDebug(ex); } Factory.Opened -= new EventHandler(Factory_Opened); Factory.Closed -= new EventHandler(Factory_Closed); Factory.Faulted -= new EventHandler(Factory_Closed); Factory = null; } else { FireClosed(); } }