public IChannelBinder EndAccept(IAsyncResult result)
            {
                IInputSessionChannel channel = this.listener.EndAcceptChannel(result);

                if (channel == null)
                {
                    return(null);
                }
                return(new InputChannelBinder(channel, this.listener.Uri));
            }
            public IChannelBinder Accept(TimeSpan timeout)
            {
                IInputSessionChannel channel = this.listener.AcceptChannel(timeout);

                if (channel == null)
                {
                    return(null);
                }
                return(new InputChannelBinder(channel, this.listener.Uri));
            }
Example #3
0
 public DurableInstanceContextInputSessionChannel(
     ChannelManagerBase channelManager,
     ContextType contextType,
     IInputSessionChannel innerChannel)
     : base(channelManager, innerChannel)
 {
     this.isFirstMessage           = true;
     this.innerInputSessionChannel = innerChannel;
     this.contextType = contextType;
     this.stateLock   = new object();
 }
 public DurableInstanceContextInputSessionChannel(
     ChannelManagerBase channelManager,
     ContextType contextType,
     IInputSessionChannel innerChannel)
     : base(channelManager, innerChannel)
 {
     this.isFirstMessage = true;
     this.innerInputSessionChannel = innerChannel;
     this.contextType = contextType;
     this.stateLock = new object();
 }
Example #5
0
            public async Task <IChannelBinder> AcceptAsync(CancellationToken token)
            {
                IInputSessionChannel channel = await listener.AcceptChannelAsync(token);

                if (channel == null)
                {
                    return(null);
                }

                return(new InputChannelBinder(channel, listener.Uri));
            }
Example #6
0
        static void ReceiveSessionMessages()
        {
            // Read messages from queue until queue is empty:
            Console.WriteLine("Reading messages from queue {0}...", SampleManager.SessionQueueName);
            Console.WriteLine("Receiver Type: PeekLock");

            // Create listener and channel using custom binding
            CustomBinding   customBinding = new CustomBinding("customBinding");
            EndpointAddress address       = SampleManager.GetEndpointAddress(SampleManager.SessionQueueName, serviceBusNamespace);
            TransportClientEndpointBehavior securityBehavior = new TransportClientEndpointBehavior();

            securityBehavior.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(serviceBusKeyName, serviceBusKey);
            customBinding.GetProperty <IReceiveContextSettings>(new BindingParameterCollection()).Enabled = true;

            IChannelListener <IInputSessionChannel> inputSessionChannelListener = null;

            try
            {
                inputSessionChannelListener = customBinding.BuildChannelListener <IInputSessionChannel>(address.Uri, securityBehavior);
                inputSessionChannelListener.Open();

                while (true)
                {
                    IInputSessionChannel inputSessionChannel = null;
                    try
                    {
                        // Create a new session channel for every new session available. If no more sessions available,
                        // then the operation throws a TimeoutException.
                        inputSessionChannel = inputSessionChannelListener.AcceptChannel(acceptSessionReceiverTimeout);
                        inputSessionChannel.Open();

                        // TryReceive operation returns true if message is available otherwise it returns false.
                        Message receivedMessage;
                        while (inputSessionChannel.TryReceive(receiveSessionMessageTimeout, out receivedMessage))
                        {
                            if (receivedMessage != null)
                            {
                                SampleManager.OutputMessageInfo("Receive", receivedMessage);

                                // Since the message body contains a serialized string one can access it like this:
                                //string soapBody = receivedMessage.GetBody<string>();

                                // Since the binding has ReceiveContext enabled, a manual complete operation is mandatory
                                // if the message was processed successfully.
                                ReceiveContext rc;
                                if (ReceiveContext.TryGet(receivedMessage, out rc))
                                {
                                    rc.Complete(TimeSpan.FromSeconds(10.0d));
                                }
                                else
                                {
                                    throw new InvalidOperationException("Receiver is in peek lock mode but receive context is not available!");
                                }
                            }
                            else
                            {
                                // This IInputSessionChannel doesn't have any more messages
                                break;
                            }
                        }

                        // Close session channel
                        inputSessionChannel.Close();
                        inputSessionChannel = null;
                    }
                    catch (TimeoutException)
                    {
                        break;
                    }
                    finally
                    {
                        if (inputSessionChannel != null)
                        {
                            inputSessionChannel.Abort();
                        }
                    }
                }

                // Close channel listener
                inputSessionChannelListener.Close();
            }
            catch (Exception)
            {
                if (inputSessionChannelListener != null)
                {
                    inputSessionChannelListener.Abort();
                }
                throw;
            }
        }
Example #7
0
 public InputSessionChannelWrapper(ChannelManagerBase channelManager, IInputSessionChannel innerChannel, Message firstMessage) : base(channelManager, innerChannel, firstMessage)
 {
 }