Beispiel #1
0
        /// <summary>
        /// Unregisters a service
        /// </summary>
        /// <param name="token">The registration token</param>
        /// <returns></returns>
        public async Task UnregisterAsync(string token)
        {
            var serviceRegistration = await _tokenProvider.ValidateAsync(token);

            if (serviceRegistration != null)
            {
                var item = await _store.FindByServiceIdAsync(serviceRegistration.ServiceId);

                if (item != null)
                {
                    // remove endpoints from service
                    item.Endpoints = item.Endpoints.Except(serviceRegistration.Endpoints).ToArray();
                    // remove ipaddress from service
                    item.IpAddresses = item.IpAddresses.Except(new[] { serviceRegistration.IpAddress }).ToArray();

                    // remove service when no endpoints registered anymore
                    if (item.Endpoints.Length > 0)
                    {
                        await _store.StoreAsync(item);
                    }
                    else
                    {
                        await _store.RemoveAsync(serviceRegistration.ServiceId);
                    }
                }
            }
        }
        /// <summary>
        /// Removes a service from the store
        /// </summary>
        /// <param name="serviceId">The service identifier.</param>
        /// <returns></returns>
        public async Task RemoveAsync(string serviceId)
        {
            await _inner.RemoveAsync(serviceId);

            await _cache.RemoveAsync(serviceId);
        }