/// <summary> /// Odoberie instanciu ktora obsluhovala prijateho / akceptovaneho klienta ktory ukoncil spojenie /// </summary> /// <param name="contract">Contract obsluhujuci akceptovaneho klienta</param> private void InternalRemoveSpecifiedContract(ITransportClient contract) { //overime instaniu if (contract == null) { return; } lock (this) { //zalofujeme this.InternalTrace(TraceTypes.Info, "Pocet klientov: pred odobratim dalsieho {0}", this.m_contracts.Count); //odoberieme contract this.m_contracts.Remove(contract); //create event about remove client this.OnTransportClientRemoved(new TransportClientEventArgs(contract)); //zalogujeme this.InternalTrace(TraceTypes.Info, "Pocet klientov: po odobrati dalsieho {0}", this.m_contracts.Count); } //ukoncime inicializovany contract if (contract != null) { contract.Dispose(); contract = null; } }
/// <summary> /// Prepis a rozsirenie prijatia / akceptovania klienta /// </summary> /// <param name="e">TcpClientEventArgs</param> protected override void OnTcpClientReceived(TcpClientEventArgs e) { //base volanie na vytvorenie eventu base.OnTcpClientReceived(e); //overime ci je mozne pridat dalsieho klienta if (this.InternalCheckContracts()) { try { //pridame instaniu servera ITransportClient contract = this.InternalCreateContract(e.Client); //validate contract if (contract != null && contract.IsConnected) { //namapujeme event oznamujuci odhlasenie klienta contract.DisconnectedEvent += new EventHandler(contract_DisconnectedEvent); //pridame contract this.InternalCreateContract(contract); //create event about new client this.OnTransportClientAdded(new TransportClientEventArgs(contract)); } else { //ukoncime inicializovany contract if (contract != null) { contract.Dispose(); contract = null; } } } catch (Exception ex) { //chybu ignorujeme this.InternalTrace(TraceTypes.Error, "Interna chyba pri udalostiach spojenych z pridavanim pripojeneho klienta. {0}", ex.Message); } } else { try { //zalogujeme this.InternalTrace(TraceTypes.Verbose, "Ukoncovanie akceptovaneho klienta..."); //ziskame pristup TcpClient client = e.Client; client.Close(); } catch (Exception) { //ignorujeme } } }
public void Dispose() { _transportClient?.Dispose(); }
/// <summary> /// Odoberie instanciu ktora obsluhovala prijateho / akceptovaneho klienta ktory ukoncil spojenie /// </summary> /// <param name="contract">Contract obsluhujuci akceptovaneho klienta</param> private void InternalRemoveSpecifiedContract(ITransportClient contract) { //overime instaniu if (contract == null) return; lock (this) { //zalofujeme this.InternalTrace(TraceTypes.Info, "Pocet klientov: pred odobratim dalsieho {0}", this.m_contracts.Count); //odoberieme contract this.m_contracts.Remove(contract); //zalogujeme this.InternalTrace(TraceTypes.Info, "Pocet klientov: po odobrati dalsieho {0}", this.m_contracts.Count); } //ukoncime inicializovany contract if (contract != null) { contract.Dispose(); contract = null; } }
/// <inheritdoc /> public void Dispose() { _tcpClient?.Dispose(); }