Beispiel #1
0
 public ObjectClient(IClient client, IFormatSerializer serializer, HeaderDictionary headers, Encoding encoding)
 {
     Client     = client;
     Serializer = serializer;
     Headers    = headers;
     Encoding   = encoding;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetMQWriter"/> class.
 /// </summary>
 /// <param name="pipeline">Pipeline to which this component belongs</param>
 /// <param name="address">Connection string</param>
 /// <param name="serializer">Format serializer with which messages are serialized</param>
 public NetMQWriter(Pipeline pipeline, string address, IFormatSerializer serializer)
 {
     this.pipeline         = pipeline;
     this.serializer       = serializer;
     this.socket           = new PublisherSocket();
     pipeline.PipelineRun += (s, e) => this.socket.Bind(address);
 }
Beispiel #3
0
 void IBusManager.AddSerializer(IFormatSerializer serializer)
 {
     if (LoadManager != null)
     {
         LoadManager.AddSerializer(serializer);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpWriter{T}"/> class.
 /// </summary>
 /// <param name="pipeline">The pipeline to add the component to.</param>
 /// <param name="port">The connection port.</param>
 /// <param name="serializer">The serializer to use to serialize messages.</param>
 /// <param name="name">An optional name for the component.</param>
 public TcpWriter(Pipeline pipeline, int port, IFormatSerializer serializer, string name = nameof(TcpWriter <T>))
 {
     this.serializer = serializer;
     this.name       = name;
     this.Port       = port;
     this.In         = pipeline.CreateReceiver <T>(this, this.Receive, nameof(this.In));
     this.listener   = new TcpListener(IPAddress.Any, port);
     this.Start();
 }
Beispiel #5
0
        public void AddSerializer(IFormatSerializer serializer)
        {
            string key = serializer.FormatExtension.ToUpper();

            if (_formats.ContainsKey(key))
            {
                throw new ArgumentException(string.Format("Cannot add serializer for extension \"{0}\", because there is another serializer exists for the same extension", serializer.FormatExtension));
            }
            _formats.Add(key, serializer);
        }
Beispiel #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);
        }
Beispiel #7
0
        private void AssertStringSerialization(dynamic value, string expected, IFormatSerializer serializer, IFormatDeserializer deserializer)
        {
            var serialized = serializer.SerializeMessage(value, originatingTime);

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

            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));
        }
Beispiel #8
0
        public IFormatSerializer GetSerializer(string ext)
        {
            ext = ext.ToUpper();
            IFormatSerializer serializer = null;

            if (ext.Length >= 2 && ext.Substring(0, 2) == ".!" || ext.Substring(0, 2) == ".$")
            {
                serializer = _formats["$"];
            }
            else
            {
                if (ext.StartsWith("."))
                {
                    ext = ext.Substring(1, ext.Length - 1);
                }
                if (_formats.ContainsKey(ext))
                {
                    serializer = _formats[ext];
                }
            }
            return(serializer);
        }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetMQWriter{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="serializer">Format serializer with which messages are serialized</param>
 public NetMQWriter(Pipeline pipeline, string topic, string address, IFormatSerializer serializer)
     : base(pipeline, address, serializer)
 {
     this.In = this.AddTopic <T>(topic);
 }
Beispiel #10
0
 public ObjectClient(IClient client, IFormatSerializer serializer, HeaderDictionary headers)
     : this(client, serializer, headers, Encoding.UTF8)
 {
 }