Ejemplo n.º 1
0
        IAsyncResult BeginPoll(MakeConnectionDuplexClientChannel <TChannel> channel, AsyncCallback callback, object state)
        {
            TChannel channelToUse = channel.GetChannelForPoll();

            this.outstandingPoll = new PollAsyncResult <TChannel>(channel, channelToUse, callback, state);
            return(this.outstandingPoll);
        }
Ejemplo n.º 2
0
        public static MakeConnectionPoller <TChannel> AddChannelToPoller(MakeConnectionDuplexClientChannel <TChannel> channel)
        {
            MakeConnectionPoller <TChannel> poller = GetForUri(channel.RemoteAddress.Uri);

            poller.AddChannel(channel);
            poller.messageVersion = channel.GetProperty <MessageVersion>();
            return(poller);
        }
Ejemplo n.º 3
0
        void EnqueueException(Exception e)
        {
            MakeConnectionDuplexClientChannel <TChannel> channelsToFault = this.channel;

            if (channelsToFault != null)
            {
                channelsToFault.EnqueueException(e);
            }
        }
Ejemplo n.º 4
0
        void EndPoll(IAsyncResult result)
        {
            Message message = null;

            try
            {
                this.outstandingPoll = null;
                message = PollAsyncResult <TChannel> .End(result);

                if (message != null && message.IsFault)
                {
                    MessageFault fault = MessageFault.CreateFault(message, MakeConnectionConstants.Defaults.MaxFaultSize);
                    MakeConnectionMessageFault wsmcFault;

                    if (MakeConnectionMessageFault.TryCreateFault(message, fault, out wsmcFault))
                    {
                        throw MakeConnectionMessageFault.CreateException(wsmcFault);
                    }
                }
            }
            catch (TimeoutException)
            {
            }
            catch (Exception e)
            {
                EnqueueException(e);
            }

            if (message != null)
            {
                MakeConnectionDuplexClientChannel <TChannel> channelToDispatch = this.channel;
                if (channelToDispatch != null)
                {
                    channelToDispatch.EnqueueAndDispatch(message, null, false);
                }
            }

            lock (ThisLock)
            {
                polling = false;

                if (this.channel != null && !stopPolling)
                {
                    ThreadPool.QueueUserWorkItem(onEnsurePollingLater, this);
                }
                else
                {
                    this.pollingComplete.Set();
                }
            }
        }
Ejemplo n.º 5
0
        public void EnsurePolling(MakeConnectionDuplexClientChannel <TChannel> channel)
        {
            bool shouldSchedule = false;

            lock (ThisLock)
            {
                shouldSchedule = !polling;
            }

            if (shouldSchedule)
            {
                ThreadPool.QueueUserWorkItem(onEnsurePollingLater, this);
            }
        }
Ejemplo n.º 6
0
            public CloseAsyncResult(TimeSpan timeout, MakeConnectionDuplexClientChannel <TChannel> channel, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.channel       = channel;
                this.timeoutHelper = new TimeoutHelper(timeout);

                IAsyncResult result = channel.poller.BeginClose(timeoutHelper.RemainingTime(), onClosePollerComplete, this);

                if (result.CompletedSynchronously)
                {
                    if (CompleteClosePoller(result))
                    {
                        base.Complete(true);
                    }
                }
            }
Ejemplo n.º 7
0
            public PollAsyncResult(
                MakeConnectionDuplexClientChannel <T> channel,
                T innerChannel,
                AsyncCallback callback,
                object state)
                : base(callback, state)
            {
                this.channel      = channel;
                this.timeout      = new TimeoutHelper(channel.ClientPollTimeout);
                this.innerChannel = innerChannel;

                this.pollingMessage = GetPollingMessage();

                IAsyncResult result = innerChannel.BeginRequest(pollingMessage, timeout.RemainingTime(), onRequestComplete, this);

                if (result.CompletedSynchronously)
                {
                    CompleteRequest(result);
                    base.Complete(true);
                }
            }
Ejemplo n.º 8
0
        void EnsurePollingCore()
        {
            bool shouldPoll = false;
            MakeConnectionDuplexClientChannel <TChannel> channelToPoll = null;

            if (!polling)
            {
                lock (ThisLock)
                {
                    if (!polling)
                    {
                        if (stopPolling)
                        {
                            this.pollingComplete.Set();
                        }
                        else
                        {
                            channelToPoll = this.channel;

                            if (channelToPoll != null)
                            {
                                polling = shouldPoll = true;
                            }
                        }
                    }
                }
            }

            if (shouldPoll)
            {
                IAsyncResult result = BeginPoll(channelToPoll, onPollComplete, this);
                if (result.CompletedSynchronously)
                {
                    EndPoll(result);
                }
            }
        }
Ejemplo n.º 9
0
 public void AddChannel(MakeConnectionDuplexClientChannel <TChannel> channel)
 {
     channel.Opened  += onChannelOpened;
     channel.Closed  += onChannelClosedOrFaulted;
     channel.Faulted += onChannelClosedOrFaulted;
 }
Ejemplo n.º 10
0
 void OnChannelClosedOrFaulted(object sender, EventArgs e)
 {
     this.channel = null;
     AbortOutstandingPolls();
 }
Ejemplo n.º 11
0
 void OnChannelOpened(object sender, EventArgs e)
 {
     this.channel = (MakeConnectionDuplexClientChannel <TChannel>)sender;
 }