Ejemplo n.º 1
0
        public override IMessage ServiceMessage(IMessage message)
        {
            if (message is CommandMessage)
            {
                CommandMessage message2 = message as CommandMessage;
                switch (message2.operation)
                {
                case 0:
                {
                    if (FluorineContext.Current.Client == null)
                    {
                        FluorineContext.Current.SetCurrentClient(base.GetMessageBroker().ClientRegistry.GetClient(message));
                    }
                    RemotingConnection connection = null;
                    foreach (IConnection connection2 in FluorineContext.Current.Client.Connections)
                    {
                        if (connection2 is RemotingConnection)
                        {
                            connection = connection2 as RemotingConnection;
                            break;
                        }
                    }
                    if (connection == null)
                    {
                        connection = new RemotingConnection(this, null, FluorineContext.Current.Client.Id, null);
                        FluorineContext.Current.Client.Renew(connection.ClientLeaseTime);
                        connection.Initialize(FluorineContext.Current.Client);
                    }
                    break;
                }

                case 2:
                {
                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }
                    IMessage[] pendingMessages = null;
                    this._waitingPollRequests.Increment();
                    int waitIntervalMillis = (base._channelSettings.WaitIntervalMillis != -1) ? base._channelSettings.WaitIntervalMillis : 0xea60;
                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }
                    if (message2.HeaderExists(CommandMessage.FluorineSuppressPollWaitHeader))
                    {
                        waitIntervalMillis = 0;
                    }
                    if (!FluorineConfiguration.Instance.FluorineSettings.Runtime.AsyncHandler)
                    {
                        waitIntervalMillis = 0;
                    }
                    if ((base._channelSettings.MaxWaitingPollRequests <= 0) || (this._waitingPollRequests.Value >= base._channelSettings.MaxWaitingPollRequests))
                    {
                        waitIntervalMillis = 0;
                    }
                    if ((message.destination != null) && (message.destination != string.Empty))
                    {
                        string             clientId    = message2.clientId as string;
                        MessageDestination destination = base.GetMessageBroker().GetDestination(message.destination) as MessageDestination;
                        MessageClient      subscriber  = destination.SubscriptionManager.GetSubscriber(clientId);
                        subscriber.Renew();
                        pendingMessages = subscriber.GetPendingMessages();
                    }
                    else if (FluorineContext.Current.Client != null)
                    {
                        pendingMessages = FluorineContext.Current.Client.GetPendingMessages(waitIntervalMillis);
                    }
                    this._waitingPollRequests.Decrement();
                    if ((pendingMessages == null) || (pendingMessages.Length == 0))
                    {
                        return(new AcknowledgeMessage());
                    }
                    return(new CommandMessage {
                            operation = 4, body = pendingMessages
                        });
                }
                }
            }
            return(base.ServiceMessage(message));
        }