Exemplo n.º 1
0
		public async Task<GetServiceInfoResponse> GetServiceInfoAsync(GetServiceInfoRequest request)
		{
			if (!(request?.Services?.Length > 0))
				return new GetServiceInfoResponse();

			var results = await GetResultsAsync(request.Services).ConfigureAwait(false);
			var response = new GetServiceInfoResponse
			{
				Services = results
			};
			return response;
		}
Exemplo n.º 2
0
		public GetServiceInfoResponse GetServiceInfo(GetServiceInfoRequest request)
		{
			if (!(request?.Services?.Length > 0))
				return new GetServiceInfoResponse();

			var results = GetResultsAsync(request.Services);
			var response = new GetServiceInfoResponse
			{
				Services = results.Result
			};
			return response;
		}
Exemplo n.º 3
0
        public GetServiceInfoResponse GetServiceInfo(GetServiceInfoRequest request)
        {
            throw new NotImplementedException();
            //if (request == null)
            //	return new GetServiceInfoResponse();

            //var response = new GetServiceInfoResponse
            //{
            //	ServiceName = request.ServiceName,
            //	//Namespace = request.Namespace,
            //	Group = request.Group,
            //	Address = ServiceDal.GetServiceInfo(request.ServiceName, request.Group)
            //};

            //return response;
        }
Exemplo n.º 4
0
        private ServiceInfo[] GetAddressInternal(string name, string group)
        {
            var itemKey = new ServiceIdentifier(name, group);
            // ReSharper disable once InconsistentlySynchronizedField
            var url = _defaultBaseUrlDictionary.GetOrAdd(itemKey, key =>
            {
                if (key == ServiceIdentifier.Empty) return null;
                if (_registryClient.Value == null) return null;

                var request = new GetServiceInfoRequest
                {
                    Services = new[]
                    {
                        new ServiceIdentifierDto
                        {
                            Name = name,
                            Group = group,
                        }
                    }
                };
                try
                {
                    var response = _registryClient.Value.GetServiceInfo(request);
                    var result = response.Services.FirstOrDefault();
                    var serviceInfos = result?.ServiceInfos
                        .Select(it => new ServiceInfo
                        {
                            Name = name,
                            Group = group,
                            Address = it.Address,
                            Data = it.Data,
                        })
                        .ToArray();

                    _updateTimeDic.AddOrUpdate(itemKey, DateTime.Now, (k, oldValue) => DateTime.Now);

                    return serviceInfos;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    throw;
                }
            });

            return url;
        }
Exemplo n.º 5
0
        private void DoUpdate()
        {
            var toUpdateServices = _updateTimeDic
                .Where(it => (DateTime.Now - it.Value).TotalSeconds > UpdateInterval)
                .Select(it => it.Key)
                .ToArray();

            var services = toUpdateServices
                .Select(it => new ServiceIdentifierDto
                {
                    Name = it.Name,
                    Group = it.Group
                })
                .ToArray();

            if (services.Length == 0) return;

            var request = new GetServiceInfoRequest { Services = services };

            try
            {
                var response = _registryClient.Value.GetServiceInfo(request);
                foreach (var item in response.Services)
                {
                    var serviceInfos = item.ServiceInfos
                        ?.Select(it => new ServiceInfo
                        {
                            Name = it.Name,
                            Group = it.Group,
                            Address = it.Address,
                            Data = it.Data,
                        })
                        .ToArray();

                    var key = new ServiceIdentifier(item.Identifier.Name, item.Identifier.Group);
                    _defaultBaseUrlDictionary[key] = serviceInfos;
                    _updateTimeDic.AddOrUpdate(key, DateTime.Now, (k, oldValue) => DateTime.Now);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
        }
Exemplo n.º 6
0
 public Task<GetServiceInfoResponse> GetServiceInfoAsync(GetServiceInfoRequest request)
 {
     return Task.FromResult(GetServiceInfo(request));
 }