예제 #1
0
        public Task <ICommandResult> ExecuteAsync(ICommand command, CommandReturnMode returnType, int timeoutMs)
        {
            var request = new Request()
            {
                Body = _serializer.Serialize(command)
            };

            request.Header = new Dictionary <string, string>()
            {
                { "Protocol", "1" },
                { "Type", command.GetType().Name },
                { "Model", ((int)returnType).ToString() },
                { "Timeout", timeoutMs.ToString() },
            };

            var channel = _channelFactory.GetChannel(commandClientConfigurationName, ProtocolCode.Command);

            if (channel == null)
            {
                throw new CommunicationException("Unable to connect to remote host.");
            }

            return
                (Task.Factory.FromAsync <Request, Response>(channel.BeginExecute, channel.EndExecute, request, null)
                 .ContinueWith <ICommandResult>(this.Parse));
        }
예제 #2
0
        public void Handle(Envelope <QueryResult> envelope)
        {
            var traceInfo = envelope.Items[StandardMetadata.TraceInfo] as TraceInfo;

            Assertions.NotNull(traceInfo, "traceInfo");

            var request = new Request()
            {
                Body   = _serializer.Serialize(envelope.Body),
                Header = new Dictionary <string, string>()
                {
                    { "Type", envelope.Body.GetType().Name },
                    { "TraceId", traceInfo.Id },
                }
            };

            var channel = _channelFactory.GetChannel(traceInfo.Address, ProtocolCode.Query);

            channel.BeginExecute(request, null, null);
        }