Beispiel #1
0
        private async Task <IReadOnlyCollection <DiscoveredMethod> > DiscoverInternalAsync(
            MethodDiscoveryQuery query, bool online = false)
        {
            _log.Debug("Method discovery {0}", query);
            var task = _discoveryService.DiscoverAsync(query, online);

            _runningTasks[task] = Nothing.Instance;
            ((Task)task).ContinueWithSynchronously((Action <Task>)OnTaskCompleted).IgnoreAwait();
            var response = await task.ConfigureAwait(false);

            _log.Debug("Method discovery response: {0}", response);
            return(response);
        }
Beispiel #2
0
        private MethodDiscoveryQuery ConvertQuery <TRequest, TResponse>(MethodDiscoveryQuery <TRequest, TResponse> query)
        {
            Maybe <string> inputMessageId  = default;
            Maybe <string> outputMessageId = default;

            if (typeof(TRequest) != typeof(Nothing))
            {
                inputMessageId = _options.Marshaller.GetMarshaller <TRequest>().MessageId;
            }
            if (typeof(TResponse) != typeof(Nothing))
            {
                outputMessageId = _options.Marshaller.GetMarshaller <TResponse>().MessageId;
            }
            return(new MethodDiscoveryQuery(query.MethodReference, inputMessageId, outputMessageId));
        }
        public async Task <IReadOnlyCollection <DiscoveredMethod> > DiscoverAsync(MethodDiscoveryQuery query, ContextLinkageOptions contextLinkageDiscoveryOptions = null, bool online = false)
        {
            var channel = await _transportConnection.CreateChannelAsync().ConfigureAwait(false);

            try
            {
                using (var msg = _protocol.MessageFactory
                                 .CreateMethodDiscoveryRequest(
                           query.InputMessageId,
                           query.OutputMessageId,
                           Convert(query.MethodReference),
                           online ? DiscoveryMode.Online : DiscoveryMode.Offline,
                           contextLinkageDiscoveryOptions.Convert(_protocol.MessageFactory)))
                {
                    var serializedRequest = _protocol.Serializer.Serialize(msg);
                    try
                    {
                        await channel.Out.WriteAsync(new TransportMessageFrame(serializedRequest)).ConfigureAwait(false);

                        channel.Out.TryComplete();
                    }
                    catch
                    {
                        serializedRequest.Dispose();
                        throw;
                    }
                    using (var serializedResponse = (await channel.In.ReadAsync().ConfigureAwait(false)).Payload)
                    {
                        var discoveryResponse = _protocol.Serializer.DeserializeMethodDiscoveryResponse(serializedResponse);
                        return(Convert(discoveryResponse));
                    }
                }
            }
            catch (Exception ex)
            {
                channel.Out.TryTerminate(ex);
                throw;
            }
            finally
            {
                await channel.Completion.ConfigureAwait(false);
            }
        }
Beispiel #4
0
        public async Task <IReadOnlyCollection <DiscoveredOnlineMethod <TRequest, Nothing> > > DiscoverOnlineAsync <TRequest, TResponse>(MethodDiscoveryQuery <TRequest, Nothing> query)
        {
            var discoveryResults = await DiscoverInternalAsync(ConvertQuery(query), true).ConfigureAwait(false);

            return(discoveryResults.Select(x => new DiscoveredOnlineMethod <TRequest, Nothing>(x)).ToList());
        }
Beispiel #5
0
 public async Task <IReadOnlyCollection <DiscoveredMethod> > DiscoverAsync(MethodDiscoveryQuery query)
 {
     return(await DiscoverInternalAsync(query).ConfigureAwait(false));
 }
Beispiel #6
0
        public async Task <IReadOnlyCollection <DiscoveredOnlineMethod <TRequest, TResponse> > > DiscoverInSpecificContextAsync <TRequest, TResponse>(MethodDiscoveryQuery <TRequest, TResponse> query, string contextId)
        {
            var discoveryResults = await DiscoverInternalAsync(ConvertQuery(query), new ContextLinkageOptions(contextId), true).ConfigureAwait(false);

            return(discoveryResults.Select(x => new DiscoveredOnlineMethod <TRequest, TResponse>(x)).ToList());
        }
 internal MethodDiscoveryQuery(MethodDiscoveryQuery <TRequest, TResponse> query) : this(query.MethodReference)
 {
 }
 internal DuplexStreamingMethodDiscoveryQuery(MethodDiscoveryQuery <TRequest, TResponse> query) : base(query)
 {
 }
 internal UnaryMethodDiscoveryQuery(MethodDiscoveryQuery <TRequest, TResponse> query) : base(query)
 {
 }