Beispiel #1
0
        public void SubscribeChannel(FizzChannelMeta meta)
        {
            if (!_isIntialized)
            {
                Initialize();
            }

            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before subscribing channel.");
                return;
            }

            if (meta == null)
            {
                FizzLogger.E("FizzClient unable to subscribe, channel meta is null.");
                return;
            }

            if (channelLoopup.ContainsKey(meta.Id))
            {
                FizzLogger.W("FizzClient channel is already subscribed.");
                return;
            }

            FizzChannel fizzChannel = AddChannelToList(meta);

            if (IsConnected && fizzChannel != null)
            {
                fizzChannel.SubscribeAndQuery();
            }
        }
Beispiel #2
0
        FizzChannel AddChannelInternal(TestChannelMeta channelMeta)
        {
            if (channelLoopup.ContainsKey(channelMeta.channelId))
            {
                return(null);
            }

            FizzChannel channel = new FizzChannel(channelMeta.channelId, channelMeta.channelName);

            Channels.Add(channel);
            channelLoopup.Add(channel.Id, channel);
            return(channel);
        }
Beispiel #3
0
        FizzChannel AddChannelToList(FizzChannelMeta channelMeta)
        {
            if (channelLoopup.ContainsKey(channelMeta.Id))
            {
                return(null);
            }

            FizzChannel channel = new FizzChannel(channelMeta);

            Channels.Add(channel);
            channelLoopup.Add(channel.Id, channel);
            return(channel);
        }
Beispiel #4
0
        public void AddChannel(TestChannelMeta channel)
        {
            if (channel == null)
            {
                return;
            }

            if (channelLoopup.ContainsKey(channel.channelId))
            {
                return;
            }

            FizzChannel fizzChannel = AddChannelInternal(channel);

            if (IsConnected)
            {
                fizzChannel.SubscribeAndQuery();
            }
        }
Beispiel #5
0
        public void RemoveChannel(string channelId)
        {
            if (string.IsNullOrEmpty(channelId))
            {
                return;
            }

            try
            {
                if (channelLoopup.ContainsKey(channelId))
                {
                    FizzChannel fizzChannel = channelLoopup[channelId];
                    channelLoopup.Remove(channelId);
                    Channels.Remove(fizzChannel);
                    fizzChannel.Unsubscribe(ex => { });
                }
            }
            catch
            {
            }
        }
Beispiel #6
0
        public void UnsubscribeChannel(string channelId)
        {
            if (!_isIntialized)
            {
                Initialize();
            }

            if (Client.State == FizzClientState.Closed)
            {
                FizzLogger.W("FizzClient should be opened before unsubscribing channel.");
                return;
            }

            if (string.IsNullOrEmpty(channelId))
            {
                FizzLogger.E("FizzClient unable to unsubscribe, channelId is null or empty.");
                return;
            }

            try
            {
                if (channelLoopup.ContainsKey(channelId))
                {
                    FizzChannel fizzChannel = channelLoopup[channelId];
                    channelLoopup.Remove(channelId);
                    Channels.Remove(fizzChannel);
                    fizzChannel.Unsubscribe(ex => { });
                }
                else
                {
                    FizzLogger.W("FizzService unable to unsubscribe, channel [" + channelId + "] does not exist. ");
                }
            }
            catch (Exception e)
            {
                FizzLogger.E(e);
            }
        }