• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Models.ChatRoom类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JabbR.Models.ChatRoom的典型用法代码示例。如果您正苦于以下问题:C# ChatRoom类的具体用法?C# ChatRoom怎么用?C# ChatRoom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ChatRoom类属于JabbR.Models命名空间,在下文中一共展示了ChatRoom类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AddOwner

        public void AddOwner(ChatUser ownerOrCreator, ChatUser targetUser, ChatRoom targetRoom)
        {
            // Ensure the user is owner of the target room
            EnsureOwner(ownerOrCreator, targetRoom);

            if (targetRoom.Owners.Contains(targetUser))
            {
                // If the target user is already an owner, then throw
                throw new InvalidOperationException(String.Format("'{0}' is already and owner of '{1}'.", targetUser.Name, targetRoom.Name));
            }

            // Make the user an owner
            targetRoom.Owners.Add(targetUser);
            targetUser.OwnedRooms.Add(targetRoom);

            if (targetRoom.Private)
            {
                if (!targetRoom.AllowedUsers.Contains(targetUser))
                {
                    // If the room is private make this user allowed
                    targetRoom.AllowedUsers.Add(targetUser);
                    targetUser.AllowedRooms.Add(targetRoom);
                }
            }
        }
开发者ID:skalinets,项目名称:JabbR,代码行数:25,代码来源:ChatService.cs


示例2: EnsureAllowed

 public static void EnsureAllowed(this ChatUser user, ChatRoom room)
 {
     if (room.Private && !room.IsUserAllowed(user))
     {
         throw new HubException(String.Format(LanguageResources.RoomAccessPermission, room.Name));
     }
 }
开发者ID:QuinntyneBrown,项目名称:JabbR,代码行数:7,代码来源:ModelExtensions.cs


示例3: SetUserInRoom

        public static void SetUserInRoom(this ICache cache, ChatUser user, ChatRoom room, bool value)
        {
            string key = CacheKeys.GetUserInRoom(user, room);

            // Cache this forever since people don't leave rooms often
            cache.Set(key, value, TimeSpan.FromDays(365));
        }
开发者ID:arri-cc,项目名称:JabbR,代码行数:7,代码来源:CacheExtensions.cs


示例4: EnsureAllowed

 public static void EnsureAllowed(this ChatUser user, ChatRoom room)
 {
     if (room.Private && !room.IsUserAllowed(user))
     {
         throw new InvalidOperationException("You do not have access to " + room.Name);
     }
 }
开发者ID:v-jli,项目名称:jean0603jabbr,代码行数:7,代码来源:ModelExtensions.cs


示例5: MakesOwnerAllowedIfRoomLocked

            public void MakesOwnerAllowedIfRoomLocked()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                var user2 = new ChatUser
                {
                    Name = "foo2"
                };
                repository.Add(user);
                repository.Add(user2);
                var room = new ChatRoom
                {
                    Name = "Room",
                    Creator = user,
                    Private = true
                };
                room.Owners.Add(user);
                user.OwnedRooms.Add(room);
                user.Rooms.Add(room);
                room.Users.Add(user);

                var service = new ChatService(repository, new Mock<ICryptoService>().Object);

                service.AddOwner(user, user2, room);

                Assert.True(user2.AllowedRooms.Contains(room));
                Assert.True(room.AllowedUsers.Contains(user2));
                Assert.True(room.Owners.Contains(user2));
                Assert.True(user2.OwnedRooms.Contains(room));
            }
开发者ID:Polows,项目名称:JabbR,代码行数:33,代码来源:ChatServiceFacts.cs


示例6: MakesUserOwner

            public void MakesUserOwner()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                var user2 = new ChatUser
                {
                    Name = "foo2"
                };
                repository.Add(user);
                repository.Add(user2);
                var room = new ChatRoom
                {
                    Name = "Room",
                    Creator = user
                };
                room.Owners.Add(user);
                user.OwnedRooms.Add(room);
                user.Rooms.Add(room);
                room.Users.Add(user);

                var service = new ChatService(repository);

                service.AddOwner(user, user2, room);

                Assert.True(room.Owners.Contains(user2));
                Assert.True(user2.OwnedRooms.Contains(room));
            }
开发者ID:kiliman,项目名称:JabbR,代码行数:30,代码来源:ChatServiceFacts.cs


示例7: CreateRoomRepository

            public IJabbrRepository CreateRoomRepository()
            {
                var repository = new InMemoryRepository();
                var room = new ChatRoom() { Name = "hashtag" };
                var user = new ChatUser() { Name = "testhashtaguser" };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                return repository;
            }
开发者ID:redsquare,项目名称:JabbR,代码行数:11,代码来源:TextTransformFacts.cs


示例8: IsUserInRoom

        public static bool IsUserInRoom(this IJabbrRepository repository, ICache cache, ChatUser user, ChatRoom room)
        {
            bool? cached = cache.IsUserInRoom(user, room);

            if (cached == null)
            {
                cached = repository.IsUserInRoom(user, room);
                cache.SetUserInRoom(user, room, cached.Value);
            }

            return cached.Value;
        }
开发者ID:shimazoe,项目名称:cchat2,代码行数:12,代码来源:RepositoryExtensions.cs


示例9: AddMessage

        public ChatMessage AddMessage(ChatUser user, ChatRoom room, string content)
        {
            var chatMessage = new ChatMessage
            {
                Id = Guid.NewGuid().ToString("d"),
                User = user,
                Content = content,
                When = DateTimeOffset.UtcNow,
                Room = room
            };

            _repository.Add(chatMessage);

            return chatMessage;
        }
开发者ID:skalinets,项目名称:JabbR,代码行数:15,代码来源:ChatService.cs


示例10: AddsNewMessageToRepository

            public void AddsNewMessageToRepository()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                repository.Add(user);
                var room = new ChatRoom
                {
                    Name = "Room"
                };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                var service = new ChatService(repository);
                ChatMessage message = service.AddMessage(user, room, "Content");

                Assert.NotNull(message);
                Assert.Same(message, room.Messages.First());
                Assert.Equal("Content", message.Content);
            }
开发者ID:kiliman,项目名称:JabbR,代码行数:23,代码来源:ChatServiceFacts.cs


示例11: AddsNewMessageToRepository

            public void AddsNewMessageToRepository()
            {
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo"
                };
                repository.Add(user);
                var room = new ChatRoom
                {
                    Name = "Room"
                };
                repository.Add(room);
                room.Users.Add(user);
                user.Rooms.Add(room);

                var service = new ChatService(new Mock<ICache>().Object, repository, new Mock<ICryptoService>().Object);
                ChatMessage message = service.AddMessage(user, room, Guid.NewGuid().ToString(), "Content");

                Assert.NotNull(message);
                Assert.Same(message, room.Messages.First());
                Assert.Equal("Content", message.Content);
            }
开发者ID:nonintanon,项目名称:JabbR,代码行数:23,代码来源:ChatServiceFacts.cs


示例12: CloseRoom

        public void CloseRoom(ChatUser user, ChatRoom targetRoom)
        {
            EnsureOwner(user, targetRoom);

            if (targetRoom.Closed)
            {
                throw new InvalidOperationException(String.Format("{0} is already closed.", targetRoom.Name));
            }

            // Make sure the (owner) user is not in the room.
            if (targetRoom.Users.Contains(user))
            {
                throw new InvalidOperationException("You are trying to close a room which you are still in. Please leave the room before closing it.");
            }

            // Kick all existing users in the room.
            foreach (var targetUser in targetRoom.Users.ToList())
            {
                LeaveRoom(targetUser, targetRoom);
            }

            // Make the room closed.
            targetRoom.Closed = true;

            _repository.CommitChanges();
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:26,代码来源:ChatService.cs


示例13: ChangeTopic

 public void ChangeTopic(ChatUser user, ChatRoom room, string newTopic)
 {
     EnsureOwner(user, room);
     room.Topic = newTopic;
     _repository.CommitChanges();
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:6,代码来源:ChatService.cs


示例14: EnsureOwner

 private static void EnsureOwner(ChatUser user, ChatRoom room)
 {
     if (!room.Owners.Contains(user))
     {
         throw new InvalidOperationException("You are not an owner of room '" + room.Name + "'");
     }
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:7,代码来源:ChatService.cs


示例15: IsUserInRoom

 internal static bool IsUserInRoom(ChatRoom room, ChatUser user)
 {
     return room.Users.Any(r => r.Name.Equals(user.Name, StringComparison.OrdinalIgnoreCase));
 }
开发者ID:alexkopy,项目名称:JabbR,代码行数:4,代码来源:ChatService.cs


示例16: SetInviteCode

        public void SetInviteCode(ChatUser user, ChatRoom room, string inviteCode)
        {
            EnsureOwner(user, room);
            if (!room.Private)
            {
                throw new InvalidOperationException("Only private rooms can have invite codes");
            }

            // Set the invite code and save
            room.InviteCode = inviteCode;
            _repository.CommitChanges();
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:12,代码来源:ChatService.cs


示例17: LeaveRoom

        public void LeaveRoom(ChatUser user, ChatRoom room)
        {
            // Remove the user from the room
            room.Users.Remove(user);

            // Remove this room from the users' list
            user.Rooms.Remove(room);
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:8,代码来源:ChatService.cs


示例18: JoinRoom

        public void JoinRoom(ChatUser user, ChatRoom room, string inviteCode)
        {
            // Throw if the room is private but the user isn't allowed
            if (room.Private)
            {
                // First, check if the invite code is correct
                if (!String.IsNullOrEmpty(inviteCode) && String.Equals(inviteCode, room.InviteCode, StringComparison.OrdinalIgnoreCase))
                {
                    // It is, add the user to the allowed users so that future joins will work
                    room.AllowedUsers.Add(user);
                }
                if (!IsUserAllowed(room, user))
                {
                    throw new InvalidOperationException(String.Format("Unable to join {0}. This room is locked and you don't have permission to enter. If you have an invite code, make sure to enter it in the /join command", room.Name));
                }
            }

            // Add this room to the user's list of rooms
            user.Rooms.Add(room);

            // Add this user to the list of room's users
            room.Users.Add(user);
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:23,代码来源:ChatService.cs


示例19: KickUser

        public void KickUser(ChatUser user, ChatUser targetUser, ChatRoom targetRoom)
        {
            EnsureOwner(user, targetRoom);

            if (targetUser == user)
            {
                throw new InvalidOperationException("Why would you want to kick yourself?");
            }

            if (!IsUserInRoom(targetRoom, targetUser))
            {
                throw new InvalidOperationException(String.Format("'{0}' isn't in '{1}'.", targetUser.Name, targetRoom.Name));
            }

            // If this user isnt' the creator and the target user is an owner then throw
            if (targetRoom.Creator != user && targetRoom.Owners.Contains(targetUser))
            {
                throw new InvalidOperationException("Owners cannot kick other owners. Only the room creator and kick an owner.");
            }

            LeaveRoom(targetUser, targetRoom);
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:22,代码来源:ChatService.cs


示例20: OpenRoom

        public void OpenRoom(ChatUser user, ChatRoom targetRoom)
        {
            EnsureOwner(user, targetRoom);

            if (!targetRoom.Closed)
            {
                throw new InvalidOperationException(string.Format("{0} is already open.", targetRoom.Name));
            }

            // Open the room
            targetRoom.Closed = false;
            _repository.CommitChanges();
        }
开发者ID:alexkopy,项目名称:JabbR,代码行数:13,代码来源:ChatService.cs



注:本文中的JabbR.Models.ChatRoom类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Models.ChatUser类代码示例发布时间:2022-05-26
下一篇:
C# Models.ChatMessage类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap