public async Task <bool> ReportInstancePropertiesAsync(ServiceInstancePropertiesRequest serviceInstancePropertiesRequest, CancellationToken cancellationToken = default)
        {
            if (!_connectionManager.Ready)
            {
                return(false);
            }

            var connection = _connectionManager.GetConnection();

            return(await new Call(_logger, _connectionManager).Execute(async() =>
            {
                var client = new ManagementService.ManagementServiceClient(connection);
                var instance = new InstanceProperties
                {
                    Service = serviceInstancePropertiesRequest.ServiceId,
                    ServiceInstance = serviceInstancePropertiesRequest.ServiceInstanceId,
                };

                instance.Properties.Add(new KeyStringValuePair
                {
                    Key = OS_NAME, Value = serviceInstancePropertiesRequest.Properties.OsName
                });
                instance.Properties.Add(new KeyStringValuePair
                {
                    Key = HOST_NAME, Value = serviceInstancePropertiesRequest.Properties.HostName
                });
                instance.Properties.Add(new KeyStringValuePair
                {
                    Key = PROCESS_NO, Value = serviceInstancePropertiesRequest.Properties.ProcessNo.ToString()
                });
                instance.Properties.Add(new KeyStringValuePair
                {
                    Key = LANGUAGE, Value = serviceInstancePropertiesRequest.Properties.Language
                });
                foreach (var ip in serviceInstancePropertiesRequest.Properties.IpAddress)
                {
                    instance.Properties.Add(new KeyStringValuePair
                    {
                        Key = IPV4, Value = ip
                    });
                }

                var mapping = await client.reportInstancePropertiesAsync(instance,
                                                                         _config.GetMeta(), _config.GetTimeout(), cancellationToken);

                //todo: should assert the result?
                return true;
            },
                                                                       () => false,
                                                                       () => ExceptionHelpers.ReportServiceInstancePropertiesError));
        }
Beispiel #2
0
        public Task PingAsync(PingRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!_connectionManager.Ready)
            {
                return(Task.CompletedTask);
            }

            var connection = _connectionManager.GetConnection();

            return(new Call(_logger, _connectionManager).Execute(async() =>
            {
                var client = new ManagementService.ManagementServiceClient(connection);
                await client.keepAliveAsync(new InstancePingPkg
                {
                    Service = request.ServiceName,
                    ServiceInstance = request.InstanceId,
                }, _config.GetMeta(), _config.GetTimeout(), cancellationToken);
            },
                                                                 () => ExceptionHelpers.PingError));
        }