Exemple #1
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>
        /// Stores the service
        /// </summary>
        /// <param name="service">The service to store.</param>
        /// <returns></returns>
        public async Task StoreAsync(Service service)
        {
            await _cache.RemoveAsync(service.ServiceId);

            await _inner.StoreAsync(service);

            await _cache.SetAsync(service.ServiceId, service, _options.Caching.ServiceStoreExpiration);
        }