public IContextLinkageOptions CreateContextLinkageOptions(ContextLinkageDiscoveryMode contextLinkageDiscoveryMode, Maybe <string> specificContextId = default)
        {
            var obj = ContextLinkageOptions.Rent();

            obj.Mode            = contextLinkageDiscoveryMode;
            obj.SpecificContext = specificContextId;
            return(obj);
        }
 private IContextLinkageOptions ConvertFromProtoStrict(ContextLinkageOptions proto)
 {
     if (proto == null || proto.ModeCase == ContextLinkageOptions.ModeOneofCase.None)
     {
         return(_messageFactory.CreateContextLinkageOptions(ContextLinkageDiscoveryMode.None, Maybe <string> .Nothing));
     }
     return(_messageFactory.CreateContextLinkageOptions(
                ConvertFromProto(proto.ModeCase),
                proto.ModeCase == ContextLinkageOptions.ModeOneofCase.SpecificContextId
             ? new Maybe <string>(proto.SpecificContextId)
             : Maybe <string> .Nothing));
 }
示例#3
0
        private async Task <IReadOnlyCollection <DiscoveredService> > DiscoverInternalAsync(
            ServiceDiscoveryQuery query, ContextLinkageOptions contextLinkageDiscoveryOptions = null, bool online = false)
        {
            _log.Debug("Service discovery {0}", query);
            var task = _discoveryService.DiscoverAsync(query, contextLinkageDiscoveryOptions, online);

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

            _log.Debug("Service discovery response: {0}", response.FormatEnumerable());
            return(response);
        }
        private ContextLinkageOptions ConvertToProto(IContextLinkageOptions obj)
        {
            var proto = ContextLinkageOptions.Rent();

            if (obj != null)
            {
                switch (obj.Mode)
                {
                case ContextLinkageDiscoveryMode.None:
                    proto.ClearMode();
                    break;

                case ContextLinkageDiscoveryMode.SpecificContext:
                    proto.SpecificContextId = obj.SpecificContext.Value;
                    break;

                case ContextLinkageDiscoveryMode.CurrentContext:
                    proto.CurrentContext = Empty.Instance;
                    break;
                }
            }
            return(proto);
        }
示例#5
0
 public IUnaryMethodCall <TResponse> Call <TRequest, TResponse>(IUnaryMethod <TRequest, TResponse> method, TRequest request, ContextLinkageOptions contextLinkageOptions = default)
 {
     return(CallUnary <TRequest, TResponse>(method.CallDescriptor, request, contextLinkageOptions));
 }
示例#6
0
        public IUnaryMethodCall CallUnary <TRequest>(MethodCallDescriptor descriptor, TRequest request, ContextLinkageOptions contextLinkageOptions = default)
        {
            _log.Debug("Starting unary call: {0}", descriptor);
            var call = new UnaryMethodCall <TRequest, Nothing>(() => _outcomingInvocationFactory.CreateAsync <TRequest, Nothing>(descriptor, request, contextLinkageOptions));

            call.Start();
            return(call);
        }
示例#7
0
 public IUnaryMethodCall Call <TRequest>(IUnaryMethod <TRequest, Nothing> method, TRequest request, ContextLinkageOptions contextLinkageOptions = default)
 {
     return(CallUnary(method.CallDescriptor, request, contextLinkageOptions));
 }
示例#8
0
        public async Task <IReadOnlyCollection <DiscoveredOnlineService> > DiscoverInCurrentContextAsync(ServiceDiscoveryQuery query)
        {
            var discoveryResults = await DiscoverInternalAsync(query, ContextLinkageOptions.WithCurrentContext(), true).ConfigureAwait(false);

            return(discoveryResults.Select(x => new DiscoveredOnlineService(x)).ToList());
        }
示例#9
0
        public IDuplexStreamingMethodCall <TRequest, TResponse> CallDuplexStreaming <TRequest, TResponse>(MethodCallDescriptor descriptor, ContextLinkageOptions contextLinkageOptions = default)
        {
            _log.Debug("Starting duplex streaming call: {0}", descriptor);
            var call = new DuplexStreamingMethodCall <TRequest, TResponse>(() => _outcomingInvocationFactory.CreateAsync <TRequest, TResponse>(descriptor, contextLinkageOptions: contextLinkageOptions));

            call.Start();
            return(call);
        }
示例#10
0
        public async Task <IReadOnlyCollection <DiscoveredOnlineMethod <TRequest, TResponse> > > DiscoverInCurrentContextAsync <TRequest, TResponse>(MethodDiscoveryQuery <TRequest, TResponse> query)
        {
            var discoveryResults = await DiscoverInternalAsync(ConvertQuery(query), ContextLinkageOptions.WithCurrentContext(), true).ConfigureAwait(false);

            return(discoveryResults.Select(x => new DiscoveredOnlineMethod <TRequest, TResponse>(x)).ToList());
        }
示例#11
0
 public IDuplexStreamingMethodCall <TRequest, TResponse> Call <TRequest, TResponse>(IDuplexStreamingMethod <TRequest, TResponse> method, ContextLinkageOptions contextLinkageOptions = default)
 {
     return(CallDuplexStreaming <TRequest, TResponse>(method.CallDescriptor, contextLinkageOptions));
 }
示例#12
0
 public IServerStreamingMethodCall <TResponse> Call <TRequest, TResponse>(IServerStreamingMethod <TRequest, TResponse> method, TRequest request, ContextLinkageOptions contextLinkageOptions = default)
 {
     return(CallServerStreaming <TRequest, TResponse>(method.CallDescriptor, request, contextLinkageOptions));
 }
示例#13
0
        public IClientStreamingMethodCall <TRequest, TResponse> CallClientStreaming <TRequest, TResponse>(MethodCallDescriptor descriptor, ContextLinkageOptions contextLinkageOptions = default)
        {
            CheckConnectionState();
            _log.Debug("Starting client streaming call: {0}", descriptor);
            var call = new ClientStreamingMethodCall <TRequest, TResponse>(() => _outcomingInvocationFactory.CreateAsync <TRequest, TResponse>(descriptor, contextLinkageOptions: contextLinkageOptions));

            call.Start();
            return(call);
        }
示例#14
0
 public IClientStreamingMethodCall <TRequest, TResponse> Call <TRequest, TResponse>(IClientStreamingMethod <TRequest, TResponse> method, ContextLinkageOptions contextLinkageOptions = default)
 {
     CheckConnectionState();
     return(CallClientStreaming <TRequest, TResponse>(method.CallDescriptor, contextLinkageOptions));
 }
示例#15
0
        public async Task <IReadOnlyCollection <DiscoveredService> > DiscoverAsync(ServiceDiscoveryQuery query, ContextLinkageOptions contextLinkageDiscoveryOptions = null, bool online = false)
        {
            var channel = await _transportConnection.CreateChannelAsync().ConfigureAwait(false);

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

                    channel.Out.TryComplete();
                    using (var serializedResponse = (await channel.In.ReadAsync().ConfigureAwait(false)).Payload)
                    {
                        var discoveryResponse = _protocol.Serializer.DeserializeServiceDiscoveryResponse(serializedResponse);
                        return(Convert(discoveryResponse));
                    }
                }
            }
            catch (Exception ex)
            {
                channel.Out.TryTerminate(ex);
                throw;
            }
            finally
            {
                await channel.Completion.ConfigureAwait(false);
            }
        }