示例#1
0
        public virtual string UnSubscribeSymbol(string Symbol, List <string> Channels = null)
        {
            string Params = string.Empty;

            lock ( SubscribedSymbols )
            {
                if (Channels == null)
                {
                    // get/use all current Channels
                    SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol);
                    if (Rec != null)
                    {
                        Channels = Rec.Channels;
                    }
                }

                if (Channels != null)
                {
                    Params = FormatChannelParamsForSymbol(Symbol, Channels);

                    if (!pgWebSocket.PGStatus.IsConnected)
                    {
                        QueueSubscribeData(Symbol, Params, Channels, false);
                    }
                    else
                    {
                        SendUnSubscribeMessage(Params);
                    }
                }
            }

            return(Params);
        }
示例#2
0
        public virtual string SubscribeSymbol(string Symbol, List <string> Channels = null, bool CreateRec = true)
        {
            string Params = string.Empty;

            lock ( SubscribedSymbols )
            {
                if (CreateRec)
                {
                    SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol);
                    if (Rec == null)
                    {
                        Rec = CreateSubscribeSymbolRec(Symbol, Channels);
                    }

                    Channels          = Rec.Channels;
                    Rec.ChannelsAdded = Channels;
                }

                Params = FormatChannelParamsForSymbol(Symbol, Channels);

                if (!pgWebSocket.PGStatus.IsConnected)
                {
                    QueueSubscribeData(Symbol, Params, Channels, true, CreateRec);
                }
                else
                {
                    SendSubscribeMessage(Params);
                }
            }

            return(Params);
        }
示例#3
0
 public void RemoveSymbol(string Symbol)
 {
     lock ( SubscribedSymbols )
     {
         UnSubscribeSymbol(Symbol);
         SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol);
         if (Rec != null)
         {
             SubscribedSymbols.Remove(GetSymbolOnly(Symbol));
         }
     }
 }
示例#4
0
        private void SetSubscribeSymbolRecsFlags(string Params, bool IsNew, bool ChannelsWereRemoved)
        {
            List <string> Symbols = Params.Split(',').ToList();

            foreach (var Symbol in Symbols)
            {
                SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol);
                if (Rec != null)
                {
                    Rec.IsNew = IsNew;
                    Rec.ChannelsWereRemoved = ChannelsWereRemoved;
                }
            }
        }
示例#5
0
        public SubscribeSymbolRec CreateSubscribeSymbolRec(string Symbol, List <string> Channels = null)
        {
            Symbol = GetSymbolOnly(Symbol);

            SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol, true);

            if (Rec == null)
            {
                SubscribedSymbols[Symbol] = Rec = new SubscribeSymbolRec(Symbol)
                {
                    // if Channels == null, use DefaultChannels for this Cluster
                    Channels = Channels != null ? Channels : new List <string>(DefaultChannels)
                };
            }

            return(Rec);
        }
示例#6
0
        private void VerifySubscribeSymbolRecsForParams(string Params, bool IsSubscribe)
        {
            List <string> Symbols = Params.Split(',').ToList();

            foreach (var Symbol in Symbols)
            {
                SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol, true);
                if (Rec == null)
                {
                    Rec = CreateSubscribeSymbolRec(Symbol);
                }

                // add Params to every record for event listeners to find/use
                Rec.Params = Params;

                if (IsSubscribe)
                {
                    Rec.ChannelsAdded.Clear();
                }
                else
                {
                    Rec.ChannelsRemoved.Clear();
                }

                foreach (string Channel in Symbols)
                {
                    if (IsSubscribe)
                    {
                        Rec.ChannelsAdded.Add(GetChannelOnly(Channel));
                    }
                    else
                    {
                        Rec.ChannelsRemoved.Add(GetChannelOnly(Channel));
                    }
                }

                Rec.Params = Params;
            }
        }
示例#7
0
        private void VerifyRemainingChannels(string Params)
        {
            List <string> Symbols = Params.Split(',').ToList();

            foreach (var Symbol in Symbols)
            {
                SubscribeSymbolRec Rec = GetSubscribeSymbolRec(Symbol);
                if (Rec != null)
                {
                    foreach (string Channel in Symbols)
                    {
                        Rec.Channels.Remove(GetChannelOnly(Channel));
                    }

                    if (Rec.Channels.Count == 0)
                    {
                        SubscribedSymbols.Remove(Rec.Symbol);
                    }

                    // reset values
                    Rec.ChannelsWereRemoved = false;
                }
            }
        }