public async void CreateSubscription(
                string channelOrSubId,
                SubscriptionConfig config)
            {
                Log.I("CreateSubscription method is dispatched, subscription id: '{0}'", channelOrSubId);
                await this.Yield();

                Log.V("CreateSubscription method is executing, subscription id: '{0}'", channelOrSubId);

                var observer = config.Observer;

                if (observer == null)
                {
                    observer = _subscriptionObserver;
                }
                else
                {
                    observer = new SubscriptionCompoundObserver(
                        _subscriptionObserver,
                        observer);
                }

                ISubscription createdSub;
                Subscription  storedSub;

                if (_susbscriptions.TryGetValue(channelOrSubId, out storedSub))
                {
                    createdSub = storedSub.ProcessSubscribe(config, observer);
                    if (createdSub == null)
                    {
                        observer.NotifySubscribeError(storedSub, new InvalidOperationException($"Subscription '{channelOrSubId}' already exists"));
                        return;
                    }
                }
                else
                {
                    var sub = new Subscription(
                        _client,
                        channelOrSubId,
                        config.Mode,
                        config.Filter,
                        config.Period,
                        config.Position,
                        config.History,
                        observer);
                    observer.NotifyCreated(sub);
                    _susbscriptions[channelOrSubId] = sub;
                    observer.NotifyEnterUnsubscribed(sub);
                    if (sub != null)
                    {
                        // subscription loop should be started after method is returned
                        this.Post(() => this.SubscriptionLoop(sub));
                    }

                    createdSub = sub;
                }

                Log.V("CreateSubscription method is completed, subscription id: '{0}'", channelOrSubId);
            }
        public SubscriptionFuture ProcessSubscribe(SubscriptionConfig config, ISubscriptionObserver observer)
        {
            Log.V("Processing subscribe, subscription: {0}", this);

            if (!MarkAsDeleted || Future != null)
            {
                return(null);
            }

            Future = new SubscriptionFuture(
                subscriptionId: SubscriptionId,
                mode: config.Mode,
                filter: config.Filter,
                period: config.Period,
                position: config.Position,
                history: config.History,
                observer: observer);

            return(Future);
        }
示例#3
0
 public void CreateSubscription(string channelOrSubId, SubscriptionConfig subscriptionConfig)
 {
     _rtmModule.CreateSubscription(channelOrSubId, subscriptionConfig);
 }