示例#1
0
        public async Task Registers_Service()
        {
            // check weather service was registred and is now listed
            var service = await _serviceStore.FindByServiceIdAsync("TestSelfService");

            service.Should().NotBeNull();

            service.ServiceId.Should().Be("TestSelfService");
            service.DisplayName.Should().Be("My Test");
            service.Endpoints.Should().HaveCountGreaterThan(0);
            service.IpAddresses.Should().HaveCountGreaterThan(0);
        }
示例#2
0
        /// <summary>
        /// Registers a new service
        /// </summary>
        /// <param name="registration">The registration information</param>
        /// <returns>A token which can be used to unregister the service</returns>
        public async Task <string> RegisterAsync(ServiceRegistrationInputModel registration)
        {
            var service = await _store.FindByServiceIdAsync(registration.ServiceId);

            if (service == null)
            {
                service = new Service()
                {
                    DisplayName = registration.DisplayName,
                    ServiceId   = registration.ServiceId,
                    Endpoints   = registration.Endpoints,
                    IpAddresses = new[] { registration.IpAddress },
                    PublicUrls  = registration.PublicUrls
                };
            }
            else
            {
                service.Endpoints = service.Endpoints.Concat(registration.Endpoints).ToArray();

                if (!string.IsNullOrWhiteSpace(registration.IpAddress))
                {
                    if (service.IpAddresses != null)
                    {
                        service.IpAddresses = service.IpAddresses.Concat(new[] { registration.IpAddress }).ToArray();
                    }
                    else
                    {
                        service.IpAddresses = new[] { registration.IpAddress }
                    };
                }

                if (registration.PublicUrls?.Length > 0)
                {
                    if (service.PublicUrls != null)
                    {
                        service.PublicUrls = service.PublicUrls.Concat(registration.PublicUrls).Distinct().ToArray();
                    }
                    else
                    {
                        service.PublicUrls = registration.PublicUrls;
                    }
                }
            }

            await _store.StoreAsync(service);

            return(await _tokenProvider.GenerateAsync(registration));
        }
 /// <summary>
 /// Gets the service by id
 /// </summary>
 /// <param name="serviceId">The identifier to find the service</param>
 /// <returns></returns>
 public Task <Service> FindByServiceIdAsync(string serviceId)
 {
     return(_cache.GetAsync(serviceId, _options.Caching.ServiceStoreExpiration, () => _inner.FindByServiceIdAsync(serviceId)));
 }