Exemple #1
0
        public override IObservable <ClientTermination> Listen(
            QbservableServiceOptions options,
            Func <IQbservableProtocol, IParameterizedQbservableProvider> providerFactory)
        => from transport in clients
        from result in Observable.FromAsync(async() =>
        {
            // TODO: Most of this code is boiler-plate and should be moved into the core library.
            var watch = Stopwatch.StartNew();

            var exceptions     = new List <ExceptionDispatchInfo>();
            var shutdownReason = QbservableProtocolShutdownReason.None;

            try
            {
                using (var protocol = new TestQbservableProtocol(transport.GetHashCode(), transport.NextRight, transport.Left, options))
                {
                    var provider = providerFactory(protocol);

                    try
                    {
                        await protocol.ExecuteServerAsync(provider).ConfigureAwait(false);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ExceptionDispatchInfo.Capture(ex));
                    }
                    finally
                    {
                        shutdownReason = protocol.ShutdownReason;
                    }

                    var protocolExceptions = protocol.Exceptions;

                    if (protocolExceptions != null)
                    {
                        foreach (var exception in protocolExceptions)
                        {
                            exceptions.Add(exception);
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationCanceled;
            }
            catch (Exception ex)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationError;

                exceptions.Add(ExceptionDispatchInfo.Capture(ex));
            }

            return(new ClientTermination(watch.Elapsed, shutdownReason, exceptions));
        })
        select result;
 public ServerDuplexSink(TestQbservableProtocol protocol)
 {
     Protocol = protocol;
 }