示例#1
0
        public async Task <SystemRegistration> QueryAsync(string name, VectorTimeStamp vts, string nsEndpoint = null)
        {
            nsEndpoint = nsEndpoint ?? NsEndpoint;
            if (string.IsNullOrWhiteSpace(nsEndpoint))
            {
                return(null);
            }
            RegClient.Connect(nsEndpoint, ZeroMQ.ZSocketType.REQ);
            Logger?.WriteLine($"Connected to NameServer at {nsEndpoint}");
            var packet = new Packet <NsQuery> {
                Payload = new NsQuery {
                    Name = name
                }, VectorTimeStamp = vts
            };
            var json = JsonConvert.SerializeObject(packet);
            SystemRegistration result = null;
            await RegClient.SendAsync($"QRY: {json}", (ZFrame frame) =>
            {
                if (frame == null)
                {
                    return;
                }
                var responseJson   = frame.ToString();
                var responsePacket = JsonConvert.DeserializeObject <Packet <SystemRegistration> >(responseJson);
                result             = responsePacket.Payload;
            });

            Logger?.WriteLine($"Queried for {SystemRegistration.Name}, Endpoint: {SystemRegistration.EndPoint}");

            await Awaiter.AwaitTrueAsync(() => { return(result != null); }, 5000);

            return(result);
        }
示例#2
0
        public async Task <bool> RegisterAsync(VectorTimeStamp vts = null, string nsEndpoint = null)
        {
            nsEndpoint = nsEndpoint ?? NsEndpoint;
            if (string.IsNullOrWhiteSpace(nsEndpoint))
            {
                return(false);
            }
            RegClient.Connect(nsEndpoint, ZeroMQ.ZSocketType.REQ);
            Logger?.WriteLine($"Connected to NameServer at {nsEndpoint}");
            var packet = new Packet <SystemRegistration> {
                Payload = SystemRegistration, VectorTimeStamp = vts ?? new VectorTimeStamp()
            };
            var json = JsonConvert.SerializeObject(packet);
            await RegClient.SendAsync($"REG: {json}", (ZFrame frame) => {
                if (frame == null)
                {
                    return;
                }
                var responseJson   = frame.ToString();
                var responsePacket = JsonConvert.DeserializeObject <Packet <SystemRegistration> >(responseJson);
                SystemRegistration = responsePacket.Payload;
                Endpoint           = SystemRegistration.EndPoint;
                IsRegistered       = true;
            });

            Logger?.WriteLine($"Sent system registration to NameServer. Name: {SystemRegistration.Name}, Endpoint: {SystemRegistration.EndPoint}");
            return(IsConnected);
        }
示例#3
0
 public void WriteLine(string message, VectorTimeStamp vts)
 {
     foreach (var logger in Loggers)
     {
         logger.WriteLine(message, vts);
     }
 }
示例#4
0
 public void WriteLine(string message, VectorTimeStamp vts)
 {
     Console.WriteLine(message, vts);
 }
示例#5
0
        public void WriteLine(string message, int id, DateTime?date = null)
        {
            var vts = new VectorTimeStamp().Update(id, date ?? DateTime.Now);

            Console.WriteLine(message, vts);
        }