private async Task ReportServiceInstancePropertiesAsync(CancellationToken cancellationToken) { var properties = new AgentOsInfoRequest { HostName = DnsHelpers.GetHostName(), IpAddress = DnsHelpers.GetIpV4s(), OsName = PlatformInformation.GetOSName(), ProcessNo = Process.GetCurrentProcess().Id, Language = "dotnet" }; var request = new ServiceInstancePropertiesRequest { ServiceId = _config.ServiceName, ServiceInstanceId = _config.ServiceInstanceName, Properties = properties }; var result = await Polling(3, () => _serviceRegister.ReportInstancePropertiesAsync(request, cancellationToken), cancellationToken); if (result && RuntimeEnvironment is RuntimeEnvironment environment) { environment.Initialized = true; Logger.Information($"Reported Service Instance Properties[Service={request.ServiceId},InstanceId={request.ServiceInstanceId}]."); } }
public async Task <bool> ReportInstancePropertiesAsync(ServiceInstancePropertiesRequest serviceInstancePropertiesRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (_transportConfig.ProtocolVersion == ProtocolVersions.V8) { return(await _serviceRegisterV8.ReportInstancePropertiesAsync(serviceInstancePropertiesRequest, cancellationToken)); } return(true); }
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)); }