UserInRoom() public method

public UserInRoom ( System.Guid roomId, ConnectionRecord cr ) : bool
roomId System.Guid
cr ConnectionRecord
return bool
コード例 #1
0
        public void Send(string message, Guid roomId)
        {
            //if no valid connectionrecord don't let the message go through
            var crc = new ConnectionRecordController();
            var cr  = crc.GetConnectionRecordByConnectionId(Context.ConnectionId);

            //if the user (connectionrecord) isn't in a room don't let message go through

            var rc = new RoomController();

            if (cr != null && rc.UserInRoom(roomId, cr))
            {
                // parse message before use
                if (Clients.Caller.username != null && Clients.Caller.username.Trim() != "phantom")
                {
                    var parsedMessage = ParseMessage(message, roomId);
                    if (parsedMessage != string.Empty)
                    {
                        int moduleId;
                        int authorUserId;
                        //int.TryParse(Clients.Caller.moduleid, out moduleId);
                        moduleId     = Convert.ToInt32(Clients.Caller.moduleid);
                        authorUserId = Convert.ToInt32(Clients.Caller.userid);

                        var m = new Message
                        {
                            ConnectionId = Context.ConnectionId,
                            MessageDate  = DateTime.UtcNow,
                            MessageText  = parsedMessage,
                            AuthorName   = Clients.Caller.username,
                            AuthorUserId = authorUserId,
                            ModuleId     = moduleId,
                            RoomId       = roomId
                        };

                        new MessageController().CreateMessage(m);
                        Clients.Group(roomId.ToString()).newMessage(m);
                    }
                }
                else
                {
                    // if there is no username for the user don't let them post
                    var m = new Message
                    {
                        ConnectionId = Context.ConnectionId,
                        MessageDate  = DateTime.UtcNow,
                        MessageText  = Localization.GetString("FailedUnknown.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                        AuthorUserId = -1,
                        RoomId       = DefaultRoomId
                    };
                    Clients.Caller.newMessage(m);
                }
            }
            else
            {
                // if there is no username for the user don't let them post
                var m = new Message
                {
                    ConnectionId = Context.ConnectionId,
                    MessageDate  = DateTime.UtcNow,
                    MessageText  = Localization.GetString("FailedUnknown.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                    AuthorName   = Localization.GetString("SystemName.Text", "~/desktopmodules/DnnChat/app_localresources/" + Localization.LocalSharedResourceFile),
                    AuthorUserId = -1,
                    RoomId       = DefaultRoomId
                };
                Clients.Caller.newMessage(m);
            }
        }