Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetMQSource{T}"/> class.
 /// </summary>
 /// <param name="pipeline">Pipeline to which this component belongs.</param>
 /// <param name="topic">Topic name.</param>
 /// <param name="address">Connection string.</param>
 /// <param name="deserializer">Format deserializer with which messages are deserialized.</param>
 public NetMQSource(Pipeline pipeline, string topic, string address, IFormatDeserializer deserializer)
 {
     this.topic        = topic;
     this.address      = address;
     this.deserializer = deserializer;
     this.Out          = pipeline.CreateEmitter <T>(this, topic);
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TcpSource{T}"/> class.
        /// </summary>
        /// <param name="pipeline">The pipeline to add the component to.</param>
        /// <param name="address">The address of the remote server.</param>
        /// <param name="port">The port on which to connect.</param>
        /// <param name="deserializer">The deserializer to use to deserialize messages.</param>
        /// <param name="deallocator">An optional deallocator for the data.</param>
        /// <param name="useSourceOriginatingTimes">An optional parameter indicating whether to use originating times from the source received over the network or to re-timestamp with the current pipeline time upon receiving.</param>
        /// <param name="name">An optional name for the component.</param>
        public TcpSource(
            Pipeline pipeline,
            string address,
            int port,
            IFormatDeserializer deserializer,
            Action <T> deallocator         = null,
            bool useSourceOriginatingTimes = true,
            string name = nameof(TcpSource <T>))
        {
            this.pipeline     = pipeline;
            this.client       = new TcpClient();
            this.address      = address;
            this.port         = port;
            this.deserializer = deserializer;
            this.deallocator  = deallocator ?? (d =>
            {
                if (d is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            });

            this.useSourceOriginatingTimes = useSourceOriginatingTimes;
            this.name = name;
            this.Out  = pipeline.CreateEmitter <T>(this, nameof(this.Out));
        }
Пример #3
0
 /// <summary>
 /// Create a <see cref="TcpSource{T}"/> from a <see cref="Rendezvous.TcpSourceEndpoint"/>.
 /// </summary>
 /// <typeparam name="T">Type of data stream.</typeparam>
 /// <param name="endpoint"><see cref="Rendezvous.TcpSourceEndpoint"/> from which to create .</param>
 /// <param name="pipeline">The pipeline to add the component to.</param>
 /// <param name="deserializer">The deserializer to use to deserialize messages.</param>
 /// <param name="deallocator">An optional deallocator for the data.</param>
 /// <param name="useSourceOriginatingTimes">An optional parameter indicating whether to use originating times received from the source over the network or to re-timestamp with the current pipeline time upon receiving.</param>
 /// <param name="name">An optional name for the TCP source component.</param>
 /// <returns><see cref="TcpSource{T}"/>.</returns>
 public static TcpSource <T> ToTcpSource <T>(
     this Rendezvous.TcpSourceEndpoint endpoint,
     Pipeline pipeline,
     IFormatDeserializer deserializer,
     Action <T> deallocator         = null,
     bool useSourceOriginatingTimes = true,
     string name = nameof(TcpSource <T>))
 => new (pipeline, endpoint.Host, endpoint.Port, deserializer, deallocator, useSourceOriginatingTimes, name);
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetMQSource{T}"/> class.
 /// </summary>
 /// <param name="pipeline">Pipeline to which this component belongs.</param>
 /// <param name="topic">Topic name.</param>
 /// <param name="address">Connection string.</param>
 /// <param name="deserializer">Format deserializer with which messages are deserialized.</param>
 /// <param name="useReceivedTimes">Flag indicating whether or not to post with originating times received over the socket. If false, we ignore them and instead use pipeline's current time.</param>
 public NetMQSource(Pipeline pipeline, string topic, string address, IFormatDeserializer deserializer, bool useReceivedTimes = true)
 {
     this.pipeline         = pipeline;
     this.useReceivedTimes = useReceivedTimes;
     this.topic            = topic;
     this.address          = address;
     this.deserializer     = deserializer;
     this.Out = pipeline.CreateEmitter <T>(this, topic);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetMQSource{T}"/> class.
 /// </summary>
 /// <param name="pipeline">The pipeline to add the component to.</param>
 /// <param name="topic">Topic name.</param>
 /// <param name="address">Connection string.</param>
 /// <param name="deserializer">Format deserializer with which messages are deserialized.</param>
 /// <param name="useSourceOriginatingTimes">Flag indicating whether or not to post with originating times received over the socket. If false, we ignore them and instead use pipeline's current time.</param>
 /// <param name="name">An optional name for the component.</param>
 public NetMQSource(Pipeline pipeline, string topic, string address, IFormatDeserializer deserializer, bool useSourceOriginatingTimes = true, string name = nameof(NetMQSource <T>))
 {
     this.pipeline = pipeline;
     this.name     = name;
     this.useSourceOriginatingTimes = useSourceOriginatingTimes;
     this.topic        = topic;
     this.address      = address;
     this.deserializer = deserializer;
     this.Out          = pipeline.CreateEmitter <T>(this, topic);
 }
Пример #6
0
        private void AssertBinarySerialization(dynamic value, IFormatSerializer serializer, IFormatDeserializer deserializer)
        {
            var serialized   = serializer.SerializeMessage(value, originatingTime);
            var deserialized = deserializer.DeserializeMessage(serialized.Item1, serialized.Item2, serialized.Item3);

            Assert.AreEqual(originatingTime, deserialized.Item2);

            var roundtrip = serializer.SerializeMessage(deserialized.Item1, originatingTime);

            Enumerable.SequenceEqual <byte>(serialized.Item1, roundtrip.Item1);
            Assert.AreEqual <int>(serialized.Item2, roundtrip.Item2);
            Assert.AreEqual <int>(serialized.Item3, roundtrip.Item3);
        }
Пример #7
0
        private void AssertStringSerialization(dynamic value, string expected, IFormatSerializer serializer, IFormatDeserializer deserializer, bool roundTrip = true)
        {
            var serialized = serializer.SerializeMessage(value, originatingTime);

            Assert.AreEqual <string>(expected, Encoding.UTF8.GetString(serialized.Item1, serialized.Item2, serialized.Item3));

            if (roundTrip)
            {
                var deserialized = deserializer.DeserializeMessage(serialized.Item1, serialized.Item2, serialized.Item3);
                Assert.AreEqual(originatingTime, deserialized.Item2);

                var roundtrip = serializer.SerializeMessage(deserialized.Item1, originatingTime);
                Assert.AreEqual <string>(expected, Encoding.UTF8.GetString(roundtrip.Item1, roundtrip.Item2, roundtrip.Item3));
            }
        }
Пример #8
0
 /// <summary>
 /// Create a <see cref="NetMQSource{T}"/> from a <see cref="Rendezvous.NetMQSourceEndpoint"/>.
 /// </summary>
 /// <typeparam name="T">Type of data stream.</typeparam>
 /// <param name="endpoint"><see cref="Rendezvous.NetMQSourceEndpoint"/> from which to create .</param>
 /// <param name="pipeline">The pipeline to add the component to.</param>
 /// <param name="topic">Topic name.</param>
 /// <param name="deserializer">The deserializer to use to deserialize messages.</param>
 /// <param name="useSourceOriginatingTimes">Flag indicating whether or not to post with originating times received over the socket. If false, we ignore them and instead use pipeline's current time.</param>
 /// <returns><see cref="NetMQSource{T}"/>.</returns>
 public static NetMQSource <T> ToNetMQSource <T>(this Rendezvous.NetMQSourceEndpoint endpoint, Pipeline pipeline, string topic, IFormatDeserializer deserializer, bool useSourceOriginatingTimes = true)
 => new NetMQSource <T>(pipeline, topic, endpoint.Address, deserializer, useSourceOriginatingTimes);