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); } }); } } }
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 { } } } } } }
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); } } }); } } } }
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); }
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); }
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); }
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()); }
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()); }
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()); }