Esempio n. 1
0
        /// <exception cref="System.TimeoutException">Thrown when no response to publish service request.</exception>
        /// <exception cref="System.AggregateException">Thrown if publish service request failed.</exception>
        public IDisposable ProvideOptionally <TRequest, TResponse>(Func <TRequest, Optional <TResponse> > func)
            where TRequest : IRequestData <TResponse>
            where TResponse : IResponseData
        {
            var requestType = typeof(TRequest);

            if (!_implements.Contains(requestType))
            {
                var publishServiceRequest = new PublishServiceRequest(new[] { requestType.GetPayloadTypeName() });
                if (!_requestSender.Send(publishServiceRequest)
                    .Wait(TimeSpan.FromSeconds(30)))
                {
                    throw new TimeoutException("Publish service request timed out.");
                }

                // This is a bit race condition prone, however does not matter.
                // There are no problems with sending publish service request more than one time.
                _implements.Add(requestType);
            }

            return(_receiver.SubscribeToRequest(func));
        }