public TcpTransportBenchmark() { _uri = new Uri("net.tcp://localhost:55321"); _cancellationToken = TimeSpan.FromSeconds(60).ToCancellationToken(); _envelopeSerializer = new EnvelopeSerializer(new DocumentTypeResolver().WithMessagingDocuments()); _transportListener = new TcpTransportListener(_uri, null, _envelopeSerializer); }
public FlowManager( IConfiguration configuration, IStateManager stateManager, IContextProvider contextProvider, INamedSemaphore namedSemaphore, IActionProvider actionProvider, ISender sender, IDocumentSerializer documentSerializer, IEnvelopeSerializer envelopeSerializer, IArtificialIntelligenceExtension artificialIntelligenceExtension, IVariableReplacer variableReplacer, ILogger logger, ITraceManager traceManager, IUserOwnerResolver userOwnerResolver, Application application) { _configuration = configuration; _stateManager = stateManager; _contextProvider = contextProvider; _namedSemaphore = namedSemaphore; _actionProvider = actionProvider; _sender = sender; _documentSerializer = documentSerializer; _envelopeSerializer = envelopeSerializer; _artificialIntelligenceExtension = artificialIntelligenceExtension; _variableReplacer = variableReplacer; _logger = logger; _traceManager = traceManager; _userOwnerResolver = userOwnerResolver; _applicationIdentity = application.Identity; }
/// <summary> /// Initializes a new instance of <see cref="PipeTcpTransportListener"/> class. /// </summary> /// <param name="listenerUri">The URI for listening new connections.</param> /// <param name="serverCertificate">The certificate to encrypt the connections with TLS.</param> /// <param name="envelopeSerializer">The serializer for envelopes.</param> /// <param name="pauseWriterThreshold">Number of buffered bytes in the pipe which can lead the write task to pause.</param> /// <param name="memoryPool">The memory pool instance which allow the pipe to reuse buffers.</param> /// <param name="traceWriter"></param> /// <param name="clientCertificateValidationCallback"></param> public PipeTcpTransportListener( Uri listenerUri, X509Certificate2 serverCertificate, IEnvelopeSerializer envelopeSerializer, int pauseWriterThreshold = EnvelopePipe.DEFAULT_PAUSE_WRITER_THRESHOLD, MemoryPool <byte> memoryPool = null, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback clientCertificateValidationCallback = null) { if (listenerUri == null) { throw new ArgumentNullException(nameof(listenerUri)); } if (listenerUri.Scheme != TcpTransport.UriSchemeNetTcp) { throw new ArgumentException($"Invalid URI scheme. The expected value is '{TcpTransport.UriSchemeNetTcp}'."); } ListenerUris = new[] { listenerUri }; if (serverCertificate != null && !serverCertificate.HasPrivateKey) { throw new ArgumentException("The certificate must have a private key", nameof(serverCertificate)); } _serverCertificate = serverCertificate; _envelopeSerializer = envelopeSerializer ?? throw new ArgumentNullException(nameof(envelopeSerializer)); _pauseWriterThreshold = pauseWriterThreshold; _memoryPool = memoryPool ?? MemoryPool <byte> .Shared; _traceWriter = traceWriter; _clientCertificateValidationCallback = clientCertificateValidationCallback; _semaphore = new SemaphoreSlim(1); }
public ClientWebSocketTransport( IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = DEFAULT_BUFFER_SIZE, WebSocketMessageType webSocketMessageType = WebSocketMessageType.Text, ClientWebSocket webSocket = null, ArrayPool <byte> arrayPool = null, bool closeGracefully = true, X509CertificateCollection clientCertificates = null, RemoteCertificateValidationCallback serverCertificateValidationCallback = null) : base( webSocket ?? new ClientWebSocket(), envelopeSerializer, traceWriter, bufferSize, webSocketMessageType, arrayPool, closeGracefully) { if (clientCertificates != null) { ((ClientWebSocket)WebSocket).Options.ClientCertificates = clientCertificates; } if (serverCertificateValidationCallback != null) { ((ClientWebSocket)WebSocket).Options.RemoteCertificateValidationCallback = serverCertificateValidationCallback; } }
public ClientWebSocketTransport( IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = 8192) : base(new ClientWebSocket(), envelopeSerializer, traceWriter, bufferSize) { }
public WebSocketTransportBenchmark() { _uri = new Uri("ws://localhost:8081"); _cancellationToken = TimeSpan.FromSeconds(60).ToCancellationToken(); _envelopeSerializer = new EnvelopeSerializer(new DocumentTypeResolver().WithMessagingDocuments()); _transportListener = new WebSocketTransportListener(_uri, null, _envelopeSerializer, null, webSocketMessageType: System.Net.WebSockets.WebSocketMessageType.Text); }
public TcpTransportListener(Uri listenerUri, X509Certificate2 sslCertificate, IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback clientCertificateValidationCallback = null) { if (listenerUri == null) { throw new ArgumentNullException(nameof(listenerUri)); } if (listenerUri.Scheme != TcpTransport.UriSchemeNetTcp) { throw new ArgumentException($"Invalid URI scheme. The expected value is '{TcpTransport.UriSchemeNetTcp}'."); } if (envelopeSerializer == null) { throw new ArgumentNullException(nameof(envelopeSerializer)); } ListenerUris = new[] { listenerUri }; if (sslCertificate != null && !sslCertificate.HasPrivateKey) { throw new ArgumentException("The certificate must have a private key"); } _sslCertificate = sslCertificate; _envelopeSerializer = envelopeSerializer; _traceWriter = traceWriter; _clientCertificateValidationCallback = clientCertificateValidationCallback; _semaphore = new SemaphoreSlim(1); }
public BuilderMessageReceiver( IFlowManager flowManager, BuilderSettings settings, IContactExtension contactExtension, IDirectoryExtension directoryExtension, ISender sender, IStateManager stateManager, IDocumentSerializer documentSerializer, IEnvelopeSerializer envelopeSerializer, IArtificialIntelligenceExtension artificialIntelligenceExtension, IContextProvider contextProvider, IUserOwnerResolver userOwnerResolver, ILogger logger) : base(contactExtension, directoryExtension, logger) { _flowManager = flowManager; _settings = settings; _sender = sender; _stateManager = stateManager; _documentSerializer = documentSerializer; _envelopeSerializer = envelopeSerializer; _contextProvider = contextProvider; _userOwnerResolver = userOwnerResolver; _artificialIntelligenceExtension = artificialIntelligenceExtension; }
public MessageFubuDiagnostics(IQueueMessageRetrieval queueMessageRetrieval, IEnvelopeSerializer serializer, IFubuRequest fubuRequest) { _queueMessageRetrieval = queueMessageRetrieval; _serializer = serializer; _fubuRequest = fubuRequest; }
public EnvelopeSender(ISubscriptionCache router, IEnvelopeSerializer serializer, ILogger logger, IEnumerable<IEnvelopeModifier> modifiers) { _router = router; _serializer = serializer; _logger = logger; _modifiers = modifiers; }
public EnvelopeSender(ISubscriptionCache router, IEnvelopeSerializer serializer, ILogger logger, IEnumerable <IEnvelopeModifier> modifiers) { _router = router; _serializer = serializer; _logger = logger; _modifiers = modifiers; }
public LightningQueuesFubuDiagnostics(IPersistentQueues queues, IQueueMessageRetrieval queueMessageRetrieval, IEnvelopeSerializer serializer) { _queues = queues; _queueMessageRetrieval = queueMessageRetrieval; _serializer = serializer; }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport"/> class. /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="serverCertificate">The server certificate.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="hostName">Name of the host.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="maxBufferSize">Max size of the buffer.</param> /// <param name="arrayPool">The array pool instance, to allow reusing the created buffers.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="serverCertificateValidationCallback">The server certificate validation callback.</param> /// <param name="clientCertificateValidationCallback">The client certificate validation callback.</param> /// <param name="ignoreDeserializationErrors">if set to <c>true</c> the deserialization on received envelopes will be ignored; otherwise, any deserialization error will be throw to the caller.</param> /// <exception cref="System.ArgumentNullException"> /// tcpClient /// or /// envelopeSerializer /// </exception> private TcpTransport( ITcpClient tcpClient, IEnvelopeSerializer envelopeSerializer, X509Certificate2 serverCertificate, X509Certificate2 clientCertificate, string hostName, int bufferSize, int maxBufferSize, ArrayPool <byte> arrayPool, ITraceWriter traceWriter, RemoteCertificateValidationCallback serverCertificateValidationCallback, RemoteCertificateValidationCallback clientCertificateValidationCallback, bool ignoreDeserializationErrors) { _tcpClient = tcpClient ?? throw new ArgumentNullException(nameof(tcpClient)); _envelopeSerializer = envelopeSerializer ?? throw new ArgumentNullException(nameof(envelopeSerializer)); _serverCertificate = serverCertificate; _clientCertificate = clientCertificate; _hostName = hostName; _traceWriter = traceWriter; _serverCertificateValidationCallback = serverCertificateValidationCallback ?? ValidateServerCertificate; _clientCertificateValidationCallback = clientCertificateValidationCallback ?? ValidateClientCertificate; _ignoreDeserializationErrors = ignoreDeserializationErrors; _jsonBuffer = new JsonBuffer(bufferSize, maxBufferSize, arrayPool); _receiveSemaphore = new SemaphoreSlim(1); _sendSemaphore = new SemaphoreSlim(1); }
public RedisTransportListener( ConfigurationOptions redisConfiguration, IEnvelopeSerializer envelopeSerializer = null, ITraceWriter traceWriter = null, int acceptTransportBoundedCapacity = 10, IConnectionMultiplexerFactory connectionMultiplexerFactory = null, string channelNamespace = null) { if (redisConfiguration == null) { throw new ArgumentNullException(nameof(redisConfiguration)); } _redisConfiguration = redisConfiguration; _envelopeSerializer = envelopeSerializer ?? new JsonNetSerializer(); _traceWriter = traceWriter; _channelNamespace = channelNamespace ?? RedisTransport.DefaultChannelNamespace; _connectionMultiplexerFactory = connectionMultiplexerFactory ?? new ConnectionMultiplexerFactory(); _transportBufferBlock = new BufferBlock <ITransport>( new DataflowBlockOptions() { BoundedCapacity = acceptTransportBoundedCapacity }); _semaphore = new SemaphoreSlim(1, 1); _listenerChannelName = GetListenerChannelName(_channelNamespace, RedisTransport.ServerChannelPrefix); }
public void SetUp() { theEnvelope = new Envelope() { Data = new byte[] { 1, 2, 3, 4 }, }; theSerializer = MockRepository.GenerateMock <IEnvelopeSerializer>(); theEnvelope.Headers["A"] = "1"; theEnvelope.Headers["B"] = "2"; theEnvelope.Headers["C"] = "3"; theEnvelope.CorrelationId = Guid.NewGuid().ToString(); theChannel = new RecordingChannel(); theNode = new ChannelNode { Channel = theChannel, Key = "Foo", Uri = "foo://bar".ToUri() }; theNode.Modifiers.Add(new HeaderSetter("D", "4")); theNode.Modifiers.Add(new HeaderSetter("E", "5")); theNode.Send(theEnvelope, theSerializer); }
private Lazy <string> CreateLazySerializedMessage(IEnvelopeSerializer envelopeSerializer) => new Lazy <string>(() => { if (Message != null) { return(envelopeSerializer.Serialize(Message)); } return(null); });
public ClientWebSocketTransport( IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = WebSocketTransport.DEFAULT_BUFFER_SIZE, WebSocketMessageType webSocketMessageType = WebSocketMessageType.Text) : base(new ClientWebSocket(), envelopeSerializer, traceWriter, bufferSize, webSocketMessageType) { }
// virtual for testing of course public virtual IHeaders Send(Envelope envelope, IEnvelopeSerializer serializer, Uri replyUri = null) { var clone = EnvelopeForSending(envelope, serializer, replyUri); Channel.Send(clone.Data, clone.Headers); return(clone.Headers); }
/// <summary> /// Initializes a new instance of the <see cref="ClientSignalRTransport"/> class. /// </summary> /// <param name="envelopeSerializer">The serializer for envelopes exchanged in the transport connections.</param> /// <param name="traceWriter">A sink for tracing messages. Default <c>null</c>.</param> public ClientSignalRTransport( IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null) : base( Channel.CreateUnbounded <string>(), envelopeSerializer, traceWriter) { }
internal ServerWebSocketTransport( HttpListenerWebSocketContext context, IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = 8192) : base(context.WebSocket, envelopeSerializer, traceWriter, bufferSize) { _context = context; }
public BlipMiddleware( RequestDelegate next, IEnvelopeBuffer envelopeBuffer, IEnvelopeSerializer envelopeSerializer) { _next = next; _envelopeBuffer = envelopeBuffer; _envelopeSerializer = envelopeSerializer; }
/// <summary> /// Initializes a new instance of the <see cref="WebSocketTransportListener"/> class. /// </summary> /// <param name="listenerUri">The listener URI.</param> /// <param name="tlsCertificate">The SSL/TLS certificate information to be used in case of using the 'wss' scheme.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="keepAliveInterval">The keep alive interval.</param> /// <param name="bindCertificateToPort">if set to <c>true</c> indicates that the provided certificate should be bound to the listener IP address.</param> /// <param name="applicationId">The application id for binding the certificate to the listene port.</param> /// <param name="acceptTransportBoundedCapacity">The number of concurrent transport connections that can be accepted in parallel.</param> /// <param name="webSocketMessageType">Indicates the message type</param> /// <exception cref="ArgumentNullException"> /// </exception> public WebSocketTransportListener( Uri listenerUri, X509CertificateInfo tlsCertificate, IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = 16384, TimeSpan?keepAliveInterval = null, bool bindCertificateToPort = true, Guid?applicationId = null, int acceptTransportBoundedCapacity = 10, WebSocketMessageType webSocketMessageType = WebSocketMessageType.Text) { if (listenerUri == null) { throw new ArgumentNullException(nameof(listenerUri)); } if (listenerUri.Scheme != UriSchemeWebSocket && listenerUri.Scheme != UriSchemeWebSocketSecure) { throw new ArgumentException($"Invalid URI scheme. The expected value is '{UriSchemeWebSocket}' or '{UriSchemeWebSocketSecure}'."); } if (tlsCertificate == null && listenerUri.Scheme == UriSchemeWebSocketSecure) { throw new ArgumentNullException(nameof(tlsCertificate)); } ListenerUris = new[] { listenerUri }; _tlsCertificate = tlsCertificate; _envelopeSerializer = envelopeSerializer ?? throw new ArgumentNullException(nameof(envelopeSerializer)); _traceWriter = traceWriter; _bufferSize = bufferSize; _bindCertificateToPort = bindCertificateToPort; _applicationId = applicationId ?? DefaultApplicationId; _keepAliveInterval = keepAliveInterval ?? System.Net.WebSockets.WebSocket.DefaultKeepAliveInterval; _httpListener = new HttpListener(); var boundedCapacity = new ExecutionDataflowBlockOptions() { BoundedCapacity = acceptTransportBoundedCapacity }; // Create blocks _httpListenerContextBufferBlock = new BufferBlock <HttpListenerContext>(boundedCapacity); _httpListenerWebSocketContextTransformBlock = new TransformBlock <HttpListenerContext, ITransport>( c => AcceptWebSocketAsync(c), boundedCapacity); _transportBufferBufferBlock = new BufferBlock <ITransport>(boundedCapacity); _nullTargetBlock = DataflowBlock.NullTarget <ITransport>(); // Link blocks _httpListenerContextBufferBlock.LinkTo(_httpListenerWebSocketContextTransformBlock); _httpListenerWebSocketContextTransformBlock.LinkTo(_transportBufferBufferBlock, t => t != null); _httpListenerWebSocketContextTransformBlock.LinkTo(_nullTargetBlock, t => t == null); _webSocketMessageType = webSocketMessageType; }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport" /> class. /// </summary> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="pauseWriterThreshold">Number of buffered bytes in the pipe which can lead the write task to pause.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="serverCertificateValidationCallback">A callback to validate the server certificate in the TLS authentication process.</param> public PipeTcpTransport( IEnvelopeSerializer envelopeSerializer, X509Certificate2 clientCertificate = null, int pauseWriterThreshold = EnvelopePipe.DEFAULT_PAUSE_WRITER_THRESHOLD, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback serverCertificateValidationCallback = null) : this(new TcpClientAdapter(new TcpClient()), envelopeSerializer, null, clientCertificate, null, pauseWriterThreshold, null, traceWriter, serverCertificateValidationCallback, null) { }
public HandlerPipeline(IEnvelopeSender sender, IEnvelopeSerializer serializer, HandlerGraph graph, IReplyWatcher replies, IBusLogger[] loggers) { _sender = sender; _serializer = serializer; _graph = graph; _replies = replies; Logger = BusLogger.Combine(loggers); }
public ClientWebSocketTransport(IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = 8192) { _envelopeSerializer = envelopeSerializer; _traceWriter = traceWriter; _clientWebSocket = new ClientWebSocket(); _receiveSemaphore = new SemaphoreSlim(1); _sendSemaphore = new SemaphoreSlim(1); _jsonBuffer = new JsonBuffer(bufferSize); }
public Envelope Send(Envelope envelope, Uri address, IEnvelopeSerializer serializer, IMessageCallback callback = null) { ITransport transport = null; if (_transports.TryGetValue(address.Scheme, out transport)) { var sending = envelope.Clone(); var channel = TryGetChannel(address); // TODO -- look up channel node modifiers if any // TODO -- there's a little opportunity here to try to reuse the serialization // if you send to more than one channel at a time w/ the same serializer if (sending.Data == null || sending.Data.Length == 0) { serializer.Serialize(sending, channel); } sending.AcceptedContentTypes = AcceptedContentTypes.ToArray(); if (channel != null) { sending.Destination = channel.Destination; sending.ReplyUri = channel.ReplyUri; if (callback == null) { channel.Sender.Send(sending.Data, sending.Headers); } else { callback.Send(sending); } } else { sending.Destination = address; sending.ReplyUri = transport.DefaultReplyUri(); if (callback == null) { transport.Send(sending.Destination, sending.Data, sending.Headers); } else { callback.Send(sending); } } return(sending); } else { throw new InvalidOperationException($"Unrecognized transport scheme '{address.Scheme}'"); } }
internal ServerWebSocketTransport( HttpListenerWebSocketContext context, IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null, int bufferSize = 8192, WebSocketMessageType webSocketMessageType = WebSocketMessageType.Text) : base(context.WebSocket, envelopeSerializer, traceWriter, bufferSize, -1, webSocketMessageType) { _context = context; }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport" /> class. /// </summary> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="maxBufferSize">Max size of the buffer for increasing.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="serverCertificateValidationCallback">A callback to validate the server certificate in the TLS authentication process.</param> public TcpTransport( IEnvelopeSerializer envelopeSerializer, X509Certificate2 clientCertificate = null, int bufferSize = DEFAULT_BUFFER_SIZE, int maxBufferSize = DEFAULT_MAX_BUFFER_SIZE, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback serverCertificateValidationCallback = null) : this(new TcpClientAdapter(new TcpClient()), envelopeSerializer, null, clientCertificate, null, bufferSize, maxBufferSize, null, traceWriter, serverCertificateValidationCallback, null) { }
public HandlerPipeline(IEnvelopeSerializer serializer, ContinuationContext context, IEnumerable<IEnvelopeHandler> handlers) { _serializer = serializer; _context = context; _handlers.AddRange(handlers); // needs to be available to continuations _context.Pipeline = this; }
public HandlerPipeline(IEnvelopeSerializer serializer, ContinuationContext context, IEnumerable <IEnvelopeHandler> handlers) { _serializer = serializer; _context = context; _handlers.AddRange(handlers); // needs to be available to continuations _context.Pipeline = this; }
public WebTransport(IEnvelopeBuffer envelopeBuffer, IEnvelopeSerializer serializer, Application application, Uri baseUri) { _envelopeBuffer = envelopeBuffer; _serializer = serializer; _application = application; _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Key", GetAuthCredentials(application)); _baseUri = baseUri.ToString().TrimEnd('/'); }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport" /> class. /// </summary> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="serverCertificateValidationCallback">A callback to validate the server certificate in the TLS authentication process.</param> /// <param name="ignoreDeserializationErrors">if set to <c>true</c> the deserialization on received envelopes will be ignored; otherwise, any deserialization error will be throw to the caller.</param> public TcpTransport( IEnvelopeSerializer envelopeSerializer, X509Certificate2 clientCertificate = null, int bufferSize = DEFAULT_BUFFER_SIZE, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback serverCertificateValidationCallback = null, bool ignoreDeserializationErrors = false) : this(new TcpClientAdapter(new TcpClient()), envelopeSerializer, null, clientCertificate, null, bufferSize, traceWriter, serverCertificateValidationCallback, null, ignoreDeserializationErrors) { }
public LazyInput( Message message, Identity userIdentity, BuilderConfiguration builderConfiguration, IDocumentSerializer documentSerializer, IEnvelopeSerializer envelopeSerializer, IArtificialIntelligenceExtension artificialIntelligenceExtension, CancellationToken cancellationToken) { Message = message ?? throw new ArgumentNullException(nameof(message)); _builderConfiguration = builderConfiguration ?? throw new ArgumentNullException(nameof(builderConfiguration)); _lazySerializedContent = new Lazy <string>(() => documentSerializer.Serialize(Content)); _analyzable = new Lazy <bool>(() => { string result = null; Message?.Metadata?.TryGetValue("builder.analyzable", out result); return(result?.ToLower() == "true"); }); _lazyAnalyzedContent = new Lazy <Task <AnalysisResponse> >(async() => { // Only analyze the input if the type is plain text or analyzable metadata is true. if (!_analyzable.Value && Content.GetMediaType() != PlainText.MediaType) { return(null); } try { return(await artificialIntelligenceExtension.AnalyzeAsync( new AnalysisRequest { Text = _lazySerializedContent.Value, Extras = new Dictionary <string, string> { ["MessageId"] = Message.Id, ["UserIdentity"] = userIdentity.ToString() } }, cancellationToken)); } catch (LimeException) { return(null); } }); _lazySerializedMessage = new Lazy <string>(() => { if (Message != null) { return(envelopeSerializer.Serialize(Message)); } return(null); }); }
public override IHeaders Send(Envelope envelope, IEnvelopeSerializer serializer, Uri replyUri = null) { if (replyUri != null) { envelope.ReplyUri = replyUri; } LastEnvelope = envelope; return envelope.Headers; }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport"/> class. /// This constructor is used by the <see cref="TcpTransportListener"/> class. /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="serverCertificate">The server certificate.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="traceWriter">The trace writer.</param> /// <param name="clientCertificateValidationCallback">A callback to validate the client certificate in the TLS authentication process.</param> /// <param name="ignoreDeserializationErrors">if set to <c>true</c> the deserialization on received envelopes will be ignored; otherwise, any deserialization error will be throw to the caller.</param> internal TcpTransport( ITcpClient tcpClient, IEnvelopeSerializer envelopeSerializer, X509Certificate2 serverCertificate, int bufferSize = DEFAULT_BUFFER_SIZE, ITraceWriter traceWriter = null, RemoteCertificateValidationCallback clientCertificateValidationCallback = null, bool ignoreDeserializationErrors = false) : this(tcpClient, envelopeSerializer, serverCertificate, null, null, bufferSize, traceWriter, null, clientCertificateValidationCallback, ignoreDeserializationErrors) { }
public static string ExecuteSerialization(IEnvelopeSerializer serializer, Envelope envelope, int count) { string json = null; var sw = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < count; i++) { json = serializer.Serialize(envelope); } sw.Stop(); System.Console.WriteLine("{0}: {1} ms", serializer.GetType().Name, sw.ElapsedMilliseconds); return json; }
public TcpTransportListener(Uri listenerUri, X509Certificate2 sslCertificate, IEnvelopeSerializer envelopeSerializer, ITraceWriter traceWriter = null) { if (listenerUri == null) { throw new ArgumentNullException("listenerUri"); } if (listenerUri.Scheme != Uri.UriSchemeNetTcp) { throw new ArgumentException("Invalid URI scheme. The expected value is 'net.tcp'."); } this.ListenerUris = new Uri[] { listenerUri }; if (sslCertificate != null) { if (!sslCertificate.HasPrivateKey) { throw new ArgumentException("The certificate must have a private key"); } try { // Checks if the private key is available for the current user var key = sslCertificate.PrivateKey; } catch (CryptographicException ex) { throw new SecurityException("The current user doesn't have access to the certificate private key. Use WinHttpCertCfg.exe to assign the necessary permissions.", ex); } } _sslCertificate = sslCertificate; _envelopeSerializer = envelopeSerializer; _traceWriter = traceWriter; }
public static Envelope ExecuteDeserialization(IEnvelopeSerializer serializer, string json, int count) { var sw = System.Diagnostics.Stopwatch.StartNew(); Envelope envelope = null; for (int i = 0; i < count; i++) { envelope = serializer.Deserialize(json); } sw.Stop(); System.Console.WriteLine("{0}: {1} ms", serializer.GetType().Name, sw.ElapsedMilliseconds); return envelope; }
public void SetUp() { theEnvelope = new Envelope() { Data = new byte[]{1,2,3,4}, }; theSerializer = MockRepository.GenerateMock<IEnvelopeSerializer>(); theEnvelope.Headers["A"] = "1"; theEnvelope.Headers["B"] = "2"; theEnvelope.Headers["C"] = "3"; theEnvelope.CorrelationId = Guid.NewGuid().ToString(); theChannel = new RecordingChannel(); theNode = new ChannelNode { Channel = theChannel, Key = "Foo", Uri = "foo://bar".ToUri() }; theNode.Modifiers.Add(new HeaderSetter("D", "4")); theNode.Modifiers.Add(new HeaderSetter("E", "5")); theNode.Send(theEnvelope, theSerializer); }
// virtual for testing of course public virtual IHeaders Send(Envelope envelope, IEnvelopeSerializer serializer, Uri replyUri = null) { var clone = EnvelopeForSending(envelope, serializer, replyUri); Channel.Send(clone.Data, clone.Headers); return clone.Headers; }
public EnvelopeStreamer(IEnvelopeSerializer envelopeSerializer, IDataSerializer dataSerializer) { _envelopeSerializer = envelopeSerializer; _dataSerializer = dataSerializer; }
private TcpTransport(ITcpClient tcpClient, IEnvelopeSerializer envelopeSerializer, X509Certificate2 serverCertificate, X509Certificate2 clientCertificate, string hostName, int bufferSize, ITraceWriter traceWriter) { if (tcpClient == null) { throw new ArgumentNullException("tcpClient"); } _tcpClient = tcpClient; _buffer = new byte[bufferSize]; _bufferCurPos = 0; if (envelopeSerializer == null) { throw new ArgumentNullException("envelopeSerializer"); } _envelopeSerializer = envelopeSerializer; _hostName = hostName; _traceWriter = traceWriter; _receiveSemaphore = new SemaphoreSlim(1); _sendSemaphore = new SemaphoreSlim(1); _serverCertificate = serverCertificate; _clientCertificate = clientCertificate; }
public Envelope EnvelopeForSending(Envelope envelope, IEnvelopeSerializer serializer, Uri replyUri) { var clone = envelope.Clone(); // Must be done in this order! Modifiers.Each(x => x.Modify(clone)); serializer.Serialize(clone, this); clone.Headers[Envelope.DestinationKey] = Uri.ToString(); clone.Headers[Envelope.ChannelKey] = Key; if (replyUri != null) { clone.Headers[Envelope.ReplyUriKey] = replyUri.ToString(); } return clone; }
void IAdvancedEngineBuilder.CustomEnvelopeSerializer(IEnvelopeSerializer serializer) { _envelopeSerializer = serializer; }
public HandlerPipeline(IEnvelopeSerializer serializer, IEnvelopeLifecycle lifecycle, IEnumerable<IEnvelopeHandler> handlers) { _serializer = serializer; _lifecycle = lifecycle; _handlers.AddRange(handlers); }
static EnvelopeViewModel() { _serializer = new EnvelopeSerializer(); }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport"/> class. /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="hostName">Name of the host.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="traceWriter">The trace writer.</param> public TcpTransport(IEnvelopeSerializer envelopeSerializer, X509Certificate2 clientCertificate = null, int bufferSize = DEFAULT_BUFFER_SIZE, ITraceWriter traceWriter = null) : this(new TcpClientAdapter(new TcpClient()), envelopeSerializer, null, clientCertificate, null, bufferSize, traceWriter) { }
public void UseSerializer(IEnvelopeSerializer serializer) { _message = new Lazy<object>(() => serializer.Deserialize(this)); }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport"/> class. /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="hostName">Name of the host.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="traceWriter">The trace writer.</param> public TcpTransport(ITcpClient tcpClient, IEnvelopeSerializer envelopeSerializer, string hostName, X509Certificate2 clientCertificate = null, int bufferSize = DEFAULT_BUFFER_SIZE, ITraceWriter traceWriter = null) : this(tcpClient, envelopeSerializer, null, clientCertificate, hostName, bufferSize, traceWriter) { }
/// <summary> /// Initializes a new instance of the <see cref="TcpTransport"/> class. /// This constructor is used by the <see cref="TcpTransportListener"/> class. /// </summary> /// <param name="tcpClient">The TCP client.</param> /// <param name="envelopeSerializer">The envelope serializer.</param> /// <param name="serverCertificate">The server certificate.</param> /// <param name="bufferSize">Size of the buffer.</param> /// <param name="traceWriter">The trace writer.</param> internal TcpTransport(ITcpClient tcpClient, IEnvelopeSerializer envelopeSerializer, X509Certificate2 serverCertificate, int bufferSize = DEFAULT_BUFFER_SIZE, ITraceWriter traceWriter = null) : this(tcpClient, envelopeSerializer, serverCertificate, null, null, bufferSize, traceWriter) { }
protected static IEnvelopeStreamer BuildStreamer(IEnvelopeSerializer serializer) { return new EnvelopeStreamer(new DataSerializerWithBinaryFormatter(), serializer); }
public EnvelopeStreamer(IDataSerializer dataSerializer, IEnvelopeSerializer envelopeSerializer = null) { _envelopeSerializer = envelopeSerializer ?? new EnvelopeSerializerWithDataContracts(); _dataSerializer = dataSerializer; }