예제 #1
0
        /// <summary>
        /// Method for fetching the <see cref="ServiceInformation"/>. This method can be used for connection checking. The call returns quickly
        /// and does not produce any noticeable server load.
        /// </summary>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public async Task <ServiceInformation> GetServiceInformation(CancellationToken cancellationToken = default(CancellationToken))
        {
            var serviceInformation = await GetServiceInformationInternal(FetchBehavior.FetchAlways, cancellationToken).ConfigureAwait(false);

            _LastValidServiceInformation = serviceInformation;

            return(_LastValidServiceInformation);
        }
예제 #2
0
        private async Task <ServiceInformation> GetServiceInformationInternal(FetchBehavior behavior, CancellationToken cancellationToken = default(CancellationToken))
        {
            // This is an intentional race condition. Calling this method from multiple threads may lead to multiple calls to Get<ServiceInformation>().
            // However, this would be rare and harmless, since it should always return the same result. It would be a lot more difficult to make this work without any races or blocking.
            // It is important to never set _LastValidServiceInformation to null anywhere to avoid possible null returns here due to the race condition.
            if (behavior == FetchBehavior.FetchAlways || _LastValidServiceInformation == null)
            {
                var serviceInformation = await _RestClient.Request <ServiceInformation>(RequestBuilder.CreateGet("ServiceInformation"), cancellationToken).ConfigureAwait(false);

                _LastValidServiceInformation = serviceInformation;
            }

            return(_LastValidServiceInformation);
        }