Beispiel #1
0
        public Task OpenAsync()
        {
            var connectedObservable =
                Observable.FromEventPattern <WampConnectionEstablishedEventArgs>
                    (x => mConnectionMonitor.ConnectionEstablished += x,
                    x => mConnectionMonitor.ConnectionEstablished  -= x)
                .Select(x => Unit.Default);

            var errorObservable =
                Observable.FromEventPattern <WampConnectionErrorEventArgs>
                    (x => mConnectionMonitor.ConnectionError += x,
                    x => mConnectionMonitor.ConnectionError  -= x)
                .Select(x => Observable.Throw <Unit>(x.EventArgs.Exception))
                .SelectMany(x => x);

            var completedObservable =
                Observable.FromEventPattern
                    (x => mConnectionMonitor.ConnectionLost += x,
                    x => mConnectionMonitor.ConnectionLost  -= x)
                .Select(x => Unit.Default);

            // Combining the observables and propagating the one that reatcs first
            // because we have to complete the task either when a connection is established or
            // an error (i.e. exception) occurs.
            var combined = connectedObservable.Amb(errorObservable).Amb(completedObservable);

            var firstConnectionOrError =
                combined.Take(1);

            Task task = firstConnectionOrError.ToTask();

            mConnection.Connect();

            return(task);
        }
Beispiel #2
0
        public void Connect()
        {
            if (mConnection == null)
            {
                mConnection = SetupConnection();
            }

            mConnection.Connect();
        }
Beispiel #3
0
        private void OnNewConnection(IWampConnection <TMessage> connection)
        {
            mSubject.OnNext(connection);

            // Yuck
            IControlledWampConnection <TMessage> casted = connection as IControlledWampConnection <TMessage>;

            casted.Connect();
        }
Beispiel #4
0
        public void OnNext(IWampConnection <TMessage> value)
        {
            mSubject.OnNext(value);

            // Yuck
            IControlledWampConnection <TMessage> casted = value as IControlledWampConnection <TMessage>;

            if (casted != null)
            {
                casted.Connect();
            }
        }
Beispiel #5
0
 public Task Open()
 {
     if (Interlocked.CompareExchange(ref mConnectCalled, 1, 0) != 0)
     {
         // Throw something that says that "Open was already called."
         throw new ArgumentException();
     }
     else
     {
         Task openTask = mClient.OpenTask;
         mConnection.Connect();
         return(openTask);
     }
 }
 public void Connect()
 {
     mConnection.Connect();
 }