예제 #1
0
파일: MessageServer.cs 프로젝트: ywscr/SAEA
        void ReplyChannelMessage(MessageUserToken userToken, ChatMessage cm)
        {
            var channelMsg = SerializeHelper.Deserialize <ChannelMessage>(cm.Content);

            if (channelMsg != null && !string.IsNullOrEmpty(channelMsg.Name))
            {
                channelMsg.Sender = userToken.ID;

                channelMsg.Sended = DateTimeHelper.ToString();

                var channel = _channelList.Get(channelMsg.Name);

                if (channel != null && channel.Members != null)
                {
                    var members = channel.Members.ToArray();

                    var ccm = new ChatMessage(ChatMessageType.ChannelMessage, SerializeHelper.Serialize(channelMsg));

                    var data = SerializeHelper.PBSerialize(ccm);

                    var sp = BaseSocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes();

                    Parallel.ForEach(members, (m) =>
                    {
                        if (m.ID != userToken.ID)
                        {
                            _server.SendAsync(m.ID, sp);
                        }
                    });
                }
            }
        }
예제 #2
0
        void ReplyChannelMessage(MessageUserToken userToken, ChatMessage cm)
        {
            var channelMsg = ConvertHelper.Deserialize <ChannelMessage>(cm.Content);

            if (channelMsg != null && !string.IsNullOrEmpty(channelMsg.Name))
            {
                channelMsg.Sender = userToken.ID;

                channelMsg.Sended = DateTimeHelper.ToString();

                var channel = _channelList.Get(channelMsg.Name);

                if (channel != null && channel.Members != null)
                {
                    lock (_channelList.SyncLocker)
                    {
                        foreach (var m in channel.Members)
                        {
                            try
                            {
                                if (m.ID != userToken.ID)
                                {
                                    var r = SessionManager.Get(m.ID);
                                    if (r != null)
                                    {
                                        ReplyBase(r, new ChatMessage(ChatMessageType.ChannelMessage, ConvertHelper.Serialize(channelMsg)));
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                }
            }
        }
예제 #3
0
        void ReplyChannelMessage(MessageUserToken userToken, ChatMessage cm)
        {
            var channelMsg = ConvertHelper.Deserialize <ChannelMessage>(cm.Content);

            if (channelMsg != null && !string.IsNullOrEmpty(channelMsg.Name))
            {
                channelMsg.Sender = userToken.ID;

                channelMsg.Sended = DateTimeHelper.ToString();

                var channel = _channelList.Get(channelMsg.Name);

                if (channel != null && channel.Members != null)
                {
                    lock (_channelList.SyncLocker)
                    {
                        var ccm  = new ChatMessage(ChatMessageType.ChannelMessage, ConvertHelper.Serialize(channelMsg));
                        var data = ConvertHelper.PBSerialize(cm);
                        var sp   = SocketProtocal.Parse(data, SocketProtocalType.ChatMessage).ToBytes();

                        Parallel.ForEach(channel.Members, (m) =>
                        {
                            if (m.ID != userToken.ID)
                            {
                                var r = SessionManager.Get(m.ID);
                                if (r != null)
                                {
                                    SendAsync(r, sp);
                                }
                            }
                        });
                    }
                }
            }
        }
예제 #4
0
        public void GetWillReuseChannelObject()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            // Act
            var channel2 = target.Get("test");

            // Assert
            Assert.NotNull(channel2);
            Assert.Same(channel, channel2);
        }
예제 #5
0
        public void GetCreatesChannel_WithOptions()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target = new ChannelList(manager.Object, factory.Object);

            Rest.ChannelOptions options = new Rest.ChannelOptions();

            // Act
            var channel = target.Get("test", options);

            // Assert
            Assert.Same(options, channel.Options);
        }
예제 #6
0
        public void Release_DetachesChannel()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();

            // Act
            target.Release("test");

            // Assert
            Assert.Equal(ChannelState.Detaching, channel.State);
        }
예제 #7
0
        public void ReleaseAll_DoesNotRemoveChannelBeforeDetached()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();

            // Act
            target.ReleaseAll();

            // Assert
            Assert.Same(channel, target.Single());
        }
예제 #8
0
        public void AllowsGenericEnumeration()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            // Act
            IEnumerator <Realtime.IRealtimeChannel> enumerator = (target as IEnumerable <Realtime.IRealtimeChannel>).GetEnumerator();

            enumerator.MoveNext();

            // Assert
            Assert.Same(channel, enumerator.Current);
            Assert.False(enumerator.MoveNext());
        }
예제 #9
0
        public void ReleaseAll_RemovesChannelWhenFailded()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();
            target.ReleaseAll();

            // Act
            manager.Raise(c => c.MessageReceived += null, new ProtocolMessage(ProtocolMessage.MessageAction.Error, "test"));

            // Assert
            Assert.False(target.Any());
        }