aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs
blob: 94e20a8b4349eaa45aaf85c764deb1731a2e4f5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Transport.Discovery
{
    /// <summary>
    /// Represents a discovery client 
    /// </summary>
    /// <seealso cref="System.EventArgs" />
    public class DiscoveredService<DiscoveryMessage> : EventArgs where DiscoveryMessage : IMessage
    {
        private Func<bool> _validateDiscoveryAction;

        /// <summary>
        /// Gets or sets the discovery message.
        /// </summary>
        public DiscoveryMessage Message { get; set; }

        /// <summary>
        /// Gets or sets the service IP address.
        /// </summary>
        public String Address { get; set; }

        /// <summary>
        /// Gets or sets the name of the host.
        /// </summary>
        public String HostName { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="DiscoveredService{DiscoveryMessage}"/> class.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="message">The message.</param>
        /// <param name="hostName">The host name.</param>
        public DiscoveredService(String address, String hostName, DiscoveryMessage message, Func<bool> validateDiscoveryAction)
        {
            HostName = hostName;
            Address = address;
            Message = message;
            _validateDiscoveryAction = validateDiscoveryAction;
        }

        /// <summary>
        /// Validates the service existence using a TCP request.
        /// </summary>
        /// <returns></returns>
        public bool ValidateServiceExistence()
        {
            return _validateDiscoveryAction();
        }
    }
}