コード例 #1
0
ファイル: Extensions.cs プロジェクト: s1me0n/Teamwork
        public static Channel GetChannel(this boSessionState _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);
        }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: s1me0n/Teamwork
        public static Channel GetChannel(this boSessionState _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.PublicData.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.PublicData = new ChannelResource()
                    {
                        Password = password, CreatedDateTime = DateTime.Now
                    };
                    result.PrivateData = AppCache.AESProvider.EncryptToString(JsonConvert.SerializeObject(result.PublicData));
                    _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.PublicData.Password != password)
                {
                    result = null;
                }
            }
            return(result);
        }