예제 #1
0
        public void EncodeDecodeDiscoveryResponse()
        {
            var response = new DiscoveryResponse("tcpex://some:123/SomeService", "1.0");
            var encoded  = DiscoveryMetadataHelper.Encode(response);
            var decoded  = DiscoveryMetadataHelper.Decode(encoded);

            Assert.IsNotNull(decoded);
            Assert.AreEqual(response, decoded);
        }
예제 #2
0
        public void EncodeDecodeDiscoveryRequest()
        {
            var request = new DiscoveryRequest("SomeService");
            var encoded = DiscoveryMetadataHelper.Encode(request);
            var decoded = DiscoveryMetadataHelper.Decode(encoded);

            Assert.IsNotNull(decoded);
            Assert.AreEqual(request, decoded);
        }
예제 #3
0
        public void EncodeSampleDiscoveryPacket()
        {
            var dp = new SamplePacket();

            dp.Version            = "1.0";
            dp.Properties["Name"] = "Dummy";

            var packet = DiscoveryMetadataHelper.Encode(dp);

            Assert.IsNotNull(packet);
            Assert.IsTrue(packet.Length == 110);
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiscoveryServer"/> class.
        /// </summary>
        /// <param name="responseMetadata">The response metadata.</param>
        /// <param name="port">The port to bind to.</param>
        /// <param name="localAddress">The local address to bind to.</param>
        public DiscoveryServer(DiscoveryMetadata responseMetadata, int port = DefaultDiscoveryPort, IPAddress localAddress = null)
        {
            if (responseMetadata == null)
            {
                throw new ArgumentNullException("responseMetadata", "Discovery response metadata is missing.");
            }

            Port                   = port;
            LocalAddress           = localAddress ?? IPAddress.Any;
            ResponseMetadata       = responseMetadata;
            ResponseMetadataPacket = DiscoveryMetadataHelper.Encode(ResponseMetadata);
        }
예제 #5
0
        public void DecodeSampleDiscoveryPacket()
        {
            var dp = new SamplePacket();

            dp.Version    = "EDC35F23-60AD-4730-A9AC-23D57B666DC1";
            dp.ServiceUri = @"tcp://msdn.microsoft.com/en-us/library/tst0kwb1(v=vs.110).aspx|Something=Else|#5235@#$%\a\p\|@@";
            dp.Properties["ExtraProperty"] = @"#%@$%45654!@#$\4214\|Shame=Value";
            DiscoveryMetadataHelper.RegisterDiscoveryMetadataFactory(dp.Signature, () => new SamplePacket());

            var packet  = DiscoveryMetadataHelper.Encode(dp);
            var decoded = DiscoveryMetadataHelper.Decode(packet);

            Assert.IsNotNull(decoded);
            Assert.AreEqual(decoded.GetType(), typeof(SamplePacket));
            Assert.AreEqual(dp, decoded);
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiscoveryClient"/> class.
        /// </summary>
        /// <param name="requestMetadata">The request metadata.</param>
        /// <param name="port">The port of the discovery server.</param>
        public DiscoveryClient(DiscoveryMetadata requestMetadata, int port = DiscoveryServer.DefaultDiscoveryPort)
        {
            if (requestMetadata == null)
            {
                throw new ArgumentNullException("requestMetadata", "Discovery request metadata is missing.");
            }

            Port                  = port;
            RequestMetadata       = requestMetadata;
            RequestMetadataPacket = DiscoveryMetadataHelper.Encode(RequestMetadata);
            DestinationAddress    = IPAddress.Broadcast;
            DestinationEndpoint   = new IPEndPoint(DestinationAddress, Port);
            Results               = new HashSet <DiscoveryMetadata>();
            RetryTimeout          = TimeSpan.FromSeconds(1);
            RetryCount            = 10;
        }