public MultiplexedPipeConnection(NamedPipeServerStream pipeServer, Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedOutputStream) : base(pipeServer.Write) { this.pipeServer = pipeServer; this.outputPump = new MultiplexConnectionOutputPump(pipeServer.Read, multiplexedOutputStream.Write, Id); this.outputPump.BeginRunPump(PumpComplete, null); }
private DuplexChannelFactory <IDataExchangeChannel> CreateDataChannelFactory(Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedInputStream) { ReplyChannelStreamConnector connector = new ReplyChannelStreamConnector(multiplexedInputStream); DuplexChannelFactory <IDataExchangeChannel> dataChannelFactory = new DuplexChannelFactory <IDataExchangeChannel>(connector, streamBinding); dataChannelFactory.Endpoint.Behaviors.Add(relayCreds); return(dataChannelFactory); }
void EnsureConnection() { lock (connectLock) { if (this.dataChannel == null || this.dataChannel.State != CommunicationState.Opened) { this.multiplexedOutputStream = new ThrottledQueueBufferedStream(10); Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedInputStream = new Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream(); this.dataChannelFactory = CreateDataChannelFactory(multiplexedInputStream); this.dataChannelFactory.Open(); this.dataChannel = dataChannelFactory.CreateChannel(new EndpointAddress("sb:"), endpointVia); try { this.dataChannel.Open(); this.dataChannel.Closed += DataChannelClosed; this.dataChannel.Faulted += DataChannelClosed; IHybridConnectionStatus status = dataChannel.GetProperty <IHybridConnectionStatus>(); if (status != null) { status.ConnectionStateChanged += (o, e) => { Trace.TraceInformation("Data channel upgraded to direct connection."); }; } this.dataChannel.Connect("np:" + toPipe); this.inputPump = new MultiplexConnectionInputPump(multiplexedInputStream.Read, CorrelateConnection, null); this.inputPump.Run(false); this.outputPump = new StreamBufferWritePump(multiplexedOutputStream, WriteToDataChannel); this.dataChannel.Extensions.Add(new DataExchangeChannelFaultHelper(outputPump)); this.outputPump.BeginRunPump(MultiplexPumpCompleted, null); return; } catch (AuthorizationFailedException af) { Trace.TraceError("Authorization failed: {0}", af.Message); if (dataChannel != null) { dataChannel.Abort(); dataChannel = null; } throw; } catch (Exception ex) { this.dataChannelFactory.Abort(); this.dataChannelFactory = null; Trace.TraceError("Unable to establish data channel: {0}", ex.Message); if (dataChannel != null) { dataChannel.Abort(); dataChannel = null; } throw; } } } }
void EnsureConnection() { lock (connectLock) { if (this.dataChannel == null || this.dataChannel.State != CommunicationState.Opened) { this.multiplexedOutputStream = new ThrottledQueueBufferedStream(10); Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream multiplexedInputStream = new Microsoft.Samples.ServiceBus.Connections.QueueBufferedStream(); this.dataChannelFactory = CreateDataChannelFactory(multiplexedInputStream); this.dataChannelFactory.Open(); this.dataChannel = dataChannelFactory.CreateChannel(new EndpointAddress("sb:"), endpointVia); try { this.dataChannel.Open(); this.dataChannel.Closed += DataChannelClosed; this.dataChannel.Faulted += DataChannelClosed; IHybridConnectionStatus status = dataChannel.GetProperty<IHybridConnectionStatus>(); if (status != null) { status.ConnectionStateChanged += (o, e) => { Trace.TraceInformation("Data channel upgraded to direct connection."); }; } this.dataChannel.Connect("np:"+toPipe); this.inputPump = new MultiplexConnectionInputPump(multiplexedInputStream.Read, CorrelateConnection, null); this.inputPump.Run(false); this.outputPump = new StreamBufferWritePump(multiplexedOutputStream, WriteToDataChannel); this.dataChannel.Extensions.Add(new DataExchangeChannelFaultHelper(outputPump)); this.outputPump.BeginRunPump(MultiplexPumpCompleted, null); return; } catch (AuthorizationFailedException af) { Trace.TraceError("Authorization failed: {0}", af.Message); if (dataChannel != null) { dataChannel.Abort(); dataChannel = null; } throw; } catch (Exception ex) { this.dataChannelFactory.Abort(); this.dataChannelFactory = null; Trace.TraceError("Unable to establish data channel: {0}", ex.Message); if (dataChannel != null) { dataChannel.Abort(); dataChannel = null; } throw; } } } }