private void StopInternal() { if (this.smsSender != null) { try { RemotingServices.Disconnect(this.smsSender); this.smsSender.Shutdown(); this.DisconnectEvents(); } finally { this.objRefSmsSender = null; this.smsSender = null; } } if (this.channel != null) { try { ChannelServices.UnregisterChannel(this.channel); } finally { this.channel = null; this.authModule = null; } } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public SmsServer() { this.smsSender = null; this.channel = null; this.objRefSmsSender = null; this.networkPort = 2000; this.uri = "SMSSender"; this.isSecured = false; this.authModule = null; this.allowAnonymous = false; this.portName = "COM1"; this.baudRate = 19200; this.timeout = 300; }
/// <summary> /// Starts the server. /// </summary> /// <exception cref="T:System.InvalidOperationException">Server is already running.</exception> public void Start() { if (this.smsSender == null) { IDictionary hashtables = new Hashtable(); hashtables["port"] = this.networkPort; hashtables["name"] = string.Concat("SMSSenderTCPChannel", this.networkPort.ToString()); if (this.isSecured) { hashtables["secure"] = "true"; this.authModule = new AuthorizationModule(this.allowAnonymous); } TcpServerChannel tcpServerChannel = new TcpServerChannel(hashtables, null, this.authModule); SmsSender smsSender = null; ObjRef objRef = null; try { ChannelServices.RegisterChannel(tcpServerChannel, this.isSecured); try { smsSender = new SmsSender(this.portName, this.baudRate, this.timeout); objRef = RemotingServices.Marshal(smsSender, this.uri); } catch (Exception exception) { ChannelServices.UnregisterChannel(tcpServerChannel); throw; } } catch (Exception exception1) { tcpServerChannel.StopListening(null); throw; } this.channel = tcpServerChannel; this.smsSender = smsSender; this.objRefSmsSender = objRef; this.ConnectEvents(); return; } else { throw new InvalidOperationException("Server is already running."); } }