Beispiel #1
0
        public static Channel GetChannel(this SessionState _sessionState, string name, string password, PubnubAPI pubnub)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
            {
                return(null);
            }
            Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.Password == password).FirstOrDefault();

            if (result == null)
            {
                //try to get channel from mongodb
                result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault();
                if (result == null)
                {
                    //save new channel
                    result                 = new Channel();
                    result.Name            = name;
                    result.Password        = password;
                    result.CreatedDateTime = DateTime.Now;
                    _sessionState.SaveChannel(result);
                    //add channel in cache
                    AppCache.ChannelList.AddSafeName(result);
                    if (pubnub != null)
                    {
                        List <object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name);
                    }
                }
                else if (result.Password != password)
                {
                    result = null;
                }
            }
            return(result);
        }
Beispiel #2
0
        public static Channel GetChannel(this SessionState _sessionState, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            Channel result = AppCache.ChannelList.Where(c => c.Name == name).FirstOrDefault();

            if (result == null)
            {
                result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();
                if (result == null)
                {
                    result = new Channel();
                }
                AppCache.ChannelList.AddSafeName(result);
            }
            return(result);
        }